473,779 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Horizontal margin collapsing

Let's say I have some block elements that self-organize by floating to
the left, so if no more blocks can fit in a row they begin on the next
row (see crummy ASCII art at end of message).

I could define the CSS for one of the floating elements as such:

..floater
{
float: left;
width: 48%;
margin-left: 1%;
margin-right: 1%;
}

The problem here is that the floaters will then have twice as much
margin in between them as they will between the floaters and the sides
of the container. Now, in CSS2 (and 3?), vertical margins can collapse
(so that the margins of two elements are overlapping) but horizontal
margins are unable to do so. Is this correct? And can anyone think of
an elegant way to simulate this - and get equal spacing between the
floaters and the edges, and the floaters and each other?

I could do something like this:

..floater:nth-child(2n) { margin-left: 1%; margin-right: 0.5%; }
..floater:nth-child(2n+1) { margin-left: 0.5%; margin-right: 1%; }

except that (a) that pseudoclass is not (AFAIK) widely supported, and
(b) what if I have more than two elements per row?

That turned out to be far longer-winded than I expected; I hope someone
read all the way through :-)

Thanks,
Jeremy

Crummy ASCII Art Diagram:

_______________ _______________ _______________ ___________
|Container |
| _______________ ________ _______________ ________ |
| | Floater #1 | | Floater #2 | |
| | | | | |
| | | | | |
| | | | | |
| |______________ _________| |______________ _________| |
| _______________ ________ _______________ ________ |
| | Floater #3 | | Floater #4 | |
| | | | | |
| | | | | |
| | | | | |
| |______________ _________| |______________ _________| |
| |
|______________ _______________ _______________ ____________|
Aug 9 '06 #1
1 5958
Jeremy wrote:
Let's say I have some block elements that self-organize by floating to
the left, so if no more blocks can fit in a row they begin on the next
row (see crummy ASCII art at end of message).
<snip>
Please disregard this message on the grounds that I'm an idiot.

Solution: floaters have equal margin on both sides. *Container* gets
left and right padding equal to this margin.

Duh.

Jeremy
Aug 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3507
by: Brian | last post by:
I have a page with content, navigation, and footer divs, in that order. The nav div has position: absolute, width 8em, on green background. The other divs have an 8em green left border, such that the nav sits on that border. There is a thin red top border on footer for testing. http://www.tsmchughs.com/test/ On that page, all is as expected. However, on the long page http://www.tsmchughs.com/test/long
1
4670
by: Corvus | last post by:
Hi All, I've been having real trouble with some css in both Win/IE6 and Win/Firefox0.9.2 that doesn't make sense to me. I have a div that is supposed to be spaced away from the top and right hand edges of it's containing div and therefore I set suitable values for it's margins. Unfortunately it refuses to move itself unless I give the parent div a border. Perhaps this will make more sense with an example (I've boiled the
1
3221
by: Peter Mount | last post by:
Hi When I zoom into my site (http://www.petermount.au.com) with Opera 7.54 the horizontal scrollbar doesn't show when the site image is bigger than my screen. Yet the horizontal scrollbar shows in print preview and when I turn css off in Opera. Could it be a problem with my css? The code is: html{ padding-top: 0; padding-bottom: 0;
19
4908
by: Thomas Mlynarczyk | last post by:
Hello, The following gives different results in IE and "Non-IE" browsers: <div style="background-color: green; width: 200px"> <div style="margin-top: 20px; background-color: red"> Hello </div> </div>
2
2424
by: Stanimir Stamenkov | last post by:
I'm trying to clear some sizing issues relative to the initial containing block and the root document element. The sample document I'm trying with: http://stanio.info/viewport_fill.html Basically, for some tests I want to specify the height of an example DIV element inside the BODY using percentages of the viewport height. For this to work the BODY container should fill the viewport height where I'm using:
1
6618
by: camphor | last post by:
hi, I have a single column webpage with a horizontal dropdown menu and am trying to make the nav bar fit across the page, the column is 800px, it looks ok in dreamweaver 8 but when I test it in firefox, the nav bar which is a horizontal blue stripe with the links written inside it doesn't stretch the whole 800px, also how would you align the words in the submenu to the main menu, currently the submenus are centered html <body> <div...
3
3208
by: =?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?= | last post by:
Hello. I seek confirmation for the reasons behind a margin-related behavior I have observed. I have set up a simple test page to illustrate the issue. The page shows a very simple 2-column layout, where columns are contained in /div/ elements. The first column is floated left and the second one is offset by a left margin. You should be able to notice that the contents of the first column are lower than those of the second one. Is...
8
3554
by: ayamopamo | last post by:
Hi- I am trying to center a web page. It seems like this should be very simple to do, but apparently it isn't my day. I have successfully centered the background by calling it in the css body tag: body { font-family: Trebuchet MS, Arial; cursor : default; background:#000000 url("Images/long-template.jpg"); background-repeat:no-repeat; background-position: center; background-attachment:scroll; height: 1228px;
0
9471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10302
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9925
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7478
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4036
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.