Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is a CSS property starting with a hash (#) valid?

Tags:

css

What does the following CSS do and is it valid?

h4 {
    width: 83%;
    #width: 75%;
}
like image 849
rick schott Avatar asked Aug 23 '11 13:08

rick schott


People also ask

What is hash used for in CSS?

The CSS id Selector The id of an element is unique within a page, so the id selector is used to select one unique element! To select an element with a specific id, write a hash (#) character, followed by the id of the element.

What is difference between and in CSS?

The dot( . ) signifies a class name while the hash ( # ) signifies an element with a specific id attribute. The class will apply to any element decorated with that particular class, while the # style will only apply to the element with that particular id.

What do periods do in CSS?

Class Selectors To match a specific class attribute, we always start the selector with a period, to signify that we are looking for a class value. The period is followed by the class attribute value we want to match.

What is the mean of dot in HTML?

Kolade Chris. In your HTML documents, you'll often need to make a list of items. And you can use bullet points for this purpose. You can show bullet points with the Unicode character (or entity) for bullet points.


3 Answers

It is not valid. #width: 75%; is a syntax error, since # isn't used in CSS property names (although it is used in CSS selectors, to select elements with specific ids). Most browsers will ignore it (hopefully) and only the first rule will be applied.

It might have been someone's attempt to write a CSS comment. This is the valid way: /*This is a comment*/

Edit

I would suggest using a CSS reset file to account for browser differences.

like image 92
Chris Laplante Avatar answered Oct 24 '22 01:10

Chris Laplante


Apparently there's a hash hack which looks exactly like the one you have, but I have no idea what specific browsers the author is trying to target or filter since there aren't any reliable results as to what browsers apply the rule and what don't (that looooooong list of user agent strings isn't what I'd call reliable; I'd call it inconsistent).

In any case, a hash is not a valid character for property names. I'm sure anyone that isn't IE will squarely discard it on sight.

like image 43
BoltClock Avatar answered Oct 23 '22 23:10

BoltClock


using # before a property is applying different css style for ie 7. Is a css hack like *. To make it valid you can use conditional comments for ie.

like image 39
Sotiris Avatar answered Oct 24 '22 01:10

Sotiris