Following is the example of conditional statement in CSS.
<head>
<style type="text/css">
body
{
color:blue;
}
</style>
<!--[if IE 7]>
<style type="text/css">
body {
background-color:red;
}
</style>
<![endif]-->
</head>
If this code will run in IE7 browser, the background color of the page will be red, for other browser it will be default color (white). |
If we want to maintain uniformity in the look and feel of all same type of elements on the page, we can write CSS class with the element name.eg.
If we want to change the look and feel of all table and h1 element on the page, we can write like this.
table
{
font-size:10pt;
font-family: Arial;
}
h1
{
font-size:14pt;
padding-left:5px;
margin:0px;
color:#094BBB;
}
The first class "table" will apply to all the tables on the page and second class "h1" will apply to all the h1 element of the page.
Note that the name of the class is not prefixed with the . (dot) as it happens with normal css class name. |
The possible value of the "Position" attributes are
absolute
fixed
inherit
relative
static
By default, relative value is considered. |
Write following css class.
a
{
text-decoration:none;
}
a:hover
{
text-decoration:underline;
}
The first class will force all anchor tag (link)to not display any docoration (underline) and second class will force all anchor tag (link) to display text decoration as underline when mouse over it (ie. display underline when mouse over). |
Wrap the div element with fload:left style.
<div style="float: left">
<img src="fsdaf.gif" />Your contents goes here.
</div>
To reverse, ie float the image in the right side and let the content fill the space at the left and further down, specify float:right style. |
Use display:block style with span.
<span style="display:block;" /> |
Use following code snippet
<p style="page-break-after: always">Place your text</p>
After above code, the rest content will appear in the next page. (It will not be visible as next page in browser but on the printer and in Print Preview, you will see them as next page) |
|
Style sheets do have its own share of limitations some of them are as follows: -
1) Inconsistent browser support
2) Vertical control limitations
3) Margin collapsing, float containment, control of element shapes, etc
4) Lack of column declaration and variables are some of the limitations present in CSS. |
There are two ways of centering block level elements:
1. By setting the properties margin-left and margin-right to auto and width to some explicit value:
BODY {width: 30em; background: cyan;}
P {width: 22em; margin-left: auto; margin-right: auto}
In this case, the left and right margins will each be four ems wide, since they equally split up the eight ems left over from (30em - 22em). Note that it was not necessary to set an explicit width for the BODY element; it was done here to keep the math clean.
Another example:
TABLE {margin-left: auto; margin-right: auto; width: 400px;}
In most legacy browsers, a table's width is by default determined by its content. In CSS-conformant browsers, the complete width of any element (including tables) defaults to the full width of its parent element's content area. As browser become more conformant, authors will need to be aware of the potential impact on their designs. |
NOTE: This is objective type question, Please click question title for correct answer. |
There are three ways of inserting a style sheet:
1. External style sheet
2. Internal style sheet
3. Inline style
External Style Sheet :
An external style sheet is ideal when the style is applied to many pages.
With an external style sheet, you can change the look of an entire Web site by changing one file.
Each page must link to the style sheet using the <link> tag. The <link> tag goes inside the head section:
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
</head>
Internal Style Sheet :
An internal style sheet should be used when a single document has a unique style. Internal styles sheet needs to put in the head section of an HTML page, by using the <style> tag, like this:
<head>
<style type="text/css">
hr {color:sienna}
p {margin-left:20px}
body {background-image:url("images/back40.gif")}
</style>
</head>
Inline Styles :
If only a small piece of code has to be styled then inline style sheets can be used.
An inline style loses many of the advantages of style sheets by mixing content with presentation.
To use inline styles you use the style attribute in the relevant tag.
The style attribute can contain any CSS property.
The example shows how to change the color and the left margin of a paragraph:
<p style="color:sienna;margin-left:20px">This is a paragraph.</p> |
Possible values are
static, relative, absolute, fixed, inherit |
Default value is "static". |
As said Both the properties are used to hide and show elements but they are different in the way they both work. visibility property, set to hidden will still occupy the space in the layout but display:none does not take up the space in the page. |
Yes, you can. Just provide a space between both the class names.
like..
<div class="class1 class2">
</div> |