html - 无法用 div 或 id 覆盖 li

标签 html css

我只想覆盖#box 中的列表项而不更改li{} 的CSS 样式.我想我只能通过创建新的 CSS 类并使用 <span> 来改变它。标签。但对我来说,只有当我在 <li> 中应用这个新类时才有可能标签,所以它只适用于一个 <li> .我一直为每个列表项执行此操作,这不是执行此操作的正确方法。

我想在#box id 中格式化 li 标签,而其他 li 标签保持原样。

<html>
<head>
<style>
ol {
    font-family: arial;
    //background: #000; /*font-size:12px; */
                font-size: 11px;
    color: #066;
 }

a:link, a:visited,a:active {color: #660066;}

table {
    border: none;
    color: #000;
 }

{}

.stylish {
    font-size: 18px;
    font-weight: bold;
 }
.sidecorner {font-size: 14px;}

.olcolor {
    color: #039FF0;
}

.myclass, ol.myclass{
    color:#3F6 !Important;

    }

li {
    font-weight: normal;
    font-size: 11pt;
    font-family: arial;
    color: #666;
 }

#box {
    background-color: #ffcc66;
    margin:20px;
    height: auto;
    width: auto;
    padding:10px;
    border:1px dotted;
}

.sidebar {
    position: absolute;
    top: 19px;
    bottom: 0px;
    left: 813px;
    width: 276px;
    min-height: 250px;
    //background: lightgrey;
    padding-bottom: 0px;
    margin-bottom: 0px;
    height: 417px;
}


#li {
    color: #666;
}
</style>


</head>


<body>
<div class="container">
  <div class="body">
    <div class="sidebar">
      <table width="276" border="0" cellpadding="1" cellspacing="1"  >
        <tr>
          <td height="59" valign="middle" style="background:#660066; color: #FFF; font-size: 16px; font-weight: bold; font-family: arial; text-align: center;">sdfsdfsdf</td>
        </tr>
        <tr>
          <td valign="middle" style="background:#F2F2F2; color: #666; "><ol style="padding-top:25px;padding-right:5px;padding-bottom:20px">
            <li> Tasdfsdf</li>
            <li>asdf</li>
            <li>sadf</li>
            <li>asdf</li>
            <li>as</li>
            <li>dfsd</li>
            <li>sdf</li>
          </ol>
            <p>&nbsp;</p></td>
        </tr>
      </table>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
    </div>
<h2>&nbsp;</h2>
    <div id="box">
  <h3>Sample Title</h3><hr style="color:#960">
  <h2>Heading...</h2>

  <ol class="myclass">
       <li>This is the sample text<br>

      </li>

     </span>
  </ol>
    </div>
  </div>
</div>
</body>


</html>

最佳答案

如果我没理解错的话,您可以将样式应用于给定 ID 下面的嵌套元素,如下所示:

#box li {
color: blue;
}

这将使其他 li 标签不受影响,但如果我理解错误 - 请在评论中纠正我。

关于html - 无法用 div 或 id 覆盖 li,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25955962/

相关文章:

html - 输入字段内的可点击图像 - 位置不起作用

javascript - PHP a href echo with span 无法正常运行

html - 响应式菜单在移动设备中始终可见

html - 我怎样才能 float div 以便它们扩展到容器之外?

iphone - 是否可以在没有触摸的情况下与 UIWebView 交互?

html - 当我转到询问页面时,页脚不会粘在底部

javascript - 使用自定义 UI 创建 html 框

css - 修改表格 td 宽度

javascript - Display CSS 属性设置为 none 后视频自动播放

css - SIM 卡的纯 css 图标