PROGRAMMING COURSES ADMIN VIDEO TUTORIALS COMMUNITY RESOURCES |
Now that we have our main.css style sheet linked to our index.html page
we can add code into our HTML tags to have them styled individually or
by group from the style sheet.
class - Used to group and style page tags. Multiple page tags can have the same class name applied. id - Used to style individual tags on the page. Only one tag on the page can be tied to an id. Here is an example of using the class and id attributes on different kinds of HTML tags to make all of them have the same style. In the example below we have given the <h2> tag the id attribute to make it behave slightly different from the other tags by applying "mystyle2" from the style sheet to it as well as the class style "mystyle1". index.html ![]() <html>
<head> <title>My Web Page</title> <link href="style/main.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="mystyle1">Here is content in a div tag</div> <hr class="mystyle1" / > <p class="mystyle1">Here is content in a p tag</p> <h2 class="mystyle1" id="mystyle2">Here is content in a H2 tag</h2> <img src="images/my_pic.jpg" class="mystyle1" /> </body> </html> And this is what your style sheet would look like defining mystyle1 and mystyle2. main.css ![]() /* We define a class style using a [.] */
.mystyle1 { background-color:#333366; color:#00FFFF; padding: 8px; letter-spacing:.5em; border-width: thick; border-style: solid; border-color: #990000 #0000FF #996600 #009900; } /* We define an ID style using a [#] */ #mystyle2 { width:350px; height:150px; margin-left:100px; } You can add the class or id attributes to most HTML tags. Experiment with any tags you want. Below we have given some examples for reference.
|
|||||||||||||||||
|
|
DevelopPHP Requires Flash Player
___________________________________________
|
||||||||