用的微信名称 2021-12-06 10:36 采纳率: 25%
浏览 38
已结题

前端内联块元素布局问题


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="./css/index.css">
    <title>Document</title>
    <style>
      
    </style>
</head>
<body>
    <!-- 顶部导航栏 -->
   <div class="top white" >

    </div> 
    <!-- 左边栏 -->
    <div class="left"><span>1</span></div><!-- 内容栏 --><div class="content" style="background-color: aquamarine;"></div> 
</body>
</html>

index.css内容如下:

*{
    margin: 0px;
    padding: 0px;
    outline: none;
}

html{
    height: 100%;
    width: 100%;
}
ul{
    list-style:none
}

 body{
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-size: 1rem;
} 

.top{
    height: 5%;
    background-color: #96b97d;
}

.top li{
    display: inline-block;
    margin: 10px 0 10px 40px;
    font-size: 1.2rem;
}

.left{
    width: 10%;
    height: 100%;
    background-color:red;
    display: inline-block;
}

.left li{
    margin: 10% 0% 0% 10%;
}

.white{
    color: #fff;
}

.content{
    width: 80%;
    height: 100%;
    display:inline-block;
}

渲染效果如下:

img

左侧栏没有显示出来,但是我把内容栏里的div加上“122312”左侧栏就能显示,修改如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="./css/index.css">
    <title>Document</title>
    <style>
      
    </style>
</head>
<body>
    <!-- 顶部导航栏 -->
   <div class="top white" >

    </div> 
    <!-- 左边栏 -->
    <div class="left"><span>1</span></div><!-- 内容栏 --><div class="content" style="background-color: aquamarine;">122312</div> 
</body>
</html>

渲染效果图:

img

麻烦谁能解释下为啥会这样,感激不尽!

  • 写回答

2条回答 默认 最新

  • 你好!机器人 2021-12-06 10:46
    关注

    同一行的行内元素对齐方式默认是底部对齐,即vertical-align:baseline,你可以在.left跟.content 加一个vertical-align:top解决这个问题

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 12月14日
  • 已采纳回答 12月6日
  • 创建了问题 12月6日

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作