March 21, 200917 yr Hey all, I'm starting my journey into web design and currently learning CSS. I'm going through the the tutorials on w3schools and I'm a bit confused on the class selectors. I know if, I were to type this: p.right {text-align: right} ... then when I assign this class in xhtml to the paragraphs, they will all show up on the right side of my page. And if I want to apply the same style to all of the elements I would just omit the "p" and assign the class accordingly. Questions are: 1. Which class selector would be better? Just assigning a class to one elements or just to leave it so you can apply the same class across the board if you wanted to? 2. When creating a class selector, can you just make up any name for it or does it have to follow a scheme for it's function? So in the above example, could I just type .blahblahblah {text-align: right} and -as long as I note the class in xhtml- still have it work just the same? Thanks. vQ.
March 21, 200917 yr Hi, Well done for learning to code by hand, good decision. 1. When creating classes, just create an overall class. So to align right create the following. .align_right { text-align: right; } If you want to add specifics to the class based on a certain element, like a paragraph, you would add the follwoing. p.align_right { text-align: right; padding: 15px; } 2. You can call classes anything you wish. The name will not affect how they work, same goes for ID's but it is important to be specific and name things after the function they perform, as this will make your life a lot easier while developing and when it comes to site maintenance. Hope this helps.
March 21, 200917 yr Author Hi, Well done for learning to code by hand, good decision. 1. When creating classes, just create an overall class. So to align right create the following. .align_right { text-align: right; } If you want to add specifics to the class based on a certain element, like a paragraph, you would add the follwoing. p.align_right { text-align: right; padding: 15px; } 2. You can call classes anything you wish. The name will not affect how they work, same goes for ID's but it is important to be specific and name things after the function they perform, as this will make your life a lot easier while developing and when it comes to site maintenance. Hope this helps. Yeah, this helps a lot. Thank you. vQ.
March 23, 200917 yr Also remember you can assign multiple classes to an element. So like <div class="wide right"><p class="right">blah</p></div> and then have two calsses .wide{width:720px;} .right{float:right;} So the div would be 720px wide, and floated to the right hand side. The p would just be floated to the right within the div. Assign multiple classes by using a space between the class names. This can come in very very useful .
March 23, 200917 yr Author Good info. Thanks a bunch. Either of you would know of a better website to learn CSS?. Like w3schools, but they don't really give an explanation on what each property does in detail like they do in their html/xhtml section.
March 23, 200917 yr http://www.tizag.com/cssT/ Has always been my preference, different people prefer different sites, but Tizag is the one i'd recommend. It's helped me, and still does so much. W3schools i find good for reference, but not for much else.
March 23, 200917 yr Author http://www.tizag.com/cssT/ Has always been my preference, different people prefer different sites, but Tizag is the one i'd recommend. It's helped me, and still does so much. W3schools i find good for reference, but not for much else. Exactly what I was looking for. Thank you so much!!
Create an account or sign in to comment