Home  >  Article  >  Web Front-end  >  css设置span元素的尺寸_html/css_WEB-ITnose

css设置span元素的尺寸_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:29:531527browse

css设置span元素的尺寸:
在默认状态下是无法设置span元素的尺寸的,只能够根据内容的尺寸自适应,也就是说给span元素设置width和height属性默认条件是无效的。之所以会出现这种情况是因为span元素是内联元素,内联元素无法设置尺寸的,只要设置为块级或者内联块级元素即可。
代码实例如下:

 

<!DOCTYPE html>    <html>    <head>    <meta charset=" utf-8">    <meta name="author" content="http://www.softwhy.com/" />    <title>蚂蚁部落</title>    <style type="text/css">#antzone{  width:200px;  height:100px;  background:green;  display:block;}</style>    </head>  <body>  <span id="antzone"></span> </body>    </html>

 

以上代码将span元素添加display:block属性之后,可以将其设置为块级元素,也就能够设置尺寸了,也可以使用display:inline-block将其设置为内联块级元素,也可以实现同样的功能。

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=13408

更多内容可以参阅:http://www.softwhy.com/divcss/

 

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