Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Half the page + CSS alignment

Tags:

css

alignment

I didn't know how to explain but draw a picture of the CSS align that I need. The template has a fixed width and the green area represents the main content and blue division provides the title for that page.

The green div has the following css:

#content {
  width: 980px;
  margin: 0 auto;
} 

This works great for the green box but I don't know how to make the blue section. That div needs to cover the right side of the page + the entire width of the green area as you can see from the picture below.

Bear in mind that user can resize the window so the width of the blue bit cannot be fixed!

How can I achieve this using pure CSS?

http://img15.imageshack.us/img15/3884/cssalign.png

like image 895
SwissChocolate Avatar asked Jul 30 '11 00:07

SwissChocolate


People also ask

How do I make my div half the screen?

Using float and marginThe left div is styled with width:50% and float:left – this creates the green colored div that horizontally covers half of the screen. The right div is then set to margin-left:50% – this immediately places it to the right of the left div.

How do you properly align in CSS?

To align things in the inline direction, use the properties which begin with justify- . Use justify-content to distribute space between grid tracks, and justify-items or justify-self to align items inside their grid area in the inline direction.

How do you center a div in the middle of the page vertically?

You can do this by setting the display property to "flex." Then define the align-items and justify-content property to “center.” This will tell the browser to center the flex item (the div within the div) vertically and horizontally.


1 Answers

Just like the picture !

Css :

#title{
   position:relative;
   width:50%;
   margin:50px 0 50px 50%;
   background:blue;
   padding:25px 245px;
   left:-490px;
}
#content{
     width:980px;
     height:600px; /* for it to work with no content */
     margin:0 auto;
     background:green;
}

Html :

<div id="title"></div>
<div id="content"></div>

DEMO : http://jsfiddle.net/sparkup/jL10axxv/

like image 56
Sparkup Avatar answered Sep 28 '22 05:09

Sparkup