作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一类行为预测的 div。代码如下:
.nav
{
background-color: none;
height: 50px;
width: 100px;
text-align: center;
color: white;
font-family: "comic sans", times, serif;
display: inline-block;
margin: auto;
margin-left: 2px;
padding-top: 15px;
}
这是在包装器 id
导航栏中:
#navbar
{
width: 100%;
height: 50px;
background-color: #141414;
}
但是每当我尝试向其中一个 div 添加图片或大字时,其余包含文本的 div 都会移动,以便只有包含文本的部分位于包装内,其余部分则垂下在 wrapper 外面。
例如:
<div id="navbar">
<div class="nav" style="background-image:url('xyz.jpg'); width:
100px; height: 50px;"></div>
<div class="nav"><a href="#" style="text-decoration:
none;">Home</a></div>
<div class="nav"><a href="#" style="text-decoration:
none;">Genres</a></div>
<div class="nav"><a href="#" style="text-decoration:
none;">Favorites</a></div>
</div> <!-- End of navbar -->
我尝试在线搜索,但未能找到解决此问题的方法。过去有人遇到过这个问题吗?
最佳答案
尝试添加:{ display: flex;}
.nav
{
background-color: none;
height: 50px;
width: 100px;
text-align: center;
color: white;
font-family: "comic sans", times, serif;
margin: auto;
margin-left: 2px;
padding-top: 15px;
}
#navbar
{
display:flex;
width: 100%;
height: 50px;
background-color: #141414;
}
<div id="navbar">
<div class="nav" style="background-image:url('paper.gif'); width:
100px; height: 50px;"></div>
<div class="nav"><a href="#" style="text-decoration:
none;">Home</a></div>
<div class="nav"><a href="#" style="text-decoration:
none;">Genres</a></div>
<div class="nav"><a href="#" style="text-decoration:
none;">Favorites</a></div>
</div>
您可以在此处阅读有关 flex
的信息:https://www.w3schools.com/css/css3_flexbox.asp
关于html - 如何在不影响以下 div 位置的情况下添加图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50084257/
我是一名优秀的程序员,十分优秀!