2016-06-07 70 views

回答

0

嘗試display:inline-block;代替浮動和對準到中心。 2個div應該在一個單獨的容器中,3個div在另一個容器中,一個在另一個容器中。每個容器使用text-align:center;

0

不需要行。

* { 
 
    margin: 0; 
 
    padding: 0; 
 
    box-sizing: border-box; 
 
} 
 

 
.parent { 
 
    text-align: center; 
 
    border: 1px solid; 
 
    padding: 1em; 
 
} 
 

 
.child { 
 
    text-align: left; 
 
    border: 1px solid red; 
 
    display: inline-block; 
 
    padding: 1em; 
 
    width: 33.33%; 
 
}
<div class="parent"> 
 
    <div class="child">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus, veniam.</div><div class="child">Quisquam architecto, deleniti aperiam ipsam nisi ullam molestiae consequatur optio.</div><div class="child">Quod ad excepturi dolore sed earum impedit, nesciunt aliquid totam.</div><div class="child">Nemo repudiandae delectus deserunt molestiae temporibus modi inventore voluptates. Officiis.</div><div class="child">Quidem autem quae tempore possimus vel commodi architecto, similique tempora.</div> 
 
</div>

的jsfiddle:https://jsfiddle.net/azizn/3da5tpgn/

警告:臭名昭著的HTML空間可以你可以用inline-block s表示佔據父寬度的33.33%,並居中對齊做導致問題,您必須刪除標籤之間的空格才能正常工作,或者使用Flexbox:

* { 
 
    margin: 0; 
 
    padding: 0; 
 
    box-sizing: border-box; 
 
} 
 

 
.parent { 
 
    display: flex; 
 
    flex-wrap: wrap; 
 
    justify-content: center; 
 
    border: 1px solid; 
 
    padding: 1em; 
 
} 
 

 
.child { 
 
    border: 1px solid red; 
 
    padding: 1em; 
 
    width: 33.33%; 
 
}
<div class="parent"> 
 
    <div class="child">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nisi, nulla.</div> 
 
    <div class="child">Neque doloribus, quasi nobis sint nesciunt. Quod incidunt, vel laudantium!</div> 
 
    <div class="child">Dicta similique quasi inventore, obcaecati quia repellendus odit quam reiciendis?</div> 
 
    <div class="child">Eum esse delectus adipisci pariatur enim, quasi sed odit optio.</div> 
 
    <div class="child">Ea, amet. Ipsam sapiente harum quaerat repudiandae nobis, impedit non.</div> 
 
</div>

的jsfiddle:https://jsfiddle.net/azizn/4w46vva9/

0

使用引導:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> 
 
<!-- Latest compiled and minified CSS --> 
 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> 
 

 
<!-- Optional theme --> 
 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous"> 
 

 
<!-- Latest compiled and minified JavaScript --> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script> 
 
<div class="container text-center"> 
 
    <div class="col-xs-4">Text 1</div> 
 
    <div class="col-xs-4">Text 2</div> 
 
    <div class="col-xs-4">Text 3</div> 
 
    <div class="col-xs-3"></div> 
 
    <div class="col-xs-3">Text 4</div> 
 
    <div class="col-xs-3">Text 5</div> 
 
    <div class="col-xs-3"></div> 
 
</div>

+0

這是不準確的。 – Aziz

+0

@Aziz對我來說看起來很好。 –

+0

是的,現在它看起來不錯(編輯後),因爲你建議引導 - 爲什麼不直接在第四個'div'中添加col-md-offset-3而不是創建空白div?他們似乎並不需要 - 見演示:https://jsfiddle.net/azizn/a64yqjt9/ – Aziz