gpt4 book ai didi

html - 居中 float DIV

转载 作者:行者123 更新时间:2023-11-28 03:55:50 24 4
gpt4 key购买 nike

我试图将 3 个 float DIV 居中。如果我给父 DIV display:table; 和子 DIV display:cell; 它将起作用,它们将像一个表一样工作。还有别的办法吗?

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Center Div</title>
<style type="text/css">
#container
{
text-align:center;
margin:0 auto;
display:table;
}
#container div
{
float:left;
padding:5px;
display:cell;
}
</style>
</head>
<body>
<div id="container">
<div style="background-color:yellow">Text 1</div>
<div style="background-color:lightgreen">Text 2</div>
<div style="background-color:lightblue">Text 3</div>
</div>
</body>
</html>

最佳答案

我想如果你定义宽度,display: block, margin 0px auto, position:relative 它应该可以工作。

关于html - 居中 float DIV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11683994/

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