[英]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.