CSS,为什么一件事有效而另一件事无效?

ML.*_*ML. 1 css

为什么这样做:

 <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>
Run Code Online (Sandbox Code Playgroud)

这不是吗?

<div style="roundedCornerBox">
    testing 10,9,8,7
</div>
Run Code Online (Sandbox Code Playgroud)

我在哪里创建了一个css文件说:

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;
}
Run Code Online (Sandbox Code Playgroud)

这是我的HTML代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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>
Run Code Online (Sandbox Code Playgroud)

Mar*_*man 8

你确定你不是说:

<div class="roundedCornerBox">
    testing 10,9,8,7
</div>
Run Code Online (Sandbox Code Playgroud)

.roundedCornerBox {
   background-color: #ccc;
   -moz-border-radius: 5px;
   -webkit-border-radius: 5px;
   border: 1px solid #000;
   padding: 10px;
}
Run Code Online (Sandbox Code Playgroud)

您需要点来标识一个css类,并使用该css类,您需要将类名放在dom元素的class属性中.