Cascading Style Sheets: Prepared By: E.Swathi, Asst - Prof., CSE, CBIT 1
Cascading Style Sheets: Prepared By: E.Swathi, Asst - Prof., CSE, CBIT 1
• If no style sheet information is specified, the browser default property values are used.
• The type attribute of the <style> tag tells the browser the type of style specification,
which is always text/css.
• Each style rule in a rule list has two parts: a selector, which indicates the tag or tags
affected by the rule, and a list of property–value pairs.
• The form of a style rule is as follows:
• Selectors can also specify that the style should apply only to elements in certain
positions in the document. This is done by listing the element hierarchy in the selector,
with only white space separating the element names. For example, the rule
form em {font-size: 14pt;}
• This applies its style only to the content of emphasis elements that are nested in a form
element in the document. This is a contextual selector (sometimes called adescendant
selector).
<h1>Welcome to My Homepage</h1>
<div>
<p id="firstname">My name is Donald.</p>
</div>
<h1>Welcome to My Homepage</h1>
<div>
<p>My name is Donald.</p>
<p>I live in Duckburg.</p>
</div>
</body>
Example:
<head>
<style type="text/css">
input:hover{color:red;}
input:focus{color:green;}
</style>
</head>
<body>
<form>
your name:<input type="text" name="text"/>
</form
</body>
Prepared by: E.Swathi, Asst.Prof., CSE, CBIT 16
The box model
• All the html elements can have borders .
• We can style these borders with different colors and width.
• Content - The content of the box, where text and images appear
• Padding - Clears an area around the content. The padding is transparent
• Border - A border that goes around the padding and content
• Margin - Clears an area outside thePrepared
border. The margin
by: E.Swathi, Asst.Prof.,is transparent
CSE, CBIT 17
Borders
Border-style Dotted/dashed/double/null
(Border-top-style,
Border-bottom-style
Border-left-style
Border-right-style)
Border-width Thin/medium(default)/ thick/value in px
(Border-left-width
Border-right-width
Border-top-width
Border-bottom-width)
Border-color Color name
(border-top-color,
border-bottom-color,
border-left-color,
border-right-color)
</body>
Prepared by: E.Swathi, Asst.Prof., CSE, CBIT 20
<div> tag
- <div> tag is used to group the html elements together.
- used to make sections in html document
- Like container which encapsulate other html elements.
Example:
<div style="background-color:red;
border:10px solid green;
padding:20px;
font-size:20px">
<p>Welcome to div tag</p>
<p>CBIT,CSE-2</p>
</div>
Example:
<html>
<head>
<title>HTML span Tag</title>
</head>
<body>
<p>This is text with different color
<span style = "color:#FF0000;"> This
is a paragraph</span>
This is a paragraph</p>
<p>
<span style = "color:#8866ff;">This is
another paragraph</span></p>
</body>
</html>
Prepared by: E.Swathi, Asst.Prof., CSE, CBIT 22
Font Properties
• The font-family property is used to specify a list of font names. The browser uses the
first font in the list that it supports. For example, the property:
font-family: Arial, Helvetica, Futura
• The font-size property does what its name implies. For example, the following property
specification sets the font size for text to 10 points:
font-size: 10pt
• The default value of the font-variant property is normal, which specifies the usual
character font. This property can be set to small-caps to specify small capital characters.
Font-variant:small-caps
• The font-style property is most commonly used to specify italic, as in
font-style: italic
• The font-weight property is used to specify the degree of boldness, as in
font-weight: bold
Besides bold, the values normal (the default), bolder, and lighter can be specified.
• The list-style-type property can be used to specify the types of sequence values.
• Only 17 colors are guaranteed to be correctly displayed by all browsers on all color
monitors. This collection is called as named colors.
• The text-align property, for which the possible keyword values are left, center, right,
and justify, is used to arrange text horizontally.
Eg: p{text-align : right}