Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

3 columns with spacing between, help

Featured Replies

I have some problems with creating a 3 column setup in CSS. The problem is when I want spacing between the columns.

 

I have tried this:

 

CSS:

#around {
text-align: left;
margin: 0px;
padding: 0px;
border:0;
width: 693px;
background-color:black;
}


#leftcol {
float: left;
width: 231px;
background-color:red;
}

#rightcol {
float: right;
width: 231px;
background-color:blue;
}

#centercol { 
float: left;
width: 231px;
background-color:green;
}

 

 

This makes no space between them, so I tried with padding-right:5px at the leftcol padding-left:5px padding-right:5px at the centercol and padding-left:5px at the rightcol, but this just made a mess.

 

What do I do wrong?

Anyone able to help? thank you...

Put a margin on the elements inside each column.

 

Eg...

 

#rightcol p { margin: 10px; }

 

That'll bump your paragraphs 10px in from the edge, without making the columns drop.

No problem.

 

Also, if you find that one column drops in IE6, try making one of the columns 1px thinner. IE6 doesn't seem to like maths. ;)

  • Author

One more problem...

This worked with text in the columns, but when I try to insert a picture in the colums I got a little problem.

Got any great ide to solve this? :)

 

Tried doing this:

 

#around {
text-align: left;
margin: 0px auto;
padding: 0px;
border:0;
width: 693px;
}


#left3col {
float: left;
width: 231px;
background-color: blue;
}

#right3col {
float: right;
width: 231px;
background-color: red;
}

#center3col { 
float: left;
width: 231px;
background-color: green;
}

#left3col p img { 
margin-right:5px; 
margin-top:0;
margin-left:0;
margin-bottom:0;
text-align:justify; }

#right3col p img { 
margin-left:5px;
margin-top:0;
margin-right:0;
margin-bottom:0;
text-align:justify; }

#center3col p img { 
margin-right:5px; 
margin-top:0;
margin-left:5px;
margin-bottom:0;
text-align:justify; }

Maths time!

 

Width of column - margin = x.

 

If x is smaller than the width of your image, you'll have problems.

To avoid applying padding to a floated div, an alternative would be to create an additional class say

 

.inside10 {
padding:10px;
}

and then in the markup you create a nested div inside the floats and apply the inside10 class to them i.e.

 

<div id="leftcol">
<div class="inside10">Left Content</div>
</div>

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.