Home > Web Front-end > HTML Tutorial > 将span元素设置为固定宽度和高度代码_html/css_WEB-ITnose

将span元素设置为固定宽度和高度代码_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:30:21
Original
1824 people have browsed it

将span元素设置为固定宽度和高度代码:
本章节介绍一下如何给span元素设置固定宽度和高度,之所以要专门介绍一下,是因为默认状态下,给它添加和width和height属性并不能够起作用,代码如下:

 

span{  width:200px;  height:200px;}
Copy after login

这是因为span元素是内联元素,无法设置高度和宽度,只能够自适应内容大小,代码修改如下:

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

以上代码可以设置span元素的尺寸,这是因为使用display:block将其转换为块级元素。

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

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

 

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