How would i create the below using pure CSS (no images, no tables, no javascript)? alt text http://img530.imageshack.us/img530/3209/divs.png
Div tag has both open(<div>) and closing (</div>) tag and it is mandatory to close the tag. The Div is the most usable tag in web development because it helps us to separate out data in the web page and we can create a particular section for particular data or function in the web pages.
Use div in Web LayoutsYou can put together the header, nav, sections, and footer of a page in an individual div tag so they can be styled together. Later in this tutorial, I will take you through how to make a web layout with multiple div tags without getting confused.
Answer: Use CSS fixed positioning You can easily create sticky or fixed header and footer using the CSS fixed positioning. Simply apply the CSS position property with the value fixed in combination with the top and bottom property to place the element on the top or bottom of the viewport accordingly.
To start, wrap a div element in another div element in your HTML. Give the inner div a class name like "child" and the outer div a class name like "parent." Then in your CSS, use the class selector .parent to style the outer div. Set its height, width, and background color.
HTML:
<div class="box">
<h2>Div Title</h2>
<p>Div content.</p>
</div>
and the CSS:
.box {border:2px solid #0094ff;}
.box h2 {background:#0094ff;color:white;padding:10px;}
.box p {color:#333;padding:10px;}
Use CSS3 for border radius
.box {
-moz-border-radius-topright:5px;
-moz-border-radius-topleft:5px;
-webkit-border-top-right-radius:5px;
-webkit-border-top-left-radius:5px;
border-top-left-radius:5px;
border-top-right-radius:5px;
}
The above code will work in firefox, safari, chrome, opera (10.5 +) etc
Now with bonus demo
HTML:
<div class="myDiv">
<h2>Div Title</h2>
<p>Div content.</p>
</div>
CSS:
.myDiv {
border:2px solid #0094ff;
-webkit-border-top-left-radius:6px;
-webkit-border-top-right-radius:6px;
-moz-border-radius-topleft:6px;
-moz-border-radius-topright:6px;
border-top-left-radius:6px;
border-top-right-radius:6px;
width:300px;
font-size:12pt; /* or whatever */
}
.myDiv h2 {
padding:4px;
color:#fff;
margin:0;
background-color:#0094ff;
font-size:12pt; /* or whatever */
}
.myDiv p {
padding:4px;
}
Demo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With