![](/img/trans.png)
[英]JS .style.display = “inline” Will display as “inline-block” in CSS
[英]CSS display inline-block and fill all spaces with elements
我有一个带display:inline-block的元素,这是一个比其他元素大的元素,在元素之间造成了空间,如图所示。
这是该示例的小提琴。
注意:请扩大结果窗口的宽度以查看完整的问题。
CSS
.calenderMonth_header {
height:35px;
line-height:35px;
text-align:center;
background-color: rgba(221,221,221,1);
border-bottom: 1px solid rgba(221,221,221,1);
}
.calenderMonth {
height: 160px;
width:160px;
margin:10px;
border-radius:2px;
background-color: rgba(238,238,238,1);
border: 1px solid rgba(221,221,221,1);
display:inline-block;
vertical-align:top;
cursor:pointer;
}
.activeMonth { height:340px; width:340px;}
.calenderMonth:hover { border: rgba(0,153,204,1) 1px solid}
JS
$(document).ready(function(e) {
var months = [
{month:'January', state:''},
{month:'Feburary', state:''},
{month:'March', state:''},
{month:'April', state:''},
{month:'December', state:''}];
$(months).each(function(index, element){
element.state == 'current' ?
activeMonth = 'activeMonth':activeMonth = '';
$('.monthsHolder').append('<article class="calenderMonth '+activeMonth+'">\
<header class="calenderMonth_header">'+element.month+'</header>\
</article>');
});
});
HTML
<section class="app_section app_section_calender hide center">
<header class="app_section_header">CALENDER
<section class="monthsHolder" align="center"></section>
</section>
如何制作较小的盒子来填充剩余的空间?
一种解决方案是让您的月份浮动,但随后您必须将居中位置移至月份持有者并指定宽度。 像这样:
.calenderMonth {
height: 160px;
width:160px;
margin:10px;
border-radius:2px;
background-color: rgba(238,238,238,1);
border: 1px solid rgba(221,221,221,1);
display:inline-block;
vertical-align:top;
cursor:pointer;
float: left;
}
.monthsHolder
{
margin: 0 auto;
width: 560px;
}
添加一个float:到您的activeMonth类:
.activeMonth {
float: left;
height: 340px;
width: 340px;
}
JsFiddle: http : //jsfiddle.net/ghorg12110/uu64hyed/2/
内联块将不会填充可用空间。 它将向下推入所有不适合可用宽度的元素。 浮动元素将解决此问题。
使用CSS float,可以将一个元素向左或向右推,允许其他元素环绕它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.