CSS Interview Questions Continue

Hope you enjoyed the read so far. We’ve more recommendations for you.

READ : jQuery Interview Questions and Answers 

READ : HTML5 interview Questions and Answers on DGlobaltech

READ : Front-end coding Question : Create function to reverse words in a sentence

9. What are some ways you might target IE (or IE6) only, without affecting other browsers?

Below are the example for browser specific Style Sheet, which targets defined browser.

Target ALL VERSIONS of IE

<!--[if IE]>
	<link rel="stylesheet" type="text/css" href="all-ie-only.css" />
<![endif]-->

Target everything EXCEPT IE

<!--[if !IE]><!-->
	<link rel="stylesheet" type="text/css" href="not-ie.css" />
 <!--<![endif]-->

Target IE 6 ONLY

<!--[if IE 6]>
	<link rel="stylesheet" type="text/css" href="ie6.css" />
<![endif]-->

READ : Difference between CSS and CSS3 : CSS2 vs. CSS3

READ : CSS Interview Questions and Answers for Experienced

READ : AJAX Interview Questions and Answers : 15 Commonly asked questions

READ : SQL Interview Questions and Answers : Commonly asked Questions

10. What’s the difference between an inline element and a block element?

A block-level element is an element that creates large blocks of content like  paragraphs or page divisions. They start new lines of text when you use them, and can contain other blocks as well as inline elements and text or data.

An inline element is an element that define text or data in the document like STRONG makes the enclosed text strongly emphasized and Q says the enclosed text is a quotation. They don’t start new lines when you use them, and they generally only contain other inline tags and text or data. Or they include nothing at all, like the BR tag.

Some properties that inline elements ignore include:

  • width and height
  • max-width and max-height
  • min-width and min-height

The CSS property display lets you change an inline property to block or a block to inline or either of them to not display at all.

display: block;
display:inline;
display:none;

    When to Change the Display Property

  • Horizontal list menus – Lists are block-level elements, but if you want your menu to display horizontally, you need to convert the list to an inline element, so that newlines aren’t added between each list item.
  • Headers in the text – Sometimes you might want a header to remain in the text, but have the HTML header values. Changing the h1-h6 values to inline will let the following text flow next to it.
  • Removing the element – And of course, if you want to remove the element completely from the document flow, you can set the display to none.

11. Explain how the CSS box model works. Draw a box and then explain what the border is, what the margin is, what the padding is, etc.? If you assign a width: or height: to something, what specifically does that refer to?

All HTML elements can be considered as boxes. In CSS, the term “box model” is used when talking about design and layout.

The CSS box model is essentially a box that wraps around HTML elements, and it consists of: margins, borders, padding, and the actual content.

The box model allows us to place a border around elements and space elements in relation to other elements.

boxdim

Explanation of the different parts:

  • Margin – Clears an area around the border. The margin does not have a background color, it is completely transparent
  • Border – A border that goes around the padding and content. The border is affected by the background color of the box
  • Padding – Clears an area around the content. The padding is affected by the background color of the box
  • Content – The content of the box, where text and images appear

Here is the snippet to draw box model to your web page.

<head>
<style>
div.test
{
width:220px;
padding:10px;
border:5px solid gray;
margin:0px;
}
</style>
</head>

<body>

<div class=”test”>The picture above is 250px wide. The total width of this element is   also 250px.</div>

</body>

12. Explain vertical margin collapsing.

Top and bottom margins of blocks are sometimes combined (collapsed) into a single margin whose size is the largest of the margins combined into it, a behavior known as margin collapsing.

Margin collapsing occurs in three basic cases:

Adjacent siblings
The margins of adjacent siblings are collapsed (except when the later sibling needs to be cleared past floats). 
Parent and first/last child
If there is no border, padding, inline content, or clearance to separate the margin-top of a block with the margin-top of its first child block, or no border, padding, inline content, height, min-height, or max-height to separate the margin-bottom of a block with the margin-bottom of its last child, then those margins collapse. The collapsed margin ends up outside the parent.
Empty blocks
If there is no border, padding, inline content, height, or min-height to separate a block’s margin-top from its margin-bottom, then its top and bottom margins collapse.
vertical margins collapse between certain boxes.
To understand how vertical margins collapse lets start with a basic html and CSS example.

Adjacent Elements With Positive Margin

Vertical adjoining margins collapses. If two elements has positive vertically adjoining margin than only the maximum of both will take effect.

CSS Code

1
2
3
#parent{ background-color:yellow; width:300px; }
#red {background-color:red; height:50px; margin-bottom:30px;}
#blue {background-color:blue; height:50px; margin-top:20px;}

Browser Result

Margins of floating and absolutely positioned elements never collapse.

There are other situations where elements do not have their margins collapsed:

  • inline-block elements
  • elements with overflow set to anything other than visible (They do not collapse margins with their children.)
  • cleared elements (They do not collapse their top margins with their parent block’s bottom margin.)
  • the root element

13. How do you float an element, and what does that mean? What’s Clearing?

With CSS float, an element can be pushed to the left or right, allowing other elements to wrap around it.

Float is very often used for images, but it is also useful when working with layouts.

Elements are floated horizontally, this means that an element can only be floated left or right, not up or down.

A floated element will move as far to the left or right as it can. Usually this means all the way to the left or right of the containing element.

Below is the example, which shows using css float property you can set image to the right of your web page.

<head>
<style>
img
{
float:right;
}
</style>
</head>

<body>

<p>

<img src=”logocss.gif” width=”95″ height=”84″ />

This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
</p>
</body>

14. What’s the difference between position: relative, position: fixed & position: absolute?

Here, I’ve listed basic difference between css positioning properties.

Position-Relative. This type of positioning is probably the most confusing and misused. What it really means is “relative to itself”. If you set position: relative;on an element but no other positioning attributes (top, left, bottom or right), it will no effect on it’s positioning at all, it will be exactly as it would be if you left it as position: static; But if you DO give it some other positioning attribute, say, top: 10px;, it will shift it’s position 10 pixels DOWN from where it would NORMALLY be.

Position-Absolute. This is a very powerful type of positioning that allows you to literally place any page element exactly where you want it. You use the positioning attributes top, left bottom and right to set the location. Remember that these values will be relative to the next parent element. If there is no such parent, it will default all the way back up to the <html> element itself meaning it will be placed relatively to the page itself.

Position-Fixed. This type of positioning is fairly rare but certainly has its uses. A fixed position element is positioned relative to the viewport, or the browser window itself. The viewport doesn’t change when the window is scrolled, so a fixed positioned element will stay right where it is when the page is scrolled.

15. What does z-index do? 

The z-index property specifies the stack order of an element.

An element with greater stack order is always in front of an element with a lower stack order.

Here is the Example, where using z-index property you can display in front of image.

<head>
<style>
img
{
position:absolute;
left:0px;
top:0px;
z-index:-1;
}
</style>
</head>

<body>
<h1>This is a heading</h1>
<img src=”w3css.gif” width=”100″ height=”140″ />
<p>Because the image has a z-index of -1, it will be placed behind the text.</p>
</body>

READ : How to prepare for a job interview : Successful face to face interview tricks and tips

READ : JavaScript Interview Questions and Answers on DGlobaltech


184 Comments

  1. I simply want to mention I am new to blogs and absolutely liked your page. Most likely I’m going to bookmark your website . You actually have superb articles. Bless you for revealing your webpage.

  2. I’m amazed, I have to admit. Rarely do I come across a blog that’s equally educative and interesting, and let me tell you, you have hit the nail on the head. The issue is something which not enough people are speaking intelligently about. I am very happy I found this in my search for something relating to this.

  3. I’m impressed, I have to admit. Seldom do I encounter a blog that’s both educative and engaging, and let me tell you, you’ve hit the nail on the head. The problem is an issue that not enough people are speaking intelligently about. Now i’m very happy that I stumbled across this during my hunt for something regarding this.

  4. Oh my goodness! Amazing article dude! Thanks, However I am going through difficulties with your RSS. I don’t understand the reason why I cannot subscribe to it. Is there anybody else getting identical RSS problems? Anyone who knows the solution can you kindly respond? Thanx!

  5. I’m impressed, I must say. Seldom do I encounter a blog that’s equally educative and interesting, and let me tell you, you have hit the nail on the head. The problem is an issue that not enough men and women are speaking intelligently about. I am very happy that I came across this in my search for something regarding this.

  6. You actually make it appear really easy along with your presentation but I find this topic to be actually one thing which I think I’d by no means understand. It sort of feels too complicated and very large for me. I am having a look forward on your next submit, I’ll attempt to get the hold of it!

  7. When I initially left a comment I appear to have clicked the -Notify me when new comments are added- checkbox and from now on every time a comment is added I receive four emails with the exact same comment. Is there an easy method you are able to remove me from that service? Thank you.

  8. Wonderful work! This is the type of info that are meant to be shared across the web. Shame on the seek engines for no longer positioning this submit upper! Come on over and seek advice from my web site . Thanks =)

  9. Thanks for giving your ideas. Something is that college students have an option between federal student loan along with a private education loan where it’s easier to opt for student loan consolidation than over the federal education loan.

  10. Pretty nice post. I just stumbled upon your weblog and wanted to say that I’ve really enjoyed surfing around your blog posts. After all I’ll be subscribing to your rss feed and I hope you write again very soon!

  11. I together with my buddies came studying the great secrets found on your web site and then immediately I had a terrible suspicion I had not thanked you for those strategies. The young boys came absolutely very interested to learn all of them and have in effect seriously been using those things. Thank you for indeed being very considerate and also for deciding on such outstanding subject areas millions of individuals are really desperate to be aware of. Our sincere regret for not expressing appreciation to earlier.
    (sildenafil citrate

  12. I just couldn’t depart your website prior to suggesting that I actually enjoyed the standard information a person provide for your visitors? Is gonna be back often in order to check up on new posts

  13. Oh my goodness! Amazing article dude! Thank you, However I am encountering troubles with your RSS. I don’t understand the reason why I am unable to subscribe to it. Is there anybody else having the same RSS problems? Anyone that knows the solution can you kindly respond? Thanks.

  14. Having read this I thought it was very enlightening. I appreciate you spending some time and effort to put this information together. I once again find myself personally spending a lot of time both reading and leaving comments. But so what, it was still worth it!

  15. (BuzzFeed News) – You may check the calories in a cheap viagra, steps captivated today and even your main part agglomeration measure but too sundry of us don’t cognizant of the condition estimation that could save our lives – blood pressure. Dubbed the silent lallapalooza, sybaritic blood vexation (BP) infrequently has symptoms in the future it causes 80% of strokes and 32% of mettle attacks, according to Blood Pressure UK. It’s little as numerous as 4 million people are undiagnosed and command only unearth old hat theirs is too foremost when they suffer with a pluck strike at or stroke.
    November 31, 2019 10:12

  16. (NBC) – Turbulent blood strength, also known as hypertension, is the most vulgar cardiovascular disease. Huge blood difficulties does not as a rule engender symptoms at start with, but if outrageous blood load is even across circumstance, it can damage your arteries and extension hazard quest of vital medical conditions such as basic nature attacks and non prescription viagra alternative, strokes, and kidney disease. White-coat hypertension refers to patients who have weighty blood straits when reasoned in the doctor’s house but normal blood difficulties when studied limit of medical settings.
    Updated: January 15, 2019 13:14

  17. (NBC) – Nonpharmacologic interventions to compress BP comprehend: preponderancy waste recompense overweight or abdominous patients with a resolution healthy slim, sodium provision, and potassium supplementation within the abstain; and increased incarnate activity with a structured exercise program. Men should be restrictive to no more than 2 and women no more than 1 conventional fire-water and need viagra without a doctor prescription tope(s) per day. The same impact of each lifestyle transformation is a 4-5 mm Hg fall off in SBP and 2-4 mm Hg decrease in DBP; but diet base-born in sodium, saturated roly-poly, and perfect well-fed and distend in fruits, vegetables, and grains may run out of steam SBP past close to 11 mm Hg.
    Updated: December 19, 2019 13:45

  18. Age-related infertility – Infertility problems commonly enter someone’s head in people who have passed a unfluctuating age. Most often, women who are 35 or heavens and men after 40, take longer to conceive. Often, women assume that if they calm are having their usual cycles, their fertility is superior, but, how to buy viagra online is to some extent true. Discretion is a large particular that impacts egg prominence and quantity. Despite that, if your fellow-dancer is older to you, require five years, this supplemental becomes a difficulty, thus, also increasing the gamble of fertility problems after 35. June 30, 2019 12:13

  19. It’s really very complex in this active life to listen news
    on Television, so I simply use internet for that reason, and obtain the hottest
    information.

  20. So, when you pay off good cheap medical insurance may sooner be utilitarian exchange for treatment of ill-timed ejaculation. As a question of fact, if this really works, viagra ibuprofen determination be underdeveloped ejaculators who succeed in wrong — they inert advocate their erection, but take home to have more orgasms!

  21. Fantastic beat ! I would like to apprentice at the same time as you amend your web site, how could i subscribe for a
    weblog site? The account helped me a applicable deal.
    I had been a little bit acquainted of this your broadcast offered vivid transparent idea

  22. Definitely imagine that that you stated. Your favorite reason appeared to
    be at the net the simplest thing to understand of.
    I say to you, I definitely get irked whilst other folks consider concerns that they just
    do not understand about. You controlled to hit the nail upon the top and
    also outlined out the entire thing without having side-effects
    , people could take a signal. Will probably be again to get more.
    Thank you

  23. Hi! Do you know if they make any plugins to assist with SEO?
    I’m trying to get my blog to rank for some targeted keywords but I’m not
    seeing very good gains. If you know of any please share.
    Kudos!

  24. Thousands to tens of millions and billions of chikungunya or dengue tests into one.
    Performing assessments sorting and Analyzing and this route is designated as
    nice assist. Antique iron banks provide a big selection of
    examine and then to help. The Canyon the Dragoon Corridor
    by which rim-to-rim helicopter flights can be found to help.
    The most important firms are international health day
    is a pink line at investigating. Predictably health care costs skyrocketed.
    It’s already identified only to notify the candidates in regards to the
    human body for example. Many candidates give in and allowed return to medical doctors for each time.

    Video surveillance any locking systems that make up the applying from with obligatory requirement for candidates.
    Today due to be self dominated that States might
    move their own belief programs. Government selected to make cash when you
    are under the impression that. In 2013 Zika re-emerged
    in the aforementioned examine which found that the propaganda
    arm they are.

  25. I simply want to mention I am very new to weblog and actually liked your web-site. Very likely I’m planning to bookmark your blog . You surely have exceptional articles and reviews. With thanks for sharing with us your webpage.

Leave a Reply

Your email address will not be published.