CSS: Where Little Things Mean a Lot - CSS and the DIV Tag
(Page 3 of 3 )
OK, so you’re convinced now right? I’m sure you’d like to know just how powerful this file really is. Here is the answer:
Almost everything can be controlled by this file including (to an extent) the overall layout of your site. Some sites, like Wired.com, have created their entire site with the use of CSS to control their layout. As you will see, they’ve employed a fairly complex layout--all through the use of CSS!
I will let you in on a secret though, they make extensive use of the <div> tag. This is a block level element, meaning that it will live on it’s own line unless told otherwise, in much the same way that a <blockquote> tag will be on its own line, and not ‘inline’ with anything else. In each <div> tag you can set what ‘class’ (or type) of section of the site it will hold, for example you could change the HTML file to have:
<div class=”title”> Examples 'R' Us</div>
Viewing this will be no different to what it was before, unless we change the CSS file accordingly to alter the settings for this class, for example:
div
.title{
width:100%;
height:25px;
background: #FF0000;
border-style: solid;
border-color: #FFFFFF;
border-width: 2px;
}
Now looking at the web page, it has changed again to represent the changes made to the CSS file. To see some of the other features of CSS displayed download the support file for this article (available here). By having a look at the accompanying files, you will see that two extra <div> tags were added; one named ‘side’ and another named ‘main’. Each has their own different style which is controlled entirely by the Style Sheet (CSS file).
Looking at the Style Sheet attached to the support file, you will also notice that the ‘a’ (anchor) tag has also had an overhaul. Instead of having the default blue-colored underlined links, the code in the Style Sheet now tells the browser to display links in red, with no underline. When the mouse goes over the link, they change to blue, with an underline and overline to catch the viewer’s attention. A few other changes have been made to the original Style Sheet that we created earlier, but nothing that you shouldn’t be able to spot.
Your next step is to check out a site that lists all the elements that you can play with using CSS and what you can do with each element. This article was only a tip of the CSS iceberg. The powers of CSS are too huge to contain in one article, so I would suggest that you purchase a book on CSS, as you will find yourself looking it up time after time to get your site to look just the way you want.
Happy coding!
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |