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

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

WBOY
Release: 2016-06-24 11:29:53
Original
1595 people have browsed it

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>
Copy after login

 

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

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

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

 

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template