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.

Help with columns using CSS

Featured Replies

Hi clever CSS people

 

I dont have a live site to show you (yet!) so I'll explain as best as possible.

I've given my webpage a width of 1240px which stops things getting messed up if I restore down or resize the browser window.

 

CSS:

 

#body {

width:1240px;

margin; 0 auto;

}

 

On my home page I have a logo in the top right, picture in the middle and some contact details in the top right - like a "banner" I suppose.

 

What I'd like to is to have two columns on the page below the "banner"

 

Something like:

 

 

Latest News About Us

 

CONTENT GOES HERE CONTENT GOES HERE

 

 

I'm really struggling to accomplish this simple layout.

Here is my CSS info for the left and right columns and headings:

 

#h1 {

font-size:220%;

font-family:"Times";

font-weight:bold;

text-align:center;

color:#000099;

 

}

 

#h2 {

float:left;

margin-left:200px;

font-size:220%;

font-family:"Times";

font-weight:bold;

color:#000099;

}

 

#left {

width: 400px;

height: 500px;

float: left;

}

 

#right {

margin-right:100px;

width: 500px;

height: 750px;

float: right;

 

Here is what I've put in the html file:

 

<div id="h1">Welcome to my webpage</div>

<div id="right">

<div id="h1">About Us</div>

SOME CONTENT.

</div>

<div id="h2">Latest News</div>

<div id="left">

SOME CONTENT

</div>

 

Am I using too many divs? I don't fully understand when to use div or class (or span??).

The heading and column to the right looks fine.

The heading to the left also looks fine.

 

However the text from the left column overlaps the right column text no matter what I do to the width of the column.

It's like the left div is not being applied to the text within it. I've checked my css file for mistakes, missing { }'s etc but know its all correct.

 

I'm thinking it may also have to do with inheriting?

 

gah, please help this struggling newbie :help:

  • Author

Well I've got my columns working.

Sort of.

 

But I've put things in the div like margin-top:-200px; etc.

Each time I adjust a picture or slideshow to the left of one column it moves the column down so I end up having to adjust the top margin value to bring it up.

 

Whilst it works I'm sure there is a better way to do it.

This is how you learn.

Edited by Webtastic

  • Author

<div> is the generic block-level element for when nothing else is appropriate. <span> is the equivalent inline element.

 

Hi Renaissance-Design

 

Thanks very much for the reply.

Could you give me an example of when and how you would use <div> and <span> please?

 

I do remember <span> from my course (briefly!).

For me it seems whenever I want to place something (text column, picture, etc) at a different place on a webpage, I use <div> to do it.

Ok, so let's say you're dividing a page into a header, content area and footer - that's the perfect time to use <div>s, because they're going to contain other block-level elements like <p>, <ul>, more <div>s etc. Only block-level elements can contain block-level elements.

 

A block-level element (without styling) will take up 100% of the horizontal space until all its content is output and is followed by a line break. An inline element such as <span>, <em> <strong> or <a> must be contained within a block-level element and does not cause a line break.

  • Author

Ok, so let's say you're dividing a page into a header, content area and footer - that's the perfect time to use <div>s, because they're going to contain other block-level elements like <p>, <ul>, more <div>s etc. Only block-level elements can contain block-level elements.

 

A block-level element (without styling) will take up 100% of the horizontal space until all its content is output and is followed by a line break. An inline element such as <span>, <em> <strong> or <a> must be contained within a block-level element and does not cause a line break.

 

Great!

I think I actually understand that!

+1

 

Many thanks

Webtastic

Edited by Webtastic

Just a couple of things I noticed... Its there a reason why the left title (H1) is not center aligned and the right title (H2) is?

 

Anyways, one thing you have to certainly do when creating columns with css is making sure your columns are being wrapped by another div (Also there is nothing wrong with using a lot of div tags), that way when the screen resolution of the user viewing your webpage has a smaller screen size then your webpage width, it will keep the columns next to each other rather then pushing one column down.

 

Second note, all your columns should float the same direction (preferably left) so that the columns stick next to each other rather then having a gap if LeftCol_Width + RightCol_Width does not = WebPage_Width.

 

Just some food for thought.

Guest
This topic is now closed to further replies.

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.