div风格不适用于CSS

时间:2017-06-19 13:05:04

标签: html css

我想展示div.HTML + CSS,但它没有显示div边框。

<body>
    <!-- format 1 -->
    <div  id="test">abc</div>
</body>

// css file
#test {
    width: 30%;
    height: 300px;
    left:30%;
    border: solid;
}

只是HTML,它有效。融合。两种格式相同吗?

<!-- format2 -->
<body>
  <div  id="test" style="width: 30%; height: 300px; left:30%; border: solid">abc</div>
</body>


它们都可以工作。在之前的版本中,我设置了div id =&#34; 18&#34;,并且在css中使用#18。这是错的。
我认为应该关闭这个问题。

2 个答案:

答案 0 :(得分:0)

在这里显示边框。您很可能没有将样式表正确链接到HTML文档。

另一种解释是,样式表中还有另一条规则用border: none覆盖该元素的边框设置。

&#13;
&#13;
#test {
    width: 30%;
    height: 300px;
    left:30%;
    border: solid;
}
&#13;
<div  id="test">abc</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

Logically, it should work exactly the same both ways. Here is a little JSFiddle to show that: https://jsfiddle.net/av25ro8w/

<body> <!--ignore this; StackOverflow makes code compulsory when you send a JSFiddle link-->
    <div id="test">abc</div>
</body>

There must be some other error in your code as it seems the code you have provided us is an example and not the exact code you're working with :)