居中浮动DIV [英] Center floating DIVs
本文介绍了居中浮动DIV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<!DOCTYPE html>
< html lang =en>
< head>
< meta charset =UTF-8/>
< title>中心Div< /标题>
< 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>
解决方案
$ $ p $ $ $ $ $ $ $ $ $ $ -居中对齐;
margin:0 auto;
width:150px;
}
Im trying to center 3 floating DIVs. It works if I give the parent DIV display:table; and the child DIVs display:cell; which will then act like a table. Is there another way ?
<!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>
解决方案
You need to assign width to the parent div
like this :
#container
{
text-align:center;
margin:0 auto;
width:150px;
}
这篇关于居中浮动DIV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文