12 replies [Last post]
np2k
np2k's picture
Offline
Regular
italy
Last seen: 13 years 13 weeks ago
italy
Joined: 2008-04-28
Posts: 11
Points: 0

I have a problem. I found a particular usage of the selector class.
For example:

... div. myclass { color: red; } ...

(Note: attention to the white-space between div. and myclass)

my teacher says: with that declaration i select all the children of the tag div (in any level) with the class "myclass" (note: the children of tag must have the class "myclass")

but if i try some examples, it doesn't work.
Id est: considering the rule above and the lines

...

Hello

i don't have the right result.

what's the problem?

ifohdesigns
ifohdesigns's picture
Offline
Enthusiast
Providence, RI
Last seen: 9 years 45 weeks ago
Providence, RI
Timezone: GMT-4
Joined: 2008-02-22
Posts: 269
Points: 0

You should have it be: div

You should have it be:

div .myclass { color: red; }

mattrossidesigns.com

np2k
np2k's picture
Offline
Regular
italy
Last seen: 13 years 13 weeks ago
italy
Joined: 2008-04-28
Posts: 11
Points: 0

what?!?! the rule is: div

:? what?!?!
the rule is:

div .myclass { color: red; }

but what does it means?

ifohdesigns
ifohdesigns's picture
Offline
Enthusiast
Providence, RI
Last seen: 9 years 45 weeks ago
Providence, RI
Timezone: GMT-4
Joined: 2008-02-22
Posts: 269
Points: 0

Yes, that rule means any div

Yes, that rule means any div that has the class .myclass in it, do the following.

mattrossidesigns.com

np2k
np2k's picture
Offline
Regular
italy
Last seen: 13 years 13 weeks ago
italy
Joined: 2008-04-28
Posts: 11
Points: 0

ifohdesigns wrote:Yes, that

ifohdesigns wrote:
Yes, that rule means any div that has the class .myclass in it, do the following.

no, this rule means any div that has the myclass in it, makes the color red:

div.myclass { color: red; }

and not div. myclass { color: red; } (with a white-space between div. and myclass)..

ifohdesigns
ifohdesigns's picture
Offline
Enthusiast
Providence, RI
Last seen: 9 years 45 weeks ago
Providence, RI
Timezone: GMT-4
Joined: 2008-02-22
Posts: 269
Points: 0

Ok this is it, plain and

Ok this is it, plain and simple:

div.myclass { color: red; }

would apply to any div that had the class "myclass"

In your markup, you do not have any so that would not do anything.

div .myclass { color: red; }

Will go through and find any div that also has an element that has "myclass" applied to it. In your case the "h1" and "p" would get the red styling.

there is no such thing as "div. myclass"

That is malformed css.

mattrossidesigns.com

np2k
np2k's picture
Offline
Regular
italy
Last seen: 13 years 13 weeks ago
italy
Joined: 2008-04-28
Posts: 11
Points: 0

ifohdesigns wrote: Will go

ifohdesigns wrote:

Will go through and find any div that also has an element that has "myclass" applied to it. In your case the "h1" and "p" would get the red styling.

sorry, but i don't understand anything...

what is the rule that do this:

"Will go through and find any div that also has an element that has "myclass" applied to it. In your case the "h1" and "p" would get the red styling."

ifohdesigns
ifohdesigns's picture
Offline
Enthusiast
Providence, RI
Last seen: 9 years 45 weeks ago
Providence, RI
Timezone: GMT-4
Joined: 2008-02-22
Posts: 269
Points: 0

div .myclass { color: red; }

div .myclass { color: red; }

mattrossidesigns.com

np2k
np2k's picture
Offline
Regular
italy
Last seen: 13 years 13 weeks ago
italy
Joined: 2008-04-28
Posts: 11
Points: 0

ifohdesigns wrote:div

ifohdesigns wrote:
div .myclass { color: red; }

perfect...my browser doesn't set the color to the red value...
i write:

string

but "string" is black (default).

ifohdesigns
ifohdesigns's picture
Offline
Enthusiast
Providence, RI
Last seen: 9 years 45 weeks ago
Providence, RI
Timezone: GMT-4
Joined: 2008-02-22
Posts: 269
Points: 0

To get the paragraph within

To get the paragraph within this div to be red do the following:

string

and CSS

div.myclass p { color: red; }

That is one way to get that paragraph red, unless you want to use this markup:

string

and CSS

div .myclass { color: red; }

Or, if you dont want to have any extra markup, in your example html:

string

and CSS

div { color: red; }

You should really read up on the basics of css.

mattrossidesigns.com

np2k
np2k's picture
Offline
Regular
italy
Last seen: 13 years 13 weeks ago
italy
Joined: 2008-04-28
Posts: 11
Points: 0

yes i have made a mistake in

yes i have made a mistake in the last code.
the right version is:


strin



but this doesn't work on my browser! THIS IS MY F...PROBLEM Smile

np2k
np2k's picture
Offline
Regular
italy
Last seen: 13 years 13 weeks ago
italy
Joined: 2008-04-28
Posts: 11
Points: 0

sorry sorry sorry i

sorry sorry sorry

i wrote:
div. myclass
and not:
div .myclass

i'm a stupid Wink

thepineapplehead
thepineapplehead's picture
Offline
Guru
Last seen: 18 weeks 6 days ago
Joined: 2004-06-30
Posts: 9674
Points: 810

Ok let's try this

Ok let's try this again.

div.myclass refers specifically and only to a div with a class of "myclass".

div .myclass refers specifically to anything IN a div that has a class of "myclass"

div. myclass refers to nothing because it's invalid.

Verschwindende wrote:
  • CSS doesn't make pies