居中的问题

<!DOCTYPE HTML>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8">

<title>居中4</title>

<style type="text/css">

ul{

position:relative;

top:5px;

left:50%;

}

div{

display:inline;

text-align:center;

}

</style>

</head>

<body>

<ul>

<li>我是第一个文本</li>

<li>我是第一个文本</li>

<li>我是第一个文本</li>

<li>我是第一个文本</li>

</ul>

<div>我是第一个div</div>

</body>

</html>

div不是块级元素吗?为什么我将块级元素转化成内联元素不能居中?求解

qq_禁灭生_03414590
浏览 1485回答 3
3回答

心似一片青苔

1、text-align是让文本居中 <div>我是第一个div</div> -> 这里的div是块级元素没错,但是div里的内容(我是第一个div)是文本, 即是inline-block 直接 div{text-align:center;} 2、举个例子:<div><img src="">我是div里面的inline-block</<img><div> 以上纯属个人理解

李晓健

行内元素都在一行默认从左到右显示,当然不会自动居中了,想让行内元素居中,就需要给它的父级添加 text-align:center;

慕的地8582982

https://www.imooc.com/wenda/detail/349177https://www.imooc.com/wenda/detail/348889https://www.imooc.com/wenda/detail/345150https://www.imooc.com/wenda/detail/351229https://www.imooc.com/wenda/detail/342279https://www.imooc.com/wenda/detail/386187https://www.imooc.com/wenda/detail/352075https://www.imooc.com/wenda/detail/356502https://www.imooc.com/wenda/detail/389281https://www.imooc.com/wenda/detail/356918https://www.imooc.com/wenda/detail/386197https://www.imooc.com/wenda/detail/394941https://www.imooc.com/wenda/detail/382074https://www.imooc.com/wenda/detail/389425https://www.imooc.com/wenda/detail/395487https://www.imooc.com/wenda/detail/356048https://www.imooc.com/wenda/detail/382784https://www.imooc.com/wenda/detail/385817https://www.imooc.com/wenda/detail/384128https://www.imooc.com/wenda/detail/385494https://www.imooc.com/wenda/detail/388316https://www.imooc.com/wenda/detail/383442https://www.imooc.com/wenda/detail/355450https://www.imooc.com/wenda/detail/342033https://www.imooc.com/wenda/detail/387423https://www.imooc.com/wenda/detail/362348https://www.imooc.com/wenda/detail/383630https://www.imooc.com/wenda/detail/387361https://www.imooc.com/wenda/detail/410608https://www.imooc.com/wenda/detail/377540https://www.imooc.com/wenda/detail/388328https://www.imooc.com/wenda/detail/385555https://www.imooc.com/wenda/detail/363399https://www.imooc.com/wenda/detail/356619https://www.imooc.com/wenda/detail/383239https://www.imooc.com/wenda/detail/377654https://www.imooc.com/wenda/detail/362346https://www.imooc.com/wenda/detail/417335https://www.imooc.com/wenda/detail/356831https://www.imooc.com/wenda/detail/387320https://www.imooc.com/wenda/detail/384104https://www.imooc.com/wenda/detail/383498https://www.imooc.com/wenda/detail/385846https://www.imooc.com/wenda/detail/546033https://www.imooc.com/wenda/detail/356647https://www.imooc.com/wenda/detail/381372https://www.imooc.com/wenda/detail/390126https://www.imooc.com/wenda/detail/381670https://www.imooc.com/wenda/detail/385845https://www.imooc.com/wenda/detail/390690https://www.imooc.com/wenda/detail/362141https://www.imooc.com/wenda/detail/342389https://www.imooc.com/wenda/detail/339680https://www.imooc.com/wenda/detail/383525https://www.imooc.com/wenda/detail/394965https://www.imooc.com/wenda/detail/390738https://www.imooc.com/wenda/detail/459186https://www.imooc.com/wenda/detail/382828https://www.imooc.com/wenda/detail/356542https://www.imooc.com/wenda/detail/377562https://www.imooc.com/wenda/detail/350025https://www.imooc.com/wenda/detail/352280https://www.imooc.com/wenda/detail/381464https://www.imooc.com/wenda/detail/363055https://www.imooc.com/wenda/detail/356454https://www.imooc.com/wenda/detail/339921https://www.imooc.com/wenda/detail/385831https://www.imooc.com/wenda/detail/408173https://www.imooc.com/wenda/detail/385582https://www.imooc.com/wenda/detail/332808https://www.imooc.com/wenda/detail/353369https://www.imooc.com/wenda/detail/390585https://www.imooc.com/wenda/detail/362177https://www.imooc.com/wenda/detail/344918https://www.imooc.com/wenda/detail/356011https://www.imooc.com/wenda/detail/350246https://www.imooc.com/wenda/detail/362796https://www.imooc.com/wenda/detail/363054https://www.imooc.com/wenda/detail/395478https://www.imooc.com/wenda/detail/352714

蜂之谷

div{     margin:0 auto;     text-align:center; }
打开App,查看更多内容
随时随地看视频慕课网APP