views:

60

answers:

4

Hi All,

Why does this work:

 <div style="background-color: #ccc;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    border: 1px solid #000;
    padding: 10px;">testing 10,9,8,7
</div>

And this does not?

<div style="roundedCornerBox">
    testing 10,9,8,7
</div>

Where I have created a css file that says:

body {
  background-color: #FFFFFF;
  text-align: center;
}

roundedCornerBox {
   background-color: #ccc;
   -moz-border-radius: 5px;
   -webkit-border-radius: 5px;
   border: 1px solid #000;
   padding: 10px;
}

Here is my HTML code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html>
<head><title></title>
     <link rel="stylesheet" href="lib/css/style.css" />      
</head>

<body>
<div style="roundedCornerBox">
    testing 10,9,8,7
</div>

<div style="background-color: #ccc;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    border: 1px solid #000;
    padding: 10px;">
        testing 10,9,8,7
 </div>
 </body>
 </html>
+2  A: 

Classes start with a dot!

.roundedCornerBox {
   background-color: #ccc;
   -moz-border-radius: 5px;
   -webkit-border-radius: 5px;
   border: 1px solid #000;
   padding: 10px;
}

<div class="roundedCornerBox">

Without the dot, it's looking for a <roundedCornerBox /> element to style. The style= needs to be class= as well.

Nick Craver
Still won't work. Check his code carefully. He's putting the class name in the style attribute.
D_N
@DN - I have that correction as well...
Nick Craver
@Tchalvak - Fair point, updated to be more explicit.
Nick Craver
A: 

You want class="roundedCornerBox" in the markup and .roundedCornerBox in your CSS.

D_N
+7  A: 

Are you sure you dont mean:

<div class="roundedCornerBox">
    testing 10,9,8,7
</div>

and

.roundedCornerBox {
   background-color: #ccc;
   -moz-border-radius: 5px;
   -webkit-border-radius: 5px;
   border: 1px solid #000;
   padding: 10px;
}

You need the dot to identify a css class and to use that css class you need to place the class name in the class attribute on the dom element.

Mark
http://www.w3.org/TR/REC-html40/present/styles.html#adef-style Definition of the style attribute.Less technical and for once more useful w3schools breakdown of the difference: http://www.w3schools.com/CSS/css_howto.asp
Tchalvak
A: 

The div tag is incorrect in your second example. It could be

<div id="roundedCornerBox">
    testing 10,9,8,7
</div>

and

#roundedCornerBox {
   background-color: #ccc;
   -moz-border-radius: 5px;
   -webkit-border-radius: 5px;
   border: 1px solid #000;
   padding: 10px;
}
Steve
He just forgot the `.` ;)
henasraf
That is if `roundedCornerBox` is a `class`. Another syntactically correct option is to make it an `id`. (*Semantically*, perhaps it is better as a `class`. Either way.)
Steve