Heim  >  Artikel  >  Web-Frontend  >  为什么没法设置span的宽度和高度_html/css_WEB-ITnose

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

WBOY
WBOYOriginal
2016-06-24 11:31:321193Durchsuche

为什么没法设置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>

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

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

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

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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn