[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2009-04-07
6
Medium Priority
?
310 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 2000 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

Technology Partners: 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

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…

650 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