CSS Building Blocks

A style sheet is a text file that contains one or more rules that determine, through property and value, how certain elements in your web page would be displayed. CSS can be created outside of a web page and can be applied to all the pages of a web site at once. A style sheet has following constructs -

  • Style sheet
  • Rule
  • Selector
  • Declaration
  • Property
  • Value

Curly braces, Colons, and Semi-colons are used to mark the beginning and ending of each part, separating them from each other. The following rule shows the parts of a style sheet and the special characters that separate them.

SELECTOR –> body { <- Declaration Block Start
width: 400px; <- Declaration
PROPERTY -> color: #FFF; <- VALUE
} <- Declaration Block End

Things to remember :-


In CSS, A style rule has two main parts – the selector and the declaration block.


In CSS, a selector is the HTML element or elements to which a CSS rule is applied


In CSS, Comments can be put between /* and */.


Example – example1.html



</html>


<header>


   <link rel="stylesheet" type="text/css" href="example1.css">


</header>


<body>


<h1>What is this ?</h1>


<img src="Picture 021.jpg" width="300" height="175"/>


<p>A lovely <em>beautiful</em>


Christmas tree.</p>


<p><small>&copy; by Ramdhari.</small></p>


</body>


</html>


exmaple1.css


p {


     color: green;


     font-family: "Trebuchet MS", "Helvetica", sans-serif;


     font-weight: bold;


}


img {


     float: right;


     margin-right: 100px;


}


Keep the html and css file in same directory and open the html in a browser and play with the property, value and check that in the browser.


The sample html and css file can be found here.

Comments

Popular posts from this blog

Palindrome program in Java using BufferedReader

OOPS: Decomposition and Abstraction