[英]Align parent of floating divs on center
<div class="bigParent">
<div class="parent">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>
</div>
http://jsfiddle.net/te9fzaub/4/ - Simple example; http://jsfiddle.net/te9fzaub/4/-简单示例;
Ok, so i have the code above, what i'm trying to achieve is to have .child
floated left and .parent
on display:inline-block;
好的,所以我有上面的代码,我想要实现的是让.child
浮动到左边, .parent
在display:inline-block;
but being centered in .bigParent
. 但以.bigParent
为中心。
The issue i'm getting i that if the 3rd .child div
isn't fitting in the .bigParent
width, it puts it on a new line and it makes .parent div's
width 100%; 我得到的问题是,如果第三个.child div
不适合.bigParent
宽度,则会将其放在新行上,并使.parent div's
宽度为100%;
Thanks in advance, love this community! 在此先感谢,热爱这个社区!
I know this is a method, but i'd like to use only css if possible. 我知道这是一种方法,但如果可能的话,我只想使用CSS。 I've posted it as answer so maybe others having this problem might consider this a temporary solution. 我已将其发布为答案,所以也许其他人遇到此问题可能会认为这是一个临时解决方案。
var maxWidth = $('.bigParent').width(),
childWidth = $('.child').width(),
nrOfChildren = Math.floor(maxWidth/childWidth),
parentWidth = nrOfChildren*(childWidth);
$('.parent').width(parentWidth);
http://jsfiddle.net/te9fzaub/6/ http://jsfiddle.net/te9fzaub/6/
Still waiting for a CSS method anyway. 无论如何,仍在等待CSS方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.