Home  >  Article  >  Web Front-end  >  How to convert inline elements and block-level elements to each other_html/css_WEB-ITnose

How to convert inline elements and block-level elements to each other_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:40:051789browse

How to convert inline elements and block-level elements to each other:

Inline elements and block-level elements can be converted to each other. Here is a brief introduction Let’s look at the conversion method.

1. Convert inline elements to block-level elements:

Just let the inline element float or set its display attribute value to block. For example:

<!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>

You can see that span has been converted to a block-level element, because only block-level elements can set the width and height.

Convert block-level elements to inline elements:

Set the display attribute value of the block-level element to 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>

The width and height set in the above code are invalid, indicating that the object has been converted to an inline element.

The original address is: http://www.51texiao.cn/div_cssjiaocheng/2015/0519/1897.html

The most original address is: http://www.softwhy.com/ forum.php?mod=viewthread&tid=4705

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn