amakeler Posted February 1, 2007 Share Posted February 1, 2007 Hi all, Subject: Observation on the Class selector - from CSS Newbie studentNow I am learning CSS from W3S, I just thought that I would point out that the syntax of the Class selector is the reverse of what is intuitive to an old-time programmer, imo.In C++ and other languages, you first define the class with the "Class" directive/key-word/reserved-word (or which ever word you use to indicate a "class"), and then you use it without stating the word "Class", so you get a short-hand notation in usage.However, in CSS I note that when you define the class you do not specify the word 'class", but when you use the class you do specify the word 'class", which causes a very long-winded usage notation, and which has to be repeated every time. Below is an example from the tutorial:<head>p.sansserif {font-family: sans-serif}</head><body><p class="sansserif">This is a paragraph</p></body>I would have designed it like this: <head>p Class sans {font-family: sans-serif}</head><body><p.sans>This is a paragraph</p></body>- avi Link to comment Share on other sites More sharing options...
smiles Posted February 1, 2007 Share Posted February 1, 2007 that is also the biggest drawback of programming language but we have to accept but if having only one language, does it sense pleased ???just imaging that you have to pass by several doors with different height, you must stoop, straight or even crawl ... I am talking about protocol Link to comment Share on other sites More sharing options...
S@m Posted February 1, 2007 Share Posted February 1, 2007 Just think:. is class# is idYou can have multiple classes with the same name on your page, but only 1 unique id name per page.Good luck! Link to comment Share on other sites More sharing options...
amakeler Posted February 6, 2007 Author Share Posted February 6, 2007 that is also the biggest drawback of programming language but we have to accept but if having only one language, does it sense pleased ???just imaging that you have to pass by several doors with different height, you must stoop, straight or even crawl ... I am talking about protocol I am starting to get more serious about CSS, so I read a CSS specification: http://www.w3.org/TR/CSS21/selector.html#q2 Belive it or not, but see 5.8.3 Class selectors, where it seems to say that you CAN specify class usage by using a dot notation, as I suggested with:<body><p.sans>This is a paragraph</p></body>But I did not see that you can define a class using teh word "class".- avi Link to comment Share on other sites More sharing options...
jesh Posted February 6, 2007 Share Posted February 6, 2007 I am starting to get more serious about CSS, so I read a CSS specification: http://www.w3.org/TR/CSS21/selector.html#q2 Belive it or not, but see 5.8.3 Class selectors, where it seems to say that you CAN specify class usage by using a dot notation, as I suggested with:<body><p.sans>This is a paragraph</p></body>But I did not see that you can define a class using teh word "class".- aviI believe I read that specification differently than you because I don't think it's possible to do what you are saying:<html><head><style>p.test { background-color: red; }</style></head><body><p.test>This paragraph will <b>not</b> have a red background.</p><p class="test">This paragraph will have a red background.</p></body></html> Link to comment Share on other sites More sharing options...
amakeler Posted February 6, 2007 Author Share Posted February 6, 2007 that is also the biggest drawback of programming language but we have to accept but if having only one language, does it sense pleased ???just imaging that you have to pass by several doors with different height, you must stoop, straight or even crawl ... I am talking about protocol I am starting to get more serious about CSS, so I read a CSS specification: http://www.w3.org/TR/CSS21/selector.html#q2 Belive it or not, but see 5.8.3 Class selectors, where it seems to say that you CAN specify class usage by using a dot notation, as I suggested with:<body><p.sans>This is a paragraph</p></body>(But I did not see that you can also define a class using the word "class"...)- avi Link to comment Share on other sites More sharing options...
jlhaslip Posted February 6, 2007 Share Posted February 6, 2007 (edited) Use the period (dot) in the css file, and the "class =" in the (x)html.*edit to fix typo* Edited February 6, 2007 by jlhaslip Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now