Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between width/margin and _width/_margin?

Tags:

css

.pageWidth
{
margin: 0 30px;
min-width: 940px;
_width: 976px;
_margin: 0 auto;

}

I saw this from a website css file. My question is: what is the difference between width/margin and _width/_margin? why use _width/_margin here?

like image 212
user2243528 Avatar asked Apr 27 '13 12:04

user2243528


People also ask

What is the difference between padding and margin in react native?

The main difference between margin and padding is that margin helps to create space around the element outside the border, while padding helps to create space around the element inside the border.

Does Max Width include margin?

This property sets the maximum content width of a block or a replaced element. This maximum width does not include padding, borders, or margins.

Does margin affect width CSS?

The width and height properties include the content, padding, and border, but do not include the margin. Note that padding and border will be inside of the box.


Video Answer


3 Answers

It is a hack for IE6. The CSS rules _margin and _width will only apply for that browser. There are more curious hacks for the IE browser like:

width: 940px\9; /* IE8 and below */  
*width : 960px; /* IE7 and below */  

If you make a fast search in google for "IE CSS hacks" you can find more information and tricks for CSS rules in the evil IE like: Quick Tip: How to Target IE6, IE7, and IE8 Uniquely with 4 Characters

like image 149
Pigueiras Avatar answered Oct 12 '22 16:10

Pigueiras


the _ and - before the properties is for compliance to Internet Explorer 6 and below. Here is the article for your reference:

http://www.javascriptkit.com/dhtmltutors/csshacks3.shtml

*Prefixing a regular property name with _ or - will cause the property to be applied to Internet Explorer 6 and below but generally not in other browsers.*

like image 24
AJ Naidas Avatar answered Oct 12 '22 16:10

AJ Naidas


It's an old CSS hack used to target Internet Explorer. IE tries to be smart and does some additional parsing over the CSS properties one of which is stripping the underscores.

So in you case IE will override the width to 976px and for the rest of the browsers the width will stay 940px. This was used in the past to fix a problem with the IE broken box model, which didn't follow the W3C conventions.

like image 1
Daniel Alexandrov Avatar answered Oct 12 '22 17:10

Daniel Alexandrov