CSS Interview Questions and Answers
Question - 81 : - How far can CSS be taken beyond the web page--that is, have generalized or non-web specific features for such things as page formatting or type setting?
Answer - 81 : - Yes, it's possible to take CSS further in several directions. W3C just published a new Working Draft which describes features for printing, e.g., footnotes, cross-references, and even generated indexes.
Another great opportunity for CSS is Web Applications. Just like documents, applications need to be styled and CSS is an intrinsic component of AJAX. The "AJAX" name sounds great.
Question - 82 : - How To Style Table Cells?
Answer - 82 : - Margin, Border and Padding are difficult to apply to inline elements. Officially, the
tag is a block level element because it can contain other block level elements (see Basics - Elements).
If you need to set special margins, borders, or padding inside a table cell, then use this markup:
|
yourtext |
to apply the CSS rules to the div inside the cell.
Question - 83 : - How To Style Forms?
Answer - 83 : - Forms and form elements like SELECT, INPUT etc. can be styled with CSS - partially.
Checkboxes and Radiobuttons do not yet accept styles, and Netscape 4.xx has certain issues, but here is a tutorial that explains the application of CSS Styles on Form Elements.
Question - 84 : - How do I get my footer to sit at the bottom...?
Answer - 84 : - Need a div which makes space at the bottom of the main page (inside the #wrap div). Then, the footer (being inside #wrap) can be placed in that space by using absolute positioning. Like this :
CSS body, html {
height:100%;
}
body {
margin:0;
padding:0;
}
#wrap {
position:relative;
width:780px;
margin:auto; min-height:100%;
}
* html #wrap {
height:100%;
}
#clearfooter {
height:50px;
overflow:hidden;
}
#footer {
position:absolute;
bottom:0;
width:100%;
height:50px;
}
HTML
...content goes here...
Question - 85 : - Can I attach more than one declaration to a selector?
Answer - 85 : - Yes. If more than one declaration is attached to a selector they must appear in a semi colon separated list, e.g.;
Selector {declaration1; declaration2}
P {background: white; color: black}
Border around a table?
Try the following:
.tblboda {
border-width: 1px;
border-style: solid;
border-color: #CCCCCC;
}
/*color, thickness and style can be altered*/
You put this style declaration either in
an external stylesheet, or you can stuff it in
the
section, like:
and apply it to the table as follows:
Content text and more content |
That should give you a grey thin border around this table.
If you want the border to 'shrink wrap' around the table, then you have to use the
tag instead the
tag. But that is not quite proper CSS or HTML, because a is for inline elements. A table is not an inline element, therefore the correct tag is a . If you play around with it a bit then you have a good chance to achieve what you want and still have correct HTML/CSS.
The other way would be that you apply the class .tblboda directly to the table (for IE and other contemporary browsers), like
and you define another class for each stylesheet: .tblboda2
In the NN4.xx stylesheet, you use the same properties as above, and in the IE and other contemporary browsers you carefully set all those properties to default, like {border-style: none;}
Then you wrap the table in the with the class .tblboda2 (NN4.xx does that) (IE a.o.c.b. don't do anything, because the border-style is set to "none" = no border at all).
This way you have a table that is wrapped in a nice little border: .tblboda2 for NN4.xx, .tblboda for IE and other modern browsers.
Question - 86 : - How do you target a certain browser?
Answer - 86 : - IE can be targetted by preceding your properties with '* html'. For example...
#nav {
position:fixed;
}
* html #nav { /* this will target IE */
position:absolute;
}
Another way to target IE is with conditional comments. Put this (below) in the head - just before the closing tag - and put anything you want to be directed only at IE in another stylesheet.
If you need to target IE5x...
#wrap {
width:760px; /* for IE5x */
w\idth:780px; /* for all other major browsers */
}
Question - 87 : - How does inheritance work?
Answer - 87 : - HTML documents are structured hierarchically. There is an ancestor, the top level element, the HTML element, from which all other elements (children) are descended. As in any other family also children of the HTML family can inherit their parents, e.g. color or size.
By letting the children inherit their parents a default style can be created for top level elements and their children. (Note: not all properties can be inherited). The inheritance starts at the oldest ancestor and is passed on to its children and then their children and the children's children and so on.
Inherited style can be overridden by declaring specific style to child element. For example if the EM element is not to inherit its parent P then own style must be declared to it. For example:
BODY {font-size: 10pt}
All text will be displayed in a 10 point font
BODY {font-size: 10pt}
H1 {font-size: 14pt} or H1 {font-size: 180%}
All text except for the level 1 headings will be displayed in a 10 point font. H1 will be displayed in a 14 point font (or in a font that is 80% larger than the one set to BODY). If the element H1 contains other elements, e.g. EM then the EM element will also be displayed in a 14 point font (or 180%) it will inherit the property of the parent H1. If the EM element is to be displayed in some other font then own font properties must be declared to it, e.g.:
BODY {font-size: 10pt}
H1 {font-size: 14pt} or H1 {font-size: 180%}
EM {font-size: 15pt} or EM {font-size: 110%}
The EM element will be displayed in a 15 point font or will be 10% larger than H1. NOTE: EM is, in this example, inside H1 therefore will inherit H1's properties and not Body's.
The above declaration will display all EM elements in 15 point font or font that is 10% larger than font declared to the parent element. If this specific font is to apply to EM elements but only if they are inside H1 and not every occurrence of EM then EM must take a form of a contextual selector.
H1 EM {font-size: 15pt} or H1 EM {font-size: 110%}
In the example above EM is a contextual selector. It will be displayed in specified font only if it will
Question - 88 : - What is the percentage value in 'font-size' relative to?
Answer - 88 : - It is relative to the parent element's font-size. For example, if the style sheet says:
H1 {font-size: 20pt;}
SUP {font-size: 80%;}
...then a inside an will have a font-size of 80% times 20pt, or 16pt.
Question - 89 : - What is wrong with font-family: "Verdana, Arial, Helvetica"?
Answer - 89 : - The quotes. This is actually a list with a single item containing the well-known 'Verdana, Arial, Helvetica' font family. It is probably intended to be a list of three items.
Unlike in most other CSS1 properties, values for the font-family are separated by a comma to indicate that they are alternatives. Font names containing whitespace should be quoted. If quoting is omitted, any whitespace characters before and after the font name are ignored and any sequence of whitespace characters inside the font name is converted to a single space.
So to ask for two fonts foo and bar the syntax is:
font-family: foo, bar
To ask for the two fonts Revival 555 and Iodine you can do this:
font-family: "Revival 555", Iodine
You could also do this:
font-family: Revival 555, Iodine
which is equivalent. Notice that this is not three fonts; you can tell because after the "l" you didn't hit a comma, (more list items to come) a semicolon (end of that property, another property coming up) or a curly brace (end of that rule). This is also equivalent:
font-family: Revival 555, Iodine
^^^^^^ whole bunch of spaces converts to one space
But this next one is asking for a different font with two spaces in the name
font-family: "Revival 555", Iodine
^^two spaces, which are not converted
In general it is more tolerant of user typing to leave out the quotes. Sometimes you need them, for example there is a real font sold by Fontworks and designed in 1995 by Stephan Müller called Friday, Saturday, Sunday. Yes, two commas in the actual font name. CSS1 can handle this:
font-family: "Friday, Saturday, Sunday", cursive
Because it can handle this, the example in the title is syntactically correct. But what the author or tool wrote was almost certainly not what the document author intended.
Question - 90 : - How do I centre my page?
Answer - 90 : - This is very easy. If we take the code in the last question and change it to this :
CSS
body, html {
height:100%;
}
body {
margin:0;
padding:0;
}
#wrap {
position:relative;
width:780px;
margin:auto; min-height:100%;
}
* html #wrap {
height:100%;
}
you get a page that fits an 800x600 resolution screen without a horizontal scrollbar, which will be centered at higher resolutions.
Share your email for latest updates
Copyright 2017, All Rights Reserved. A Product Design BY CoreNet Web Technology