gpt4 book ai didi

html - 页脚 div 文本不会对齐

转载 作者:搜寻专家 更新时间:2023-10-31 22:43:42 25 4
gpt4 key购买 nike

我想做的是在页脚中排列 3 个 div。但我似乎无法让他们正确排队。当我尝试使用 float 时,只有其中两个会排成一行,而第三个会在它们下方。有人知道怎么回事吗?

body{
background-color: rgb(240, 240, 240);
}

#pageFooter{
margin-top: 10px;
background-color: red;
height: 200px;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
box-shadow: 1px 1px 1px 1px #888888;
}

#pageFooter p{
color: white;
padding-left: 1em;
font-family: sans-serif;
vertical-align: middle;
line-height: 40px;
font-weight: bold;
}

#leftFooter{
text-align: left;
float: left;
position: relative;
}

#midFooter{
text-align: center;
float: center;
position: relative;
}

#rightFooter{
text-align: right;
float: right;
position: relative;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Oppgave 1</title>

<link rel="stylesheet" type="text/css" href="css/meyersReset.css">
<link rel="stylesheet" type="text/css" href="css/mainStyle.css">

</head>

<body>

<div id="container">
<footer id="pageFooter">
<div id="leftFooter">
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
</div>

<div id="midFooter">
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
</div>

<div id="rightFooter">
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
</div>
</footer>

</div>

</body>
</html>

最佳答案

我认为 display: table 技术适合您的情况:

body {
background-color: rgb(240, 240, 240);
}
#pageFooter {
margin-top: 10px;
background-color: red;
height: 200px;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
box-shadow: 1px 1px 1px 1px #888888;
display: table;/*Add display table*/
width: 100%;
}
#pageFooter p {
color: white;
padding-left: 1em;
font-family: sans-serif;
vertical-align: middle;
line-height: 40px;
font-weight: bold;
}
#leftFooter {
text-align: left;
display: table-cell;/*add display table-cell*/
position: relative;
}
#midFooter {
text-align: center;
display: table-cell;/*add display table-cell*/
position: relative;
}
#rightFooter {
text-align: right;
display: table-cell;/*add display table-cell*/
position: relative;
}
<body>
<div id="container">
<footer id="pageFooter">
<div id="leftFooter">
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
</div>
<div id="midFooter">
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
</div>
<div id="rightFooter">
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
<p>Lorem Ipsum</p>
</div>
</footer>
</div>
</body>

关于html - 页脚 div 文本不会对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26700709/

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