Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

The class selector

Featured Replies

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.

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. :)

  • 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.

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 :).

  • 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.

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.

  • 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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.