Fluid display: two Divs arranged side by side
P粉098979048
2023-08-27 12:48:00
<p>I'm trying to place two divs side by side and using the following CSS. </p>
<pre class="brush:css;toolbar:false;">#left {
float: left;
width: 65%;
overflow: hidden;
}
#right {
overflow: hidden;
}
</pre>
<p>HTML is very simple, a wrapper div contains two divs on the left and right. </p>
<pre class="brush:html;toolbar:false;"><div id="wrapper">
<div id="left">Left side div</div>
<div id="right">Right side div</div>
</div>
</pre>
<p>I tried many times on StackOverflow and other sites to find a better way, but couldn't find any definite help. </p>
<p>So, at first glance, the code works fine. The problem is that when I increase the width (%), the left div automatically gets padding/margin. So at 65% width the left div has some padding or margin and is not perfectly aligned with the right div, I tried setting the padding/margin to 0 with no success. Secondly, if I zoom in on the page, the right div slides under the left div, which is like a stuttery display. </p>
<p>Note: Sorry, I checked a lot of information. This question has been asked many times but these answers didn't help me. I've explained what the problem was in my case. </p>
<p>I hope this can be resolved. </p>
<p>Thank you. </p>
<p>Edit: Sorry for my HTML problem, there are two "box" divs on the left and right, their padding is in %, so the left side shows more padding due to the larger width. Sorry, the CSS above works perfectly, it displays smoothly and is fixed, sorry for asking the wrong question...</p>
Try a system like this:
If you use margin-left on another div equal to the width of the first div, you can just float one div. This works no matter how much you zoom, and there are no subpixel issues.
Using this CSS for my current website. The effect is perfect!