Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If the html says <div id="two words", how do I write the CSS selector in the style sheet?

Tags:

If it said "oneword", then I could write "#oneword", but what do I write when there is a space in the word?

like image 282
Corey Trager Avatar asked Oct 30 '08 11:10

Corey Trager


People also ask

Can you use div id in CSS?

Yes, yes you can.

How can you set an id selector on a CSS document?

CSS ID selector To use an ID selector in CSS, you simply write a hashtag (#) followed by the ID of the element. Then put the style properties you want to apply to the element in brackets.

How do you add a CSS to a div in HTML?

CSS can be added to HTML documents in 3 ways: Inline - by using the style attribute inside HTML elements. Internal - by using a <style> element in the <head> section. External - by using a <link> element to link to an external CSS file.

Can a CSS class have two words?

Class names can be one or multiple words. If your class name is multiple words, use hyphens where you would put spaces.


1 Answers

If it contains spaces, it is not legal HTML. You shouldn't expect this to work. Here is the relevant section of the HTML 4.01 specification.

[EDIT] As others have noted, you can get around this by assigning one or more class names to the div and using a class name to do the selection.

like image 101
tvanfosson Avatar answered Oct 15 '22 23:10

tvanfosson