Pages

Showing posts with label CSS for Dummy. Show all posts
Showing posts with label CSS for Dummy. Show all posts

Monday, 16 December 2013

CSS Spans

Spans are very similar to divisions except they are an inline element versus a block level element. No linebreak is created when a span is declared.
You can use the span tag to style certain areas of text, as shown in the following:
<span class=”italic”>This text is italic</span>
Then in my CSS file:
.italic{ 
  font-style: italic; 
}
The final result is: This text is italic.
The purpose of the last 2 chapters was to provide you with a basis for using CSS in an (X)HTML file. For a more detailed explaination of XHTML please visit W3Schools

CSS Divisions

Ok so you have finished the first 4 chapters in my series. You have learned the very basics of CSS, how the syntax works and a bit about classes and IDs. Now we are gonna take a quick break from CSS and focus on the (X)HTML side of using it.

Divsions


Divisions are a block level (X)HTML element used to define sections of an (X)HTML file. A division can contain all the parts that make up your website. Including additional divisions, spans, images, text and so on.

You define a division within an (X)HTML file by placing the following between the <body></body> tags:


<div>
Site contents go here
</div>
Though most likely you will want to add some style to it. You can do that in the following fashion:
<div id=”container”>
Site contents go here
</div>
The CSS file contains this:
#container{
  width: 70%;
  margin: auto;
  padding: 20px;
  border: 1px solid #666;
  background: #ffffff;
}
Now everything within that division will be styled by the “container” style rule, I defined within my CSS file. A division creates a linebreak by default. You can use both classes andIDs with a division tag to style sections of your website.

CSS IDs

IDs are similar to classes, except once a specific id has been declared it cannot be used again within the same (X)HTML file.
I generally use IDs to style the layout elements of a page that will only be needed once, whereas I use classes to style text and such that may be declared multiple times.
The main container for this page is defined by the following.
<div id=”container”>
Everything within my document is inside this division.
</div>
I have chosen the id selector for the “container” division over a class, because I only need to use it one time within this file.
Then in my CSS file I have the following:
#container{ 
  width: 80%;
  margin: auto;
  padding: 20px;
  border: 1px solid #666;
  background: #ffffff;
}
You will notice that the id selector begins with a (#) number sign instead of a (.) period, as the class selector does.

CSS Classes

The class selector allows you to style items within the same (X)HTML element differently. Similiar to what I mentioned in the introduction about inline styles. Except with classes the style can be overwritten by changing out stylesheets. You can use the same class selector again and again within an (X)HTML file.
To put it more simply, this sentence you are reading is defined in my CSS file with the following.
p { 
  font-size: small; 
  color: #333333
}
Pretty simple, but lets say that I wanted to change the word “sentence” to green bold text, while leaving the rest of the sentence untouched. I would do the following to my (X)HTML file.
<p>
To put it more simply, this <span class=”greenboldtext”>sentence</span> you are reading is styled in my CSS file by the following.
</p>
Then in my CSS file I would add this style selector:
.greenboldtext{ 
  font-size: small; 
  color: #008080;
  font-weight: bold;
}
The final result would look like the following:
To put it more simply, this sentence you are reading is styled in my CSS file by the following.
Please note that a class selector begins with a (.) period. The reason I named it “greenboldtext” is for example purposes, you can name it whatever you want. Though I do encourage you to use selector names that are descriptive. You can reuse the “greenboldtext” class as many times as you want.