• +91 9723535972
  • info@interviewmaterial.com

CSS Interview Questions and Answers

Related Subjects

CSS Interview Questions and Answers

Question - 31 : - What is parent-child selector?

Answer - 31 : - Parent-child selector is a selector representing the direct descendent of a parent element. Parent-child selectors are created by listing two or more tilde (~) separated selectors. BODY ~ P {background: red; color: white} The P element will be declared the specified style only if it directly descends from the BODY element:

Red and white paragraph

BODY ~ P ~ EM {background: red; color: white} The EM element will be declared the specified style only if it directly descends from the P element which in its turn directly descends from the BODY element: <

Red and white EM

Question - 32 : - How can I  specify background images?

Answer - 32 : - With CSS, you can suggest a background image (and a background color, for those not using your image) with the background property. Here is an example: body { background: white url(example.gif) ; color: black ; } If you specify a background image, you should also specify text, link, and background colors since the reader's default colors may not provide adequate contrast against your background image. The background color may be used by those not using your background image. Authors should not rely on the specified background image since browsers allow their users to disable image loading or to override document-specified backgrounds.

Question - 33 : - How do I have a fixed (non-scrolling) background image?

Answer - 33 : - With CSS, you can use the background-attachment property. The background attachment can be included in the shorthand background property, as in this example: body { background: white url(example.gif) fixed ; color: black ; } Note that this CSS is supported by Internet Explorer, Mozilla, Firefox Opera, Safari, and other browsers. In contrast, Microsoft's proprietary BGPROPERTIES attribute is supported only by Internet Explorer.

Question - 34 : - What are inline, block, parent, children, replaced and floating elements?

Answer - 34 : - Inline elements which do not have line breaks. Can occur in block elements or other inline elements, cannot contain block elements. Inline elements in HTML 3.2; EM, STRONG, DFN, CODE, SAMP, KBD, VAR, CITE, TT, I, B, U, STRIKE, BIG, SMALL, SUB, SUP, A, IMG, APPLET, FONT, BASEFONT, BR, SCRIPT, MAP, INPUT, SELECT, TEXTAREA. Inline elements in HTML 4.0; EM, STRONG, DFN, CODE, SAMP, KBD, VAR, CITE, ABBR, ACRONYM, TT, I, B, BIG, SMALL, SUB, SUP, A, IMG, OBJECT, BR, SCRIPT, MAP, Q, SPAN, BDO, INPUT, SELECT, TEXTAREA, LABEL, BUTTON, (INS, DEL). Inline elements in HTML 4.0 Transitional; EM, STRONG, DFN, CODE, SAMP, KBD, VAR, CITE, ABBR, ACRONYM, TT, I, B, U, S, STRIKE, BIG, SMALL, SUB, SUP, A, IMG, APPLET, OBJECT, FONT, BASEFONT, BR, SCRIPT, MAP, Q, SPAN, BDO, IFRAME, INPUT, SELECT, TEXTAREA, LABEL, BUTTON, (INS, DEL). Block elements which do have line breaks. May occur in other block elements, cannot occur in inline elements, may contain both block and inline elements. Block elements in HTML 3.2; H1, H2, H3, H4, H5, H6, ADDRESS, P, DL, DT, DD, UL, OL, DIR, MENU, LI, DIV, CENTER, BLOCKQUOTE, PRE, HR, ISINDEX, TABLE, FORM. Block elements in HTML 4.0; P, H1, H2, H3, H4, H5, H6, UL, OL, PRE, DL, DIV, NOSCRIPT, BLOCKQUOTE, FORM, HR, TABLE, FIELDSET, ADDRESS, (INS, DEL). Block elements in HTML 4.0 Transitional; P, H1, H2, H3, H4, H5, H6, UL, OL, DIR, MENU, PRE, DL, DIV, CENTER, NOSCRIPT, NOFRAMES, BLOCKQUOTE, FORM, ISINDEX, HR, TABLE, FIELDSET, ADDRESS, (INS, DEL). Parents and children elements which either contain (parents) or are in the content of (children) other elements, e.g.

texttexttext

. P is a parent of STRONG. STRONG is a child of P. If not specified otherwise, children will inherit parent's properties. Replaced elements which content is replaced. For example content of the IMG element is replaced with an image, content of the INPUT element is replace with a field. Floating elements which follow the flow of a parent - inline elements.

Question - 35 : - Which set of definitions, HTML attributes or CSS properties, take precedence?

Answer - 35 : - CSS properties take precedence over HTML attributes. If both are specified, HTML attributes will be displayed in browsers without CSS support but won't have any effect in browsers with CSS support.

Question - 36 : - How do  I eliminate the blue border around linked images?

Answer - 36 : - in your CSS, you can specify the border property for linked images: a img { border: none ; } However, note that removing the border that indicates an image is a link makes it harder for users to distinguish quickly and easily which images on a web page are clickable.

Question - 37 : - Why call the subtended angle a "pixel", instead of something else (e.g. "subangle")?

Answer - 37 : - In most cases, a CSS pixel will be equal to a device pixel. But, as you point out, the definition of a CSS pixel will sometimes be different. For example, on a laser printer, one CSS pixel can be equal to 3x3 device pixels to avoid printing illegibly small text and images. I don't recall anyone ever proposing another name for it. Subangle? Personally, I think most people would prefer the pragmatic "px" to the non-intuitive "sa".

Question - 38 : - Why was the decision made to make padding apply outside of the width of a 'box', rather than inside, which would seem to make more sense?

Answer - 38 : - It makes sense in some situations, but not in others. For example, when a child element is set to width: 100%, I don't think it should cover the padding of its parent. The box-sizing property in CSS3 addresses this issue. Ideally, the issue should have been addressed earlier, though.

Question - 39 : - How to use CSS to separate content and design ?

Answer - 39 : - The idea here is that all sites contain two major parts, the content: all your articles, text and photos and the design: rounded corners, colors and effects. Usually those two are made in different parts of a webpage’s lifetime. The design is determined at the beginning and then you start filling it with content and keep the design fixed. In CSS you just add the nifty -tag I’ve told you about to the head of your HTML document and you have created a link to your design. In the HTML document you put content only, and that link of yours makes sure it looks right. You can also use the exact same link on many of your pages, giving them all of them the same design. You want to add content? Just write a plain HTML document and think about marking things up like “header” instead of “big blue header” and use CSS to make all headers look the way you want! Some examples of good and bad coding. What’s wrong with this? Welcome to my page Comment: The font-tag is design and design shouldn’t be in the HTML document. All design should be in the CSS-file! Instead do this: In the HTML:

Welcome to my page

In the CSS: h1 { font-size: 2em; } One more example: An error occurred This looks right doesn’t it? But if you look up what stands for you quickly find bold. But bold is certainly design, so it still doesn’t belong in the HTML document. A better choice is that stands for emphasis or simply “this piece of text is important”. So instead of saying “this text looks like this” you are saying “this text is important” and you let the looks be decided by the CSS. Seems like a minor change, but it illustrates how to select your tags. Use this instead: In the HTML: An error occured In the CSS: em { font-weight: bold; color: Red; } One last example: Question - 40 : - Can CSS be used with other than HTML documents?

Answer - 40 : - 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.


NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Latest News

10000+ interview questions in different categories

Freshers and experienced

Our partners