作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
注意:在我发布我的问题之前,我搜索了这个网站来获得答案,但我找不到任何允许我在百分比值中设置等边距的解决方案。
以下代码未缩放到完整的 25%:
请参阅下面的示例 HTML 代码:
<style>
#Wrapper {
margin:0 auto;
width:70%;
}
#MainLogo{
width:100%;
height:100px;
border:1px solid #000;
}
#LeftSide{
width:25%;
height: 600px;
background-color:#90F;
margin-top:5px;
float:left;
}
#FloatLeft {
float:left;
}
#One{
width:25%;
height:300px;
background-color:#000;
margin-top:5px;
float:left;
}
#Two{
width:25%;
height:300px;
background-color:#F00;
margin-top:5px;
float:left;
}
#Three{
width:25%;
height:295px;
background-color:#F00;
margin-top:5px;
float:left;
clear:both;
}
#Four{
width:25%;
height:295px;
background-color:#000;
margin-top:5px;
float:left;
}
#RightSide{
width:25%;
height: 600px;
background-color:#00F;
margin-top:5px;
float:right;
margin-bottom:5px;
}
#MainFooter{
width:100%;
height:100px;
border:1px solid #000;
clear:both;
}
</style>
<body>
<div id="Wrapper">
<header id="MainLogo">
Logo Goes here!!
</header>
<aside id="LeftSide">
Left side goes here
</aside>
<div id="FloatLeft">
<aside id="One">
One Goes Here!!
</aside>
<aside id="Two">
Two aside goes here!!
</aside>
<aside id="Three">
Three aside goes here!!
</aside>
<aside id="Four">
Four aside goes here!!
</aside>
</div>
<aside id="RightSide">
Right side goes here
</aside>
<footer id="MainFooter">
Main Footer Goes here!!
</footer>
</div>
最佳答案
它不工作的原因是因为诸如 padding
之类的事情和 margin
.您将需要使用 box-sizing
属性来获得你想要的效果。
首先,您应该删除所有内容的填充和边距,然后设置 box-sizing
属性(property)border-box
.这将确保无论多少padding
或 margin
你有,它将永远停留在height
, 和 width
您指定。
这是一个示例用法
* {
padding:0;
margin:0;
box-sizing-border-box;
}
box-sizing
属性尚未得到完全支持,因此您将需要使用供应商特定的属性
关于html - 如何在 html 中设置与百分比 % 相等的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17410504/
我是一名优秀的程序员,十分优秀!