为什么没法设置span的宽度和高度_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:31:32
Original
1193 people have browsed it

为什么没法设置span的宽度和高度:
建议:尽可能的手写代码,可以有效的提高学习效率和深度。
很多刚开始学习div+css布局的时候可能会碰到这样的问题,使用CSS代码无法设置span的高度和宽度,尽管CSS代码没有错误,却无法生效。例如

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

在以上代码中,设置的span元素的高度和宽度无法生效。这种现象的原因是,内联元素无法设置宽度和高度,如果要想设置宽度和高度,则必须首先转换成块级元素,方法是将内联元素的display属性值设置为block即可。 CSS代码修改如下:

width:200px;height:200px;display:block;border:1px solid red;
Copy after login

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

更多内容可以参阅: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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!