• +91 9971497814
  • info@interviewmaterial.com

CSS Interview Questions Answers

Question 1 : As a reader, how can I make my browser recognize my own style sheet?

Answer 1 : Netscape It is not possible to do this in Netscape yet (as of version 4.0.) Internet Explorer 3.0 (Win95/NT) [It is possible to do this at least in Windows95/NT, but no user interface is provided. Unknown how this might be accomplished on other operating systems.] 1. Open the Registry editor (Start..Run..regedit..ENTER) 2. Under the 'HKEY_LOCAL_MACHINE\Software\Microsoft\InternetExplorer\Styles' key, Edit..New..String Value 3. The new value should be called 'StyleSheet Pathname' 4. For the value, type in the full directory path of your .css style sheet. Internet Explorer 4.0 (Win95/NT) 1. Under the View menu, select 'Internet Options'. 2. Under the 'General' tab, choose the 'Accessibility' button. 3. Choose the 'Format documents using my style sheet' check box and 'Browse...' to the location of your .css style sheet.

Question 2 : Can CSS be used with other than HTML documents?

Answer 2 : Yes. CSS can be used with any ny structured document format. e.g. XML, however, the method of linking CSS with other document types has not been decided yet.

Question 3 : Can I attach more than one declaration to a selector?

Answer 3 : 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 <head></head> section, like: <style type="text/css"> (here you can place your styles) </style> and apply it to the table as follows: <div class="tblboda"> <table yaddayadda> <tr> <td>Content text and more content</td> </tr> </table> </div> 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 <span> 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 <div>. 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 <table ... class="tableboda"> 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 <div> 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 4 : Can I include comments in my Style Sheet?

Answer 4 : Yes. Comments can be written anywhere where whitespace is allowed and are treated as white space themselves. Anything written between /* and */ is treated as a comment (white space). NOTE: Comments cannot be nested.

Question 5 : Can Style Sheets and HTML stylistic elements be used in the same document?

Answer 5 : Yes. Style Sheets will be ignored in browsers without CSS-support and HTML stylistic elements used.

Question 6 : Can you use someone else's Style Sheet without permission?

Answer 6 : This is a somewhat fuzzy issue. As with HTML tags, style sheet information is given using a special language syntax. Use of the language is not copyrighted, and the syntax itself does not convey any content - only rendering information. It is not a great idea to reference an external style sheet on someone else's server. Doing this is like referencing an in-line image from someone else's server in your HTML document. This can end up overloading a server if too many pages all over the net reference the same item. It can't hurt to contact the author of a style sheet, if known, to discuss using the style sheet, but this may not be possible. In any case, a local copy should be created and used instead of referencing a remote copy. I want my page fonts to look the same everywhere as in… a) Why are my font sizes different in different browsers ? b) Why are my font sizes different on different platforms ? These questions represent the tip of the iceberg of a large topic about which whole essays have been written and a wide range of different views are held. The WWW was originally devised to present the same content in different presentation situations and for a wide range of readers: on that basis, "looking the same" is not a design criterion, indeed different presentations would be expected to look different. Some would have it that this original aim is no longer relevant, and that the purpose of web design is now to factor out the differences between display situations and put the author in control of the details of the presentation. Others point out that CSS was designed to give the reader a substantial amount of joint control over this process, and that this is desirable, for example to accommodate users with different visual acuity. Reading of textual matter on a computer screen is quite a delicate business, what with the relatively coarse pixel structure of a computer display; even with a close knowledge of the display details, it isn't possible to achieve the detailed control that would be possible, say, on a printer. Whatever one's aims, the practical truth is that many of the efforts made to guarantee the precise result on the screen have seriously counterproductive side effects in a www situation. The CSS specifications themselves recommend that authors should not use absolute size units in a situation where the properti

Question 7 : Colored Horizontal Rule?

Answer 7 : You can apply styles to Horizontal Rules <HR> in IE without problems, but NN4.xx can only render the silvery HR. But there is a way around it: .rule {border-top-width: 1px; border-top-style: solid; border-color: #FF0000; margin: 0px 2%;} that, applied to a div, should give you a red HR in NN4.xx and IE, with a 2% gap on the left and right side. CSSharky Logo On this page is an Example of a coloured 'Horizontal Rule'. Update: Thanks to Matt Del Vecchio here is an improved format for the Horizontal Rule: hr { height:0px; border:0px; border-top:1px solid #ff1493; } ....this works in both IE and Netscape. It tells the browser to not render the hr rule itself, and then sets a 1px border, which looks just how most folks want to render the hr rule. It uses the <hr> element and that is better than writing your own class as all devices will know what to do with an <hr> tag.

Question 8 : CSS is clearly very useful for separating style from content. But apparently people tend to have problems when using it for layouts. Would you say this is because people have not yet understood how to properly do layout in CSS, or is it CSS that is lacking in this area? What can be done to improve the situation? --- Would the web benefit from HTML and CSS being complemented with some kind of "layout language"?

Answer 8 : Layout and style should be tackled by the same language and the two are intertwined. Trying to split the two is like splitting the HTML specification in two, one specification describing inline elements and the other describing block elements. It's not worth the effort. CSS is capable of describing beautiful and scalable layouts. The CSS Zen Garden has been a eye-opening showcase of what is possible today. If MS IE had supported CSS tables, another set of layouts would have been possible. So, there is still lots of potential in the existing CSS specifications which should be the next milestone. I always wanted to have "included" substyles or "aliases" in my CSS definition, to save redundancy. (For includes) .class1 { color:#ff0000; } .class2 { background-color:#ffffff; } .class3 { include:class1,class2;font-weight:bold; } (For aliases) @alias color1 #ff0000; @alias color2 #ffffff; @alias default_image url('/img/image1.jpg'); .class1 { color:color1; } .class2 { background-image:default_image;background-color:co lor2; } This way we could change colors or images for a whole webpage by editing a reduced number of lines.

Question 9 : Do URL's have quotes or not?

Answer 9 : Double or single quotes in URLs are optional. The tree following examples are equally valid: BODY {background: url(pics/wave.png) blue} BODY {background: url("pics/wave.png") blue} BODY {background: url('pics/wave.png') blue}

Question 10 : Document Style Semantics and Specification Language (DSSSL)?

Answer 10 : Document Style Semantics and Specification Language is an international standard, an expression language, a styling language for associating processing (formatting and transformation) with SGML documents, for example XML.

CSS Contributors


Share your email for latest updates


Our partners