I have the following HTML structure
<div id='parent'>
<div id='child-1'>Some text goes here</div>
<div id='child-2'>Different text goes here</div>
<div class='clear'></div>
</div>
I also have the following CSS
#parent {
width: 800px;
position: relative;
}
#child-1 {
width: 500px;
float: left;
}
#child-2 {
width: 200px;
float: left;
}
.clear {
clear: both;
}
Now, the contents of the child DIVs (child-1 and child-2) could be anything, so eventually child-1 might have longer height than child-2, or child-2 might have a longer height than child-1.
What I want to do, is have a vertical line between child-1 and child-2, and this line has the length of the DIV that is of longer height. I tried border on both DIVs, (right border for child-1 and left border for child-2), but this is not a good idea, because the line will appear thick where the two DIVs touch each other and then thin for the extended part.
How can I do that? I also like to use CSS only if possible, no jQuery nor JavaScript. If you think extra DIVs are needed then this is OK though.
Thanks.
You can use <hr> , as it is semantically correct, and then use CSS to convert it to a vertical line.
To add a horizontal line between two divs, just put <hr> between the divs. You can use CSS to style this in a variety of ways such as adjusting the color and thickness of the line as well as the top and bottom margins.
You can use: border-style: solid; border-width: thin; border-color: #FFFFFF; You can change these as you see fit, though.
I tried border on both divs, (right border on child-1 and left border on div-2, but this is not a good idea, because the line will appear thick where the two divs touch each other and then thin for the extended part.
That's a good way to go, actually. The final step, though, is to give the right div a negative left margin of 1px (assuming the border is 1px wide), so that the two borders overlap.
#child-1 {
width: 500px;
float: left;
border-right: 1px solid gray;
}
#child-2 {
width: 200px;
float: left;
border-left: 1px solid gray;
margin-left: -1px;
}
Another option is to use display: table
on the parent and then display: table-cell
on the columns, and then have a single border line between them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With