I have two divs like this:
<section id="main"> <div id="left"> <asp:ContentPlaceHolder ID="left" runat="server" /> </div> <div id="right"> <asp:ContentPlaceHolder ID="right" runat="server" /> </div> </section>
And here is my css:
#left { float: left; margin-right: 17px; } #right { float: right; }
I want the space between the divs to be 40px. I tried adding padding, margin and width in my css, but I think it didn't set the padding to correct 40px. How to do it?
Use the margin property. I put stye=“margin-top: 50px;” in the second div.
The simplest way to add a space in HTML (besides hitting the spacebar) is with the non-breaking space entity, written as or  . Multiple adjacent non-breaking spaces won't be collapsed by the browser, letting you “force” several visible spaces between words or other page elements.
For folks searching for solution to set spacing between N
divs, here is another approach using pseudo selectors:
div:not(:last-child) { margin-right: 40px; }
You can also combine child pseudo selectors:
div:not(:first-child):not(:last-child) { margin-left: 20px; margin-right: 20px; }
Float them both the same way and add the margin of 40px. If you have 2 elements floating opposite ways you will have much less control and the containing element will determine how far apart they are.
#left{ float: left; margin-right: 40px; } #right{ float: left; }
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