two divs side by side

This is a discussion on "two divs side by side" within the Web Page Design section. This forum, and the thread "two divs side by side are both part of the Design Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Aug 9th, 2007, 19:13
Junior Member
Join Date: Jul 2007
Location: Arkansas, USA
Age: 21
Posts: 45
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
two divs side by side

How do you get two divs to be side by side?
Last Blog Entry: First Post! (Apr 18th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Aug 9th, 2007, 20:30
Junior Member
Join Date: Jul 2007
Location: Dallas, TX
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Re: two divs side by side

Here's a very short thumbnail view about DIVs.

DIVs (think of it as a shorter term for DIVision) are the basic building blocks of CSS.

By default, a DIV wants to extend 100% of the screen unless a width is specified.

DIVs also, by default 'stack' on top of each other.

It is possible to 'float' an element to the left or right of another element, and thus you can have two DIVs side-by-side.

I might suggest that you read through the CSS section of this forum as well as other online resources such as www.w3schools.com to get a basic overview of CSS.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Aug 9th, 2007, 20:35
Elite Veteran
Join Date: Sep 2006
Location: Pink House
Posts: 3,946
Thanks: 0
Thanked 0 Times in 0 Posts
Re: two divs side by side

Here's a simple example

css

Code: Select all
.container {
    width: 50%;
    float: left;
    text-align: center;
    }
html
Code: Select all
<body>
<div class="container">First Div</div>
<div class="container">Second Div</div>
</body>
</html>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Aug 9th, 2007, 21:18
Marc's Avatar
Staff Manager

SuperMember
Join Date: Apr 2007
Location: Scotland, UK
Posts: 1,801
Thanks: 0
Thanked 17 Times in 17 Posts
Re: two divs side by side

Linda, i think you missed a bit.....!

CSS:
Code: Select all
    #container {
    width: 700px;
    }  
 
    .left {
    width: 50%;
    float: right;
    text-align: center;
    }
 
    .right{
    width: 50%;
    float: right;
    text-align: center;
    }
Code: Select all
 
<div id="container">
 
<div class="left">   Left Column   </div>
 
<div class="right">  Right Column   </div>
 
</div>
Basicly what the above is doing is puting the two columns into a big div (#container) with the width of 700px. The 2 columns are 50% so they will each be 50% of the big div = 350px. If that makes sense!
__________________
Marc
Staff Manager - Webforumz.com


Want to be a moderator? PM me.

Last edited by Marc; Aug 9th, 2007 at 21:30.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Aug 9th, 2007, 21:29
Marc's Avatar
Staff Manager

SuperMember
Join Date: Apr 2007
Location: Scotland, UK
Posts: 1,801
Thanks: 0
Thanked 17 Times in 17 Posts
Re: two divs side by side

Grrr... Why does the HTML code always go like that? Thats it ill change it to [code ]....[/code ] tags!
__________________
Marc
Staff Manager - Webforumz.com


Want to be a moderator? PM me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Aug 9th, 2007, 22:05
Most Reputable Member
Join Date: May 2006
Location: North West, UK
Age: 22
Posts: 1,173
Thanks: 0
Thanked 0 Times in 0 Posts
Re: two divs side by side

No her code is fine. They'll just float left of each other in much the same way that li's do in a list. Her code is very efficient that's all. That code should work anyway.

Pete.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Aug 9th, 2007, 22:07
Elite Veteran
Join Date: Sep 2006
Location: Pink House
Posts: 3,946
Thanks: 0
Thanked 0 Times in 0 Posts
Re: two divs side by side

The question was... how do you put two div's side by side. I didn't place a container or wrapper because technically it's not necessary.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Aug 9th, 2007, 22:08
Marc's Avatar
Staff Manager

SuperMember
Join Date: Apr 2007
Location: Scotland, UK
Posts: 1,801
Thanks: 0
Thanked 17 Times in 17 Posts
Re: two divs side by side

Oh.. Cool!!! I never knew that you can do that! You learn somthing new every day dont ya? Sorry Linda!
__________________
Marc
Staff Manager - Webforumz.com


Want to be a moderator? PM me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Aug 9th, 2007, 22:09
Most Reputable Member
Join Date: May 2006
Location: North West, UK
Age: 22
Posts: 1,173
Thanks: 0
Thanked 0 Times in 0 Posts
Re: two divs side by side

No linda, Marc thought you needed to float: right; the right hand side div to get it to work but you don't.

Pete.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Aug 9th, 2007, 22:14
Elite Veteran
Join Date: Sep 2006
Location: Pink House
Posts: 3,946
Thanks: 0
Thanked 0 Times in 0 Posts
Re: two divs side by side

No problem Marc! It's ok... I make mistakes a lot so it's ok to check my posts!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Aug 9th, 2007, 23:28
Junior Member
Join Date: Jul 2007
Location: Arkansas, USA
Age: 21
Posts: 45
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: two divs side by side

That is what I used but it wasn't working so I changed it to have 2 containers: one set to left and one set to right and that worked.
Last Blog Entry: First Post! (Apr 18th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
css, div, html

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i put a border only on a certain side snelll Web Page Design 15 May 28th, 2008 13:30
Side by side positioning josephman1988 Web Page Design 7 Oct 20th, 2007 12:49
Side Column with CSS Pádraig Web Page Design 2 Aug 8th, 2007 12:36
pictures side by side thisandthat Web Page Design 3 May 16th, 2006 00:36
Client-Side VS Server Side Scripting redev2006 JavaScript Forum 1 Jul 30th, 2005 19:30


All times are GMT. The time now is 21:18.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved