I want the borders connecting the checkboxes.
I tried with pseudo borders, but was having difficulty in setting height as website is responsive for different screens.
Can anyone suggest a way to handle it for responsive screens.
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
overflow: hidden;
}
.parent {
border-left: 3px dashed black;
display: flex;
flex-wrap: wrap;
flex-direction: column;
}
.child {
display: flex;
flex-direction: column;
}
input {
width: 2rem;
height: 2rem;
}
.child input {
position: relative;
display: flex;
justify-content: center;
align-items: center;
margin-left: 4rem;
}
.child input::before {
content: '';
position: absolute;
left: -4rem;
border: 2px dashed black;
width: 100%;
}
<div class="parent">
<div>
<input type="checkbox" />
<div class="child">
<input type="checkbox">
<input type="checkbox" />
</div>
</div>
</div>
2
Answers
Try using
border-style: dashed
and::before
pseudo-element in this way:The first thing you want to do is start with semantic HTML. Then, you can use pseudoelements with gradient backgrounds to make the dashed lines.
Now, much of this is quite fragile. For example, it relies on magic numbers to get things lined up, which depends on the font and size of the checkbox. In the future, anchor positioning may be able to help, but for now, to really get it right, I’d suggest using SVG or canvas to draw the lines based on the positions of the elements.
That said, here’s a quick attempt at doing it all with CSS.