Monday, 22 April 2013

Style tag in HTML5


The HTML <style> tag is used for declaring style sheets within your HTML document. The <style> tag is supported in all major browsers. The required type attribute defines the content of the style element. The only possible value is "text/css". The style element always goes inside the head section.
let's look at an example. If you want the color of some text to look red, the style attribute would look like this:

style="color:red"
The style sheet property is "color". The value of the color is "red". Notice there is a colon in between color and red, not an equal sign, and there are no extra quote marks.
Insert style into an HTML tag, such as the <DIV> tag. Place a semicolon after your first property and value, and add another. So if we want the text to be red and to be italic, we would do the following:
<DIV style="color:red; font-style:italic">This style for some red-hot italic text!</DIV>
Attributes
HTML tags can contain one or more attributes. Attributes are added to a tag to provide the browser with more information about how the tag should appear or behave.
There are 3 kinds of attributes that you can add to your HTML tags: Element-specific, global, and event handler content attributes. The attributes that you can add to this tag are listed below.
Element-Specific Attributes
The following table shows the attributes that are specific to this tag/element.
Attributes Introduced by HTML5
AttributesDescription             
Typetype is used to specify the content type which is generally text/css.
Mediamedia can be used to specify which media the styles are associated to. A value such as screen, print, projection, braille, speech or all can be used or a combination in a comma-separated list.
Scopedif the <style> tag is being used outside of the document <head>, it must have the scoped attribute.
Global Attributes
The following attributes are standard across all HTML 5 tags.
HTML5 Global Attributes
accesskeydraggablestyle
classhiddentabindex
dirspellcheck 
contenteditableidtitle
contextmenulang 

Event Handler Content Attributes

Here are the standard HTML 5 event handler content attributes.
onabortonerror*onmousewheel
onblur*onfocus*onpause
oncanplayonformchangeonplay
oncanplaythroughonforminputonplaying
onchangeoninputonprogress
onclickoninvalidonratechange
oncontextmenuonkeydownonreadystatechange
ondblclickonkeypressonscroll
ondragonkeyuponseeked
ondragendonload*onseeking
ondragenteronloadeddataonselect
ondragleaveonloadedmetadataonshow
ondragoveronloadstartonstalled
ondragstartonmousedownonsubmit
ondroponmousemoveonsuspend
ondurationchangeonmouseoutontimeupdate
onemptiedonmouseoveronvolumechange
onendedonmouseuponwaiting
For Example
<html>
<head>
<style type="text/css">
h1 {color:red;}
p {color:blue;}
</style>
</head>
<body>
<h1>Style tag in HTML5</h1>
<p>A paragraph.<br />The HTML style tag is used for declaring style sheets within your HTML document. The <style> tag is supported in all major browsers. The required type attribute defines the content of the style element. </p>
   
</body>
</html>

Internet Explorer]

style1.gif

Fire Fox  

style2.gif

Type attribute

The type attribute identifies the content between the <style> and </style> tags. The value "text/css" indicates that the content is standard CSS.

<style type="text/css">
h1 {color:red}
p {color:blue}
</style>
</head>

<body>
<h1>Header 1</h1>
<p>A paragraph.</p>
</body>

Media Attribute

The media attribute is used to specify different styles for different media types. To define more than one media type per style element, use a comma   separated list.

<style type="text/css" media="screen,projection">

For Example

<html>
<head>
<style type="text/css">
h1 {color:#FF0000;}
p {color:#0000FF;}
body {background-color:#FFEFD6;}
</style>

<style type="text/css" media="print">
h1 {color:#000000;}
p {color:#000000;}
body {background-color:#FFFFFF;}
</style>
</head>

<body>
<h1>Example of media attribete</h1>
<p>A paragraph.</p>
</body>
</html>
Internet explorer
style3.gif

No comments:

Post a Comment