Jump to content

Syntax Question


turtle

Recommended Posts

Hi,I'm new to CSS and wherever I looked I couldn't get an answer to my question. So here I am at the forums. Basically I'm wondering if the following is correct.

#text{font-size:130%}#header{font-family:arial, verdana, "lucida console";font-weight:bold;font-size: 480%;text-align:center}.hello{font-size: 900%}

As you can see I have no html tag on the id's or the class yet still they work. I checked a few validation websites and they said all was fine.In my html document I was using the id multiple times to define different sections with headers and text.So basically I'm asking can I use the following in the CSS code#*what ever i like* {CSS styles....}And in the html document put<div id="*what ever i like*>The bit of text </div>And can I do the same with classes doing this in the CSS.*what ever i like* {CSS styles.....}And in the html document put<div class="*what ever i like*>The bit of text</div>Is this ok to do ???Thanks for any help :)

Link to comment
Share on other sites

Make sure to put a closing " for the <div class"*whatever*>. Looks like you can use _, a-z, A-Z for the first character of the id/class and 0-9, A-Z, a-z, _ for any character after. CSS has a lot of ways to select certain elements.# is for id's. is for classesIf you don't specify what element to select such as h1.example { ... }, it will select all of the elements with that same class name, and that is what you did.

Link to comment
Share on other sites

It is invalid to have two elements with the same id. Also, if you have spaces in your class attribute you assign multiple classes to that element, e.g.

<img class="class1 class2 class3" />

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...