css样式不能生效

1.在写一个div的时候,最外部的div的样式可以起作用,可是向下嵌套一层div的时候,css不会对这个div起作用,
说明这个样式是被引入了.
2.以下是代码

html:`<div id="nav_s">
            <span class="loggg">asdasdasdsad</span>

    </div>`

css:`#nav_s {
position: fixed;
top: 0;
width: 100%;
z-index: 100;
width: 100%;
height: 100px;
background-color: black;
color: white;

};
.loggg {

color: red;
width: 500px;
height: 500px;
background-color: red;

}`

阅读 4k
2 个回答

你说的没有起作用;是说span吧,换成display:block;
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        #nav_s {
            position: fixed;
            top: 0;
            width: 100%;
            z-index: 100;
            width: 100%;
            height: 100px;
            background-color: black;
            color: white;
        } //这里不能有分号
        
        .loggg {
            color: red;
            width: 500px;
            height: 500px;
            background-color: red;
            display: block;
        }
    </style>
</head>

<body>
    <div id="nav_s">
        <span class="loggg">asdasdasdsad</span>

    </div>
</body>

</html>

span这种行内元素直接设置宽高是无效的,注意不是所有的行内元素都这样。

可以像楼上那样转为block。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题