This is extremely simple but I am wondering why people write this?
div#some_id
You can only have one ID of that name "some_id" on a webpage. So why be specific with it? Is it for readability purposes?
This is extremely simple but I am wondering why people write this?
div#some_id
You can only have one ID of that name "some_id" on a webpage. So why be specific with it? Is it for readability purposes?
There are a couple of possible reasons:
You're right, but this would mean a div with an ID of some_id
. (More correctly, an element with an ID of some_id
, which is also a div
).
This grants a higher specificity value, but you're right. It's usually worthless with IDs, more useful with class names.
For example:
div.large { width: 500px; /* 500px is a large div */ }
input.large { width: 100px; /* 100px is a large input */ }
Same class name, different results.
The reason this is done is mainly for readability in the stylesheet.
As you can only have 1 id on a page it makes sense that you would not need to specify which type of element it is.