为什么没法html怎么设置div大小span的宽度和高度_html/css_WEB-ITnose


www.style.width=document.body.offsetWidth;
www.style.height=document.body.offsetHeight;
断点以上两行
document.body.offsetWidth
document.body.offsetHeight
都有确定的值
但就是没法赋给width 和 height
哇哈哈登录后复制求教
把你的JS函数改成下面的就行了:
function fun(){ var www = document.getElementById('www'); www.style.width = document.body.offsetWidth+'px'; www.style.height = document.body.offsetHeight+'px'; www.style.opacity = 0.5;}登录后复制
把你的JS函数改成下面的就行了:
JavaScript code?12345678function fun(){
var www = document.getElementById('www');
www.style.width = document.body.offsetWidth+'px';
www.style.height = document.……
的确是少加了px 这里纠正一下,文档中只有div一个元素,因此document.body的宽高和该div的宽高一致,用document.body.offsetWidth仍然跟div.style.width一样宽,所以也看不出效果
}
不知道为什么span 中line-height设置大小小于18px的话都是无效的18之后才看到效果,不知道是怎么回事求大佬解答一下http://codepen.io/1206189299/…直接给答案:给span设置display:inline-block;。原理请参看这篇文章,解释了 什么是 Block box、Line box。但是里面没有讲清楚为什么不能小于18px。这里有个解释 Height of an inline boxBut using a font-size value of 15px doesn’t mean that the tallest glyph will be 15px tall too. That depends on the font. This is somewhat analogous to normal, the initial value of line-height, which is defined asTells user agents to set the used value to a “reasonable” value based on the font of the element[…]. We recommend a used value for ‘normal’ between 1.0 to 1.2.That means that, if you use font-size: 15px, a “reasonable” line-height would be between 15px and 18px. In the “Verdana” font, Firefox thinks the best is 18px; in the “sans-serif”, it uses 17px.line-height这个东西确实不好回答,我猜这个东西和你字体设置大小有关系。引用MDN:对于块级元素,CSS属性line-height指定了元素内部line-boxes的最小高度。对于非替代行内元素,line-height用于计算line box的高度。加上display: block;是行内元素,用line-heigh需要把变成块状元素用。加上楼上说的display: block;
您愿意向朋友推荐“博客详情页”吗?
强烈不推荐
不推荐
一般般
推荐
强烈推荐
}

我要回帖

更多关于 html怎么设置div大小 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信