Jump to content

Very Basic Problems HTML


nshady

Recommended Posts

Hi , I read a book and they mention bout <element id=name and <element class=nameid=name identifies a particular element while class=name identifies a particular classhuh ? what a particular class ? Element got class and individual ones ? Please guide me thanks.

Link to comment
Share on other sites

It's just that a class attribute is used to identify a particular group of elements. By using other languages (CSS most of the time), you can manipulate elements of the same class all at once.IDs are used when you need to manipulate only one certain element. IDs could also be used in the URL to link to the specific part of the page where that ID occurs.

Link to comment
Share on other sites

This is an example of a class, the class is called .red and you can see that when i add this class to the <p> and <div> tags there contents are colored red.

<html><head><style type="text/css">.red {color:red}</style></head><body><p class="red">This is a paragraph</p><div class="red">This is a paragraph</div></body></html>

This is an example of id, notice how the <p> tag has id="red and the <div> tag has id="green". Then if you look in the <style> tag i can add styles to these tags by specifying a # in front of there id = #red + #green.

<html><head><style type="text/css">#red {color:red}#green {color:green}</style></head><body><p id="red">This is a paragraph</p><div id="green">This is a paragraph</div></body></html>

Does this make sense? :)

Link to comment
Share on other sites

This is an example of a class, the class is called .red and you can see that when i add this class to the <p> and <div> tags there contents are colored red.
<html><head><style type="text/css">.red {color:red}</style></head><body><p class="red">This is a paragraph</p><div class="red">This is a paragraph</div></body></html>

This is an example of id, notice how the <p> tag has id="red and the <div> tag has id="green".  Then if you look in the <style> tag i can add styles to these tags by specifying a # in front of there id = #red + #green.

<html><head><style type="text/css">#red {color:red}#green {color:green}</style></head><body><p id="red">This is a paragraph</p><div id="green">This is a paragraph</div></body></html>

Does this make sense? :)

I think im beginning to understand , actually Id and Class have the same effect its just that ID can be used with 1 element rite ? Best to use one time.So better to use class rite ? What if i use class in every part , without using ID at all , issit okay ?
Link to comment
Share on other sites

so i can omit id ? i use class in every single document But ID can be used a lot of times rite ? It's just that it cannot use da same NameLike <p id=orange>so the next 1 like <div id=(cannot orange anymore)as for class u can use same for both with different elements rite ?

Link to comment
Share on other sites

What if i use class in every part , without using ID at all , issit okay ?
Yes that's fine, that's what makes css so powerful, you can give tags the same class and if you later decide you want to style that class differently all you have to do is make one change and all elements will change.
Link to comment
Share on other sites

oops edited , reenter my questionsBut ID can be used a lot of times rite ? It's just that it cannot use da same NameLike <p id=orange>so the next 1 like <div id=(cannot orange anymore)as for class u can use same for both with different elements rite ?

Link to comment
Share on other sites

But ID can be used a lot of times rite ? It's just that it cannot use da same NameLike <p id=orange>so the next 1 like <div id=(cannot orange anymore)as for class u can use same for both with different elements rite ?

Yes. That's exactly what we meant. Just remember to put quotes though:<p id="orange">And before you ask (others asking this have): you think up of the class and/or IDs name. There are no predefined values. Orange could as well be "navigation", "link", "right", etc. or anything you come up with.
Link to comment
Share on other sites

But ID can be used a lot of times rite ? It's just that it cannot use da same NameLike <p id=orange>so the next 1 like <div id=(cannot orange anymore)as for class u can use same for both with different elements rite ?
Yes your getting it, so if you wanted to use the same styles for more than one id you would seperate them with a comma.This means if you wanted the color to be orange you make one change and both id's change, saving you time.
<html><head><style type="text/css">#redPara, #redDiv{color:red}</style></head><body><p id="redPara">This is a paragraph</p><div id="redDiv">This is a paragraph</div></body></html>

Css is quite flexible, you can achieve the same things differently :)

Link to comment
Share on other sites

ID can be used in Javascript to refer to a specific element. That's another reason why you only want 1 element with any given ID (although CSS will still style 10 elements with the same ID).You can also give one element multiple classes.

.red {color: red;}.uline {text-decoration: underline;}.floating {position: absolute; top: 150px; left: 100px;}<div class="red uline floating">...</div>

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...