如何让样式表只作用于一个表格下面是我用的一个样式表,把它置于页首则页中所有表格都受到影响
问:我如何让它只影响页面中某一个表格而不影响其它的表?
    <style type="text/css">
        .style2
        {
            width: 613px;
        }
        .style3
        {
            width: 313px;
        }
        table
        {
            /*table-layout: fixed;*/
            border-collapse: collapse;
        }
        table, td
        {
            border: 1px solid #A9CBEE;
        }
    </style>
假设只影响下面的这个表(不规则),如何进行修改:
            <table align="center" style="width: 90%;" border="2">
                <tr>
                    <td align="center" rowspan="3" valign="top">
                        <%# Eval("id")%><br>
                        <%# Eval("教师姓名")%>
                    </td>
                    </td>
                    <td class="style2">
                        <%# Eval("部门")%>
                        <%# Eval("标题")%>
                </tr>
                <tr>
                    <td class="style3">
                        <%# Eval("文章")%>
                    </td>
                </tr>
                <tr>
                    <td class="style3">
                        发布时间:<%# Eval("发布时间")%>
                    </td>
                </tr>
            </table>

解决方案 »

  1.   

    <table id="mytable" class="xx">
    <tr class="xxtr"><td class="xxtd"><td></tr>
    </table>
    css:
    #mytable.xx{}
    #mytable .xxtr{}
    #mytable .xxtd{}
    注意空格跟没空格的区别
      

  2.   

    使用 #id { } 这样只作用在id为id的 html 元素上。
      

  3.   

     全局和局部的控制
     #table { xx}
     .table1 { xx}
     .table1 td {xx}
     .table2 { xx}
     .table2 td {xx}
      

  4.   

      #tableid
      {
      /*table-layout: fixed;*/
      border-collapse: collapse;
      }
      #tableid, td
      {
      border: 1px solid #A9CBEE;
      }
      </style>
    假设只影响下面的这个表(不规则),如何进行修改:
      <table align="center" style="width: 90%;" border="2" id="tableid">
      

  5.   

    <style type="text/css">
       #tbl .style2
       {
       width: 613px;
       }
       #tbl .style3
       {
       width: 313px;
       }
       #tbl
       {
       /*table-layout: fixed;*/
       border-collapse: collapse;
       }
       #tbl, td
       {
       border: 1px solid #A9CBEE;
       }
       </style><table id="tbl" align="center" style="width: 90%;" border="2">
       <tr>
       <td align="center" rowspan="3" valign="top">
       <%# Eval("id")%><br>
       <%# Eval("教师姓名")%>
       </td>
       </td>
       <td class="style2">
       <%# Eval("部门")%>
       <%# Eval("标题")%>
       </tr>
       <tr>
       <td class="style3">
       <%# Eval("文章")%>
       </td>
       </tr>
       <tr>
       <td class="style3">
       发布时间:<%# Eval("发布时间")%>
       </td>
       </tr>
       </table>
      

  6.   

    宽度不是已经有了吗  也可以   width: 15%
      

  7.   

    在你需要的表格那里用class指定就好了嘛。
      

  8.   

    本例中
    1:td单元格宽度受父节点容器(table)的限制.td列之间宽度调整百分比或者给定固定宽,当宽度太大自动换行
    2:让table的宽度不限制,这样td内内容过长,就会自动变长