行内块元素介绍
发布时间:2023-03-29 14:04:35 所属栏目:教程 来源:
导读:利用元素的行内元素特性我们可以很轻松的做到水平居中。
行内块的语法格式也很简单:display: inline-block;。
<!DOCTYPE html>
<html>
<head>
<Meta charset="UTF-8">
<Meta name="viewport" content
行内块的语法格式也很简单:display: inline-block;。
<!DOCTYPE html>
<html>
<head>
<Meta charset="UTF-8">
<Meta name="viewport" content
利用元素的行内元素特性我们可以很轻松的做到水平居中。 行内块的语法格式也很简单:display: inline-block;。 <!DOCTYPE html> <html> <head> <Meta charset="UTF-8"> <Meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> /* 清除默认样式 */ * { padding: ; margin: ; } /* 令html和body全屏显示, 并有一个灰色背景 */ html, body { height: ; background: gray; } body { /* 令子元素水平居中 */ text-align: center; /* 灰色背景 */ background: gray; } .center { /* 令其显示为行内块元素 */ display: inline-block; /* 给个宽高方便查看 */ width: ; height: ; /* 白色背景 */ background: white; } </style> </head> <body> <div class="center"></div> </body> </html> display: inline-block; 可以让元素既拥有行内元素的特性,同时又拥有块级元素的特性。 不过看了这么多种方式的单列布局,可是看起来依然还是很抽象。 换句话说就是不好看,那么下一小节我们就为其添油加醋一下,使其看起来更加贴合实际。 (编辑:汽车网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读