如何更改DIV填充而不影响宽度/高度? [英] How to change a DIV padding without affecting the width/height ?
本文介绍了如何更改DIV填充而不影响宽度/高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个div,我想指定一个FIXED的宽度和高度,以及一个填充,可以改变而不减少原来的DIV宽度/高度或增加它,有一个CSS技巧,使用填充?
解决方案
解决方案是用 padded div div 。
c>< div class =outer>< div class =inner>
<! - 您的内容 - >
< / div><! - end .inner - >
< / div><! - end .outer - >
CSS
.outer,.inner {
display:block;
}
.outer {
/ *指定固定宽度* /
width:300px;
padding:0;
}
.inner {
/ *指定填充,可以保留固定宽度的.outer * /
padding:5px;
}
I have a div that I want to specify a FIXED width and height for, and also a padding which can be changed without decreasing the original DIV width/height or increasing it, is there a CSS trick for that, or an alternative using padding?
解决方案
Solution is to wrap your padded div, with fixed width outer div
HTML
<div class="outer">
<div class="inner">
<!-- your content -->
</div><!-- end .inner -->
</div><!-- end .outer -->
CSS
.outer, .inner {
display: block;
}
.outer {
/* specify fixed width */
width: 300px;
padding: 0;
}
.inner {
/* specify padding, can be changed while remaining fixed width of .outer */
padding: 5px;
}
这篇关于如何更改DIV填充而不影响宽度/高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文