Cascading Style Sheets: Basic CSS syntax

  1. Margins and padding
  2. CSS
  3. Advanced CSS syntax

Style sheet syntax is fairly simple: the name of the HTML tag you wish to modify, a space, an opening curly bracket, and then a list of modifiers and a closing curly bracket.

The modifiers themselves are a name, a colon, and then a value, followed by a semicolon.

tagname {

modifiername: value;

}

You can have as many tag names and modifier names as you want. If two modifiers conflict with each other, the last modifier takes precedence. For example, if you set all margins to 10%, and then set margin-left to 20% later, the left margin will be 20% and the rest of the margins will be 10%. But if you do it in the reverse order: first specify the margin-left and then specify all margins, then all margins will be 10%.

The last modifier you specify is the one that takes effect.

Let’s say that you want all of your headlines to have an indented border on the top and bottom. You can specify multiple tag names in for your style sheet definition by separating them with commas.

Add the following definition below the body definition that we already have:

h1, h2 {

border-top-style: inset;

border-bottom-style: inset;

border-width: .15em;

border-color: orange;

color: brown;

}

image 7

This changes the appearance of all of our h1 and our h2 tags. They get a border on the top and bottom, and their color changes to brown.

  1. Margins and padding
  2. CSS
  3. Advanced CSS syntax