gpt4 book ai didi

html - 一行中的两个 div 元素,但一个是透明的

转载 作者:太空宇宙 更新时间:2023-11-04 08:58:09 24 4
gpt4 key购买 nike

我想要宽度为 (100% - 330px) 的灰色 div。如果两个 div 元素都有 bg-color,那么使用 2 个 div 元素会很容易,但我需要一个固定大小的透明元素。我知道我可以用 calc() 解决这个问题,但我宁愿避免它。

#transp {
width:330px;
float:right;
height: 18px;
}

#grayline {
background-color: #444;
height: 18px;
width: 100%;
}

#grayline2 {
background-color: #444;
height: 18px;
width: calc(100% - 330px);
}
<div>
<!--This how it looks-->
<div id="transp"></div>
<div id="grayline"></div>
</div>
<br />
<div>
<!--This how it should look-->
<div id="grayline2"></div>
</div>

最佳答案

.grayline 中删除 width 并添加 330px 的右边距:

#transp {
width: 330px;
float: right;
height: 18px;
}

#grayline {
background-color: #444;
height: 18px;
margin-right: 330px;
}

#grayline2 {
background-color: #444;
height: 18px;
width: calc(100% - 330px);
}
<div>
<!--This how it looks-->
<div id="transp"></div>
<div id="grayline"></div>
</div>
<br />
<div>
<!--This how it should look-->
<div id="grayline2"></div>
</div>

关于html - 一行中的两个 div 元素,但一个是透明的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42969519/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com