Solved

Having trouble lining up columns.  I'm using CSS not tables.

Posted on 2009-04-07
6
298 Views
Last Modified: 2012-05-06
Using the CSS and HTML code shown below I am trying to display two rows with for left-justified columns.  However its not working for me.  The display looks like this:

Item One          Item Two          Item Three       Item Four
Item Five            Item Six            Item Seven        Item Eight

Does anyone have words of wisdom that might help me fix this problem?

Thanks.
<style>
span.col2 {
	margin-left: 20em;
}
 
span.col3 {
	margin-left: 30em;
}
 
span.col4 {
	margin-left: 50em;
}
 
 
div.row {
font-weight: bold;
width: 60%;
float: left;
padding-top: 5px;
padding-left: 0px;
padding-bottom: 5px;
padding-right: 0px
}
</style>
 
<div class="row">			
Item One			
<span class="col2">
Item Two
</span>
<span class="col3">
Item Three
</span>
<span class="col4">				
Item Four
</span>
</div>
			
<div class="row">
Item Five			
<span class="col2">			
Item Six						
</span>
<span class="col3">
Item Seven
</span>
<span  class="col4">			
Item Eight
</span>
</div>

Open in new window

0
Comment
Question by:jwright9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 9

Expert Comment

by:Ramanhp
ID: 24092262
<style>
span.col2 {
        margin-left: 10em;
 width:100px;
}
 
span.col3 {
        margin-left: 10em; width:100px;
 
}
 
span.col4 {
        margin-left: 10em; width:100px;
 
}
 
 
div.row {
overflow: auto;
font-weight: bold;
width: 100%;
float: left;
padding-top: 5px;
padding-left: 0px;
padding-bottom: 5px;
padding-right: 0px
}
</style>
 
<div class="row">                      
Item One                        
<span class="col2">
Item Two
</span>
<span class="col3">
Item Three
</span>
<span class="col4">                            
Item Four
</span>
</div>
                       
<div class="row">
Item Five                      
<span class="col2">                    
Item Six                                                
</span>
<span class="col3">
Item Seven
</span>
<span  class="col4">                    
Item Eight
</span>
</div>
0
 
LVL 9

Expert Comment

by:Ramanhp
ID: 24092300
<style>
span.col2 {
        margin-left: 10em; width:120px;
}
 
span.col3 {
        margin-left: 10em; width:120px;
 
}
 
span.col4 {
        margin-left: 10em; width:120px;
 
}
 
 
div.row {
overflow: auto;
font-weight: bold;
width: 100%;
float: left;
padding-top: 5px;
padding-left: 0px;
padding-bottom: 5px;
padding-right: 0px
}
</style>
 
<div class="row">                      
Item One                        
<span class="col2">
Item Two
</span>
<span class="col3">
Item Three
</span>
<span class="col4">                            
Item Four
</span>
</div>
                       
<div class="row">
Item Five                      
<span class="col2">                    
Item Six                                                
</span>
<span class="col3">
Item Seven
</span>
<span  class="col4">                    
Item Eight
</span>
</div>
0
 
LVL 4

Expert Comment

by:iDeej
ID: 24092391
Using floating is another way to go her also:

HTML:
               <div class="row">
                    <div class="colsLeft">
                        <div class="col1">
                            <h1>Col1</h1>
                        </div>
                        <div class="col2">
                            <h1>Col2</h1>
                        </div>
                    </div>
                    <div class="colsRight">
                        <div class="col3">
                            <h1>Col3</h1>
                        </div>
                        <div class="col4">
                            <h1>Col4</h1>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="colsLeft">
                        <div class="col1">
                            <h1>Col5</h1>
                        </div>
                        <div class="col2">
                            <h1>Col6</h1>
                        </div>
                    </div>
                    <div class="colsRight">
                        <div class="col3">
                            <h1>Col7</h1>
                        </div>
                        <div class="col4">
                            <h1>Col8</h1>
                        </div>
                    </div>
                </div>

CSS:

.row {
    clear:both;
    width: 60%;
    float: left;
    padding-bottom: 10px;
}

.colsLeft {
    width: 48%;
    float: left;
}

.colsRight {
    width: 48%;
    float: right;
}

.col1, .col3 {
    width: 48%;
    float: left;
    background: #ddd;
}

.col2, .col4 {
    width: 48%;
    float: right;
    background: #bbb;
}
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jwright9
ID: 24092434
Hi iDeej, I think your solution would work for two column layout but I need a four column layout.  Might you know how to do that?
0
 
LVL 4

Accepted Solution

by:
iDeej earned 500 total points
ID: 24092571
hello jwright,

this code creates two columns which each contain two more columns essentially giving you 4 columns.

I often use this for 3 column layouts where the left column will contain one column of navigation and the right column will contain the main content column and the right column.

I have tested the code and get two rows of 4 columns. If you test the code you should see that I have set background colors to make this clearer.

hope it helps,

Daniel.
0
 

Author Closing Comment

by:jwright9
ID: 31567770
Daniel,  Thanks so much for your help.  Your solution works awesomely!  J.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Check input text, Number 7 54
allow link tag to be submit like form 15 60
Incorrect css styling in footer 3 24
Expanding/Collapsing Tree on SharePoint List 29 62
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question