gpt4 book ai didi

css - HTML5/CSS - 将内容添加到 SECTION 时,位置会移动。为什么?

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

我无法理解为什么我的布局中的部分在添加内容时会移动位置。我的意图是让每行三个部分彼此水平对齐。非常感谢任何帮助,谢谢。

JSFiddle - http://jsfiddle.net/z6mx3/1/

CSS

body {
margin:0px;
padding:0px;
}

#container {
background-color:Silver;
width:1024px;
margin:auto;
padding-left:10px;
padding-right:10px;
padding-bottom:20px;
min-height:100%;
position:absolute;
left:0;
right:0;
}

#content {
font-family:Arial, Helvetica, sans-serif;
color:#664E44;
background-color:red;
overflow:auto;
}


section {
color:#24292E;
width:300px;
height:500px;
display:inline-block;
margin: 0 15px;
background-color:#A8B1B1;
padding:4px;
}

html

<!DOCTYPE html>
<html lang="en">
<head>
<title>Test</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="container">
<div id="content">
<section>
<h2>Header</h2>
<p></p>
</section>

<section>

</section>

<section>
</section>

<section>
</section>

<section>
</section>

<section>
</section>
</div>
</div>
</body>
</html>

最佳答案

inline-block 元素的默认对齐方式是baseline

您只需要在 CSS 中添加正确的对齐选项

section {
color:#24292E;
width:300px;
height:500px;
display:inline-block;
margin: 0 15px;
background-color:#A8B1B1;
padding:4px;
vertical-align:top /* here*/
}

JSFiddle Demo

关于css - HTML5/CSS - 将内容添加到 SECTION 时,位置会移动。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22480706/

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