Juddles
Juddles

Reputation: 757

Columns in CSS3 and HTML5

I'm trying to break the line between my pairs of columns and really having some trouble. I want the 1st column centered on the page, the second smaller column to the right of it.

This would be repeated below this pair of columns.

<html>

<head>
        <title>Choose to Give</title>
        <link rel="stylesheet" type="text/css" href="web.css" />
</head>


<body>

<ul class="nav">
  <li><a href="/home/">Home</a></li>
  <li><a href="/about_us/">About</a></li>
  <li><a href="/foundations/">Foundations</a></li>
  <li><a href="/forums/">Forums</a></li>
  <li><a href="/contact/">Contact</a></li>
</ul>



<div class="column1of2">
<h2>
Do something that matters.
blah blah
</h2>
</div>


<div class="column2of2">
<h2>
Top user contributions.
</h2>
</div>

<br>

<div class="column1of2">
<h2>
Random title here
blah blah
</h2>
</div>


<div class="column2of2">
<h2>
Top company contributions.
</h2>
</div>


</body>


</html>

And then the CSS.

body {
        background-color:#66FF33;
        font-size: 8pt;
        color: black;
        text-align: left;
}




.nav{
        border:10px solid black;
        background-color: white;
        border-width:10px 0;
        list-style:none;
        padding:0;
        margin-top: 10%;
        text-align:center;
        font-size: 12pt;
}
.nav li{
        display:inline;
}
.nav a{
        display:inline-block;
        padding:10px;
}


h1 {
        text-align: left;
        color: black;
        background-color: white;
        padding: 30px;
        border-style: solid;
        border-width: 10px;
        border-left-width: 10px;
        border-right-width: 10px;
        border-color: black;
        border-radius: 5px;

}


h2 {
        text-align: left;
        color: black;
        background-color: white;
        padding: 30px;
        border-style: solid;
        border-width: 10px;
        border-left-width: 10px;
        border-right-width: 10px;
        border-color: black;
        border-radius: 5px;

}

.column1of2 {
float: left;
width: 30%;
left-margin: 10%;
}

.column2of2 {
float: right;
width: 15%;
right-margin: 2%;
}

Upvotes: 0

Views: 241

Answers (2)

Vish
Vish

Reputation: 169

This can be don using the a div which holds both the divs column1of2 and column2of2 in it where in we can give margin:0px auto to column1of2 along with float:left and for column2of2 we can give float:right and margin-left:5%; After closing the div of column2of2 we can add another div and then closing the div "row_holder" and having css for the class clear as .clear{clear:both;}.

Upvotes: 1

Atif Azad
Atif Azad

Reputation: 527

use clear left for the

 .column1of2 {clear:left}

Upvotes: 2

Related Questions