Heim  >  Artikel  >  Web-Frontend  >  内联元素和块级元素的如何相互转换_html/css_WEB-ITnose

内联元素和块级元素的如何相互转换_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:40:051791Durchsuche

内联元素和块级元素的如何相互转换:

内联元素和块级元素之间可以相互转换,下面就简单介绍一下转换方法。

一.内联元素转换为块级元素:

让内联元素产生浮动或者将它的display属性值设置为block即可。例如:

<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="author" content="http://www.51texiao.cn/" /><title>蚂蚁部落</title> <style type="text/css"> .myfloat{   width:200px;   height:200px;   border:1px solid red;   float:right; } .mydisplay{   width:200px;   height:200px;   border:1px solid green;   display:block; } </style> </head> <body>   <span class="myfloat">我将要浮动</span>   <span class="mydisplay">我将要添加display属性</span> </body> </html>

可以看到span已经被转换为块级元素,因为块级元素才可以设置宽度和高度。

块级元素转换为内联元素:

将块级元素的display属性值设置为inline即可。

<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="author" content="http://www.51texiao.cn/" /><title>蚂蚁部落</title> <style type="text/css"> .mytest{   width:200px;   height:200px;   border:1px solid red;   display:inline; } </style> </head> <body>   <div class="mytest">我将要浮动</div> </body> </html>

上面的代码中设置的宽度和高度都已经失效,说明对象已经被转换为内联元素。

原文地址是:http://www.51texiao.cn/div_cssjiaocheng/2015/0519/1897.html

最为原始地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=4705

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn