【发布时间】:2020-03-18 01:40:34
【问题描述】:
我正在尝试复制使用float 属性来对齐其内容的Float Example 与Grid and Flex Solution。我想在任何地方替换 float 属性,并且除了包含 <aside> 和 <div> 框的 <section> 之外,我已经能够正确对齐所有内容。这是它应该看起来的样子:
* {
box-sizing: border-box;
text-align: center;
}
section {
padding: 20px;
margin-bottom: 20px;
background: #FFA500;
}
#full {
width: 100%;
overflow: auto;
clear: both;
color: #fff;
background: #394549;
}
#division {
padding: 20px;
margin-top: 20px;
background: #214fb3;
}
aside {
float: left;
width: 33%;
height: 200px;
padding: 20px;
margin-left: 30px;
background: #a6b747;
border: 1px solid #eee;
}
<section id="full">
<aside>
<aside> #a6b747
</aside>
<section> #394549
<div id="division">
<div> #6ea3da
</div>
</section>
这就是我目前在<aside> 框上使用的position: absolute;。
* {
text-align: center;
font-size: 24px;
line-height: 32px;
}
#full {
grid-area: full;
background: #394549;
color: #fff;
height: 200px;
padding: 20px;
}
aside {
position: absolute;
height: 160px;
width: 33%;
padding: 20px;
margin-left: 30px;
background: #a6b747;
border: 1px solid #eee;
}
#division {
width: 100%;
padding: 20px;
background: #214fb3;
}
<section id="full">
<aside>
<aside> #a6b747
</aside>
<section> #394549
<div id="division">
<div> #6ea3da
</div>
</section>
我不得不弄乱像素以获得正确的高度,但我不确定如何修复 <div> 和 <aside> 框的宽度。即使在调整窗口大小时,它们也应该与第一个示例保持一致,而且我也不确定如何对齐 <section> 和 <div> 文本。
【问题讨论】:
-
请提供您的 HTML + CSS 代码,谢谢
-
我已将 html 和 css 的 sn-ps 添加到问题中。整个代码都在我一开始提到的代码笔中。不知道为什么我被否决了。
-
不确定,这通常是因为他们没有足够的信息来解决您的问题。注意:我没有对你投反对票。感谢您提供代码。
标签: html css flexbox grid css-float