<link rel="stylesheet" type="text/css" href="path_to_file"/>
.#id_name
. Give both left and right a height, width and colour. The Net treats censorship as a defect and routes around it.
John Gilmore, Founder of Electronic Frontier Foundation 1993
There are times when it is convenient to create a block on the page to be used by CSS and Javascript. The tag div is used to do this. div is a block element and is used widely to create structure on the page. There is also an inline equivalent of div called span. Both div and span are entirely structural elements and carry no Semantic meaning.
All body elements can have names attached to them to provide hooks for the CSS or Javascript. There are two types of names
CSS is a declarative language, which means that it is made up of a series of declaration blocks. The first part of the declaration determines element(s) of the HTML the block is going to operate on. This is called the selector and can be a single HTML element, an id or class name or a more complex statement. The next stage is to create the block which is done using the curly braces { }
. Inside the braces are the CSS commands. These commands follow the name/value pairs similar to the HTML attributes, but with different syntax.
In CSS not all commands can be used on every element, some CSS command can only be used on HTML block elements. Some CSS command names can have a single value, while others can have multiple values. In this session we will use the following command:
CSS commands can be in any order and can overwrite previously written commands. That is where the Cascading nature of CSS is important. Each block takes the CSS from the enclosing block (called the parent) and applies those commands to itself. However these can be overwritten by the current command block. For example in the sample CSS below, the whole page has a background colour of green. However the h2 command is sitting inside the body and should have the background set to green (from its parent the body tag) but has been overwritten by the colour yellowgreen. The order of the command in the file is important as they will be read and applied in the order they are written. This means that if you write two blocks on the h2 with different background colours, only the last one will be displayed. This especially applies where there is more than one file as the later files will overwrite the earlier files. It is good practise to set up your CSS file with the general styles at the top and the specific instance styles at the bottom.
body{
background: green;
color: yellow;
}
h1{
color: grey;
background: yellowgreen;
}
CSS is rapidly changing which means that it is difficult to follow a standard or for the browsers to keep pace. The process is for a feature to be proposed for adoption in CSS. The browsers then work out how to implementment this new feature and release a BETA version for general use. During this BETA phase the CSS command can be used on the newer browsers often with browser specific commands. Once all browsers are happy with the way the command works the standard command is released and adopted by all browsers. This takes time and sites like caniuse are helpful to track this process. In this course some BETA CSS commands will be used in Session 5.
The browsers are built to do the best job they can of rendering the page using the HTML and CSS that it is given. If you form the commands badly they will be ignored. Also you can use multiple commands for a single feature and the browser will only implement the commands that it knows. There are no error messages with HTML or CSS, which can be frustrating at times.
Every HTML element creates a box which can be manipulated by CSS.
This means that it is possible to apply the CSS commands for margin, border, and padding to all html elements. In practise margin and padding are best left to block level elements otherwise you may have some unexpected results.
CSS has six different ways to handle the various colours. Any of these can be used interchangeably, this is entirely personal preference. The use of hash codes (Hexadecimal) seems to be the most common, but all have their uses.
#
(#RED|GREEN|BLUE
). For example background: #FF0000
turns the background to red. rgb(255,0,0)
for red.hsl(360, 100%, 50%)
The most common measurements in CSS are px (eg 100px
), pt (eg 12pt
), em(eg 3em
) or percent (eg 80%
). These are detailed below:
The issue here is that the web page needs to work regardless of which screen/window size the user has available or wants to use, which device the page is view upon and which browser is used. This is the real challenge of web design, you can't locate things on a page using absolute measurement, like you can on a page which is printed in a standard size. The challenge is to develop a page which dynamically resizes and looks good regardless of size. CSS is making great strides but this goal is still to be reached. The new features of CSS (viewport dynamic measurements and dynamic displays through Flexible Box layout) are still in BETA or even pre-BETA, and show real promise.
It is good programming practise to place comments in your code, especially when working on one code base as a team. Comments can be placed in both HTML and CSS code, but the syntax is different.
In both CSS and HTML comments need be inside the comment start and finish marker, though the start and finish marker are different, see the table below.
Comment Start Marker | Comment End Marker | Example | |
---|---|---|---|
HTML | <!-- | --> | <!--This is an HTML comment--> |
CSS | /* | */ | /*This is a CSS comment*/ |