html - 有人能告诉我为什么我的 div 样式不起作用吗

标签 html css

我的 ID #kiwi 似乎无效。谁能解释一下为什么它不起作用?我一直在寻找一些帮助,但找不到。当我也尝试对其进行分类时,它甚至不起作用。

<head>
    <title>this is the title sucker</title>

    <style>
        #kiwi {background-color:green;}
    </style>
</head>

<body>      
    <table border="1">

        <tr>
            <th colspan="3">Statistics</th>
        </tr>

        <tr>
            <th colspan="1">Car model name</th>
            <th colspan="0">Vegetables</th>
            <th>Delicious Fruits</th>
        </tr>


        <div id="kiwi">
        <tr>
            <td>Jaguar</td>
            <td>Tomato</td>
            <td>Kiwi</td>
        </div>
        </tr>
        <tr>
            <td>BMW</td>
            <td>Potato</td>
            <td>Apples</td>
        </tr>
        <tr>
            <td>AUDI</td>
            <td>Cabbage</td>
            <td>Watermelon</td>
        </tr>

    </table>
</body>

最佳答案

您应该将 id 分配给 <tr>标记而不是将其放在 div 中

这个有效:

<head>
    <title>this is the title sucker</title>
    <style>
        #kiwi {background-color:green;}
    </style>
</head>

<body>      
    <table border="1">

        <tr>
            <th colspan="3">Statistics</th>
        </tr>

        <tr>
            <th colspan="1">Car model name</th>
            <th colspan="0">Vegetables</th>
            <th>Delicious Fruits</th>
        </tr>

        <tr id="kiwi">
            <td>Jaguar</td>
            <td>Tomato</td>
            <td>Kiwi</td>

        </tr>

        <tr>
            <td>BMW</td>
            <td>Potato</td>
            <td>Apples</td>
        </tr>
        <tr>
            <td>AUDI</td>
            <td>Cabbage</td>
            <td>Watermelon</td>
        </tr>

    </table>
</body>

关于html - 有人能告诉我为什么我的 div 样式不起作用吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49350096/

相关文章:

JavaScript 代码在 WPF WebBrowser 加载的 HTML 页面中不起作用

javascript - React 入门,无法渲染页面传递 props

html - 使用 MQ 对 HTML/CSS 进行移动/平板电脑优化

html - 变换 scaleX 并保持固定的正确位置

javascript - onclick:改变位置后做一些事情

html - 水平弹出菜单 - 隐藏选项

html - 我可以在 html 选择下拉列表中的内容和箭头之间放置一个空格吗?

html - 使用 float left 和左边距用 Items 填充 div

css - 如何在图像背景上应用图案和颜色?

html - 如何覆盖 IOS Safari 中的输入[类型 ="select"] 文本颜色