Enjoy an ad free experience by logging in. Not a member yet?
Register .
02-15-2009, 09:54 PM
PM User |
#1
Regular Coder
Join Date: Oct 2008
Location: Sweden
Posts: 103
Thanks: 7
Thanked 0 Times in 0 Posts
Using commas to select different CSS Styles?
I've been wondering how to do this for a while now... I'm not sure how to explain it.. so i'll try my best to show you.
Instead of using:
.class-1 a {
css here
}
class-2 a {
css here
}
i want to use something like this, but i don't know if i'm doing it right, or how to do it...:
class-1 a, class2 a {
css for both classes here..
}
Is that possible to do, and am i doing it right? Should i just add a comma between each class name, like above?
Thanks
-Nike
__________________
-Nike -
PTS -
Blubbz
I would love to change the world, but they won't give me the source code.
02-15-2009, 10:08 PM
PM User |
#2
The Apostate
Join Date: Oct 2007
Posts: 3,215
Thanks: 16
Thanked 265 Times in 263 Posts
Yes, you're doing it right, but you're forgetting the full stops before your class names ^^
02-15-2009, 10:09 PM
PM User |
#3
Regular Coder
Join Date: Oct 2008
Location: Sweden
Posts: 103
Thanks: 7
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by
CyanLight
Yes, you're doing it right, but you're forgetting the full stops before your class names ^^
More info please.. what do you mean?
__________________
-Nike -
PTS -
Blubbz
I would love to change the world, but they won't give me the source code.
02-15-2009, 10:12 PM
PM User |
#4
Supreme Master coder!
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
I guess it depends on where you are from to understand what a full stop means. It means a dot or a period in the American English language.
Code:
.class-1 a, .class2 a {
css for both classes here..
}
__________________
|||| If you are getting paid to do a job, don't ask for help on it! ||||
02-15-2009, 10:13 PM
PM User |
#5
Regular Coder
Join Date: Oct 2008
Location: Sweden
Posts: 103
Thanks: 7
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by
_Aerospace_Eng_
I guess it depends on where you are from to understand what a full stop means. It means a dot or a period in the American English language.
Code:
.class-1 a, .class2 a {
css for both classes here..
}
Oh yea, i'm sorry... I totally forgot the dots xD, thanks. I understand now
__________________
-Nike -
PTS -
Blubbz
I would love to change the world, but they won't give me the source code.
02-15-2009, 10:20 PM
PM User |
#6
New Coder
Join Date: Jan 2009
Location: Cornwall - UK
Posts: 47
Thanks: 0
Thanked 9 Times in 9 Posts
If you are trying to allow people to change the style, colours etc of a website you are going the wrong way about it.
Code:
.class1, .class2
{
color:#000;
background:#fff;
}
Will asign black text on a white background to both classes. It's the same as:
Code:
.class1
{
color:#000;
background:#fff;
}
.class2
{
color:#000;
background:#fff;
}
All the best - redspyder
Last edited by redspyder; 02-17-2009 at 12:41 AM ..
02-15-2009, 10:25 PM
PM User |
#7
Regular Coder
Join Date: Oct 2008
Location: Sweden
Posts: 103
Thanks: 7
Thanked 0 Times in 0 Posts
Thanks redspyder.
I've seen people do this too:
.class1 .class2 {
css here
}
without the comma between, what is that for then? Is it even correct?
-Nike
__________________
-Nike -
PTS -
Blubbz
I would love to change the world, but they won't give me the source code.
02-15-2009, 10:32 PM
PM User |
#8
Regular Coder
Join Date: Nov 2004
Location: The land of chocolate
Posts: 226
Thanks: 1
Thanked 16 Times in 16 Posts
It means an element with class2 is nested within an element with class1. An example would be:
Code:
<div class="class1">
<div class="class2">
The css is applied to this content.
</div>
</div>
__________________
-Snow
Susie, if you want to see your doll again, leave $100 in this envelope by the tree out front. Do NOT call the police. You CANNOT trace us. You CANNOT find us.
Sincerely,
- Calvin.
02-15-2009, 10:34 PM
PM User |
#9
Regular Coder
Join Date: Oct 2008
Location: Sweden
Posts: 103
Thanks: 7
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by
snowieken
It means an element with class2 is nested within an element with class1. An example would be:
Code:
<div class="class1">
<div class="class2">
The css is applied to this content.
</div>
</div>
Why can't i just use
class-2 {
css here..
}
instead of
class-1 .class-2 {
css here...
}
?? I don't see the point with it?
__________________
-Nike -
PTS -
Blubbz
I would love to change the world, but they won't give me the source code.
02-16-2009, 12:30 AM
PM User |
#10
The Apostate
Join Date: Oct 2007
Posts: 3,215
Thanks: 16
Thanked 265 Times in 263 Posts
It makes the selector more specific, which gives it more weight in deciding the final outcome.
Also, you may have classes outside a container element, like so:
Code:
<ul>
<li class="alt">miaow</li>
<li>rawr</li>
<li class="non-feline">
<ul>
<li class="alt">squeak</li>
<li class="alt">moo</li>
<li>eep!</li>
</ul>
<li class="alt">meow</li>
</ul>
You may want to select only the
.alts within
.non-feline.
02-16-2009, 08:23 AM
PM User |
#11
Regular Coder
Join Date: Oct 2008
Location: Sweden
Posts: 103
Thanks: 7
Thanked 0 Times in 0 Posts
Aaaah, ook, i think i get it.
If i use this CSS
.outer-div {
font-size: 16px;
font-weight: bold;
}
.inner-div {
font-size: 16px;
}
For this code...
<div class="outer-div">
<div class="inner-div"></div>
</div>
Then the outer Div will be bold and with a 16px font.. and the inner div will have a 16px font and then it will use the bold tag from the outer div..? So the inner-div will also be bold?
__________________
-Nike -
PTS -
Blubbz
I would love to change the world, but they won't give me the source code.
Last edited by najkiie; 02-16-2009 at 08:45 AM ..
02-16-2009, 08:42 AM
PM User |
#12
Supreme Master coder!
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
Quote:
So the inner-div will also be bold?
Yes it'll be inherited to the .inner-div
(assuming you meant
Code:
.inner-div {
font-size: 16px;
}
above)
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
02-16-2009, 08:45 AM
PM User |
#13
Regular Coder
Join Date: Oct 2008
Location: Sweden
Posts: 103
Thanks: 7
Thanked 0 Times in 0 Posts
abduraooft, yes.. sorry i wrote wrong :P
Exellent, now i understand this too
Thanks!
__________________
-Nike -
PTS -
Blubbz
I would love to change the world, but they won't give me the source code.
02-16-2009, 08:52 AM
PM User |
#14
Supreme Master coder!
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
Quote:
Exellent, now i understand this too
CSS specificity is also worth a look.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 01:21 AM .
Advertisement
Log in to turn off these ads.