Web Design & Development
CSS
Introduction To CSS | Introduction To CSS |
|
|
|
| Written by Youssef | |
| Thursday, 17 July 2008 | |
What exactly is CSS?CSS stands for cascading style sheets. Ok, what does that mean? Look at it like this, XHTML contains the data/content to display, CSS decides how the content looks, and Javascript determines how the web page interacts. CSS provides not only structure to the web page like a table would but also stylization the content like background color and font size. How to apply attributes to different elementsAttributes are instructions of how elements in the HTML should look. Attributes can be anything from font-size to background-color, but this section describes how to effectively apply certain attributes to different elements.
Print vs ScreenBelieve it or not, you can create a CSS for when someone prints out a web page which is great for a visitor because usually if you print you just want the primary content. Generally, you want a very different style sheet as compared to the “screen” version. Using the attribute “display: none;” you can and should get ride of ads, a sidebar and any other information someone wouldn’t want to print out. You also want a black text on white background design, otherwise you’ll make people print too much ink. You link to the print CSS file almost exactly the same except for the ‘ media=”print” ‘ part. <link rel=”stylesheet” href=”style.css” type=”text/css” media=”screen” /> <!– for browser –> <link rel=”stylesheet” href=”print.css” type=”text/css” media=”print” /> <!– for printer –> CSS DefaultWhen you load your HTML file in any web browser whether it be Firefox, Internet Explorer or Safari, the browser will render the web page with certain style attributes already assigned. You can of course override these attributes with CSS, but if you don’t specify differently, the browser will render the page with certain attributes already applied. Each web browser has subtle difference in how they render a web page under defaults, but in general a web page will look the same. Save lines of code, be efficientFrom time to time, you’ll notice your coping and pasting attributes from one id or class to another. If you find yourself applying the same attributes to a few elements, then you can combine attribute assignments so that multiple classes, ids and elements share the attributes. Lets take the attributes for the left and right arrows on the javascript image gallery. I originally had this as the attributes: #moveleft{ <span> </span>margin:0px; <span> </span>height:58px; <span> </span>color: white; <span> </span>width: 16px; <span> </span>text-indent: -2000em; <span> </span>text-decoration: none; <span> </span>z-index: 1000; <span> </span>display:block; <span> </span>cursor: pointer; <span> </span>float:left; <span> </span>background: url('left.gif'); } #moveright{ <span> </span>margin:0px; <span> </span>height:58px; <span> </span>color: white; <span> </span>width: 16px; <span> </span>text-indent: -2000em; <span> </span>text-decoration: none; <span> </span>z-index: 1000; <span> </span>display:block; <span> </span>cursor: pointer; <span> </span>float:left; <span> </span>background: url('right.gif'); } This is silly though because the two are essentially duplicates of each other except for the background image. We can though apply one set of attributes to both ids (using a comma to include more elements) and set the background to their respective urls: #moveleft, #moveright{ margin:0px; } #moveleft{background: url(’left.gif’);} #moveright{background: url(’right.gif’);} ConclusionThe mark of a good CSS designer is one that creates the CSS for the HTML. If you start designing your HTML around what you can do with the CSS, you still have more to learn. In the future, I’ll delve into the basics of taking a design in Photoshop into HTML web page. |