2016-06-24 41 views
0

我想列出一些數據和由垂直線分離的圖形。 這是我做已經:如何在CSS中使用豎線分隔的圖形和列?

HTML:

<div class="containers vertical-divider"> 
    <div class="column one-third"> 
    <h1 class="span glyphicon glyphicon-th"></h1> 
    </div> 
    <div class="column two-thirds"> 
    <h3>Title</h3> 
    <p>consectetur adipiscing elit. Donec sit amet vestib.</p> 
    </div> 
    <div class="column two-thirds"> 
    <h3>Details</h3> 
    <p>Lorem ipsum dolor sit amet, consectetur adipis.</p> 
    </div> 
    <div class="column one-third"> 
    <h1 class="glyphicon glyphicon-pencil"></h1> 
    </div> 
    <div class="column one-third"> 
    <h1 class="glyphicon glyphicon-remove"></h1> 
    </div> 
</div> 
<hr> 

CSS:

.vertical-divider{ 
    clear: both; 
    position: relative; 
} 

.vertical-divider:after { 
    clear: both; 
    content: " "; 
    display: block; 
    height: 0; 
    visibility: hidden; 
} 

.vertical-divider .column:not(:first-child):after, .vertical-divider .columns:not(:first-child):after{ 
    background: #DDDDDD; 
    bottom: 0; 
    content: " "; 
    margin-left: -10px; 
    position: absolute; 
    top: 0; 
    width: 1px; 
} 

/* Very simple grid for example */ 
.containers { position: relative; width: 960px; margin: 20px auto; padding: 0; } 

.containers .column, .containers .columns { float: left; display: inline; margin-left: 10px; margin-right: 10px; } 

.containers .one-third.column { width: 50px; } 

.containers .two-thirds.column { width: 250px; } 

小提琴:http://jsfiddle.net/xxpe6fnw/

正如你所看到的問題是與右側glyphicons ,每列中的寬度也不響應。

如果有人有更好,更容易的想法得到相似的結果(也許使用一些引導功能?),然後我在聽。

回答

0

嘗試使用input-group和input-group-addon。

我叉你的小提琴:http://jsfiddle.net/o7es6jvu/

<span class="input-group-addon" id="basic-addon1"><h1 class="glyphicon glyphicon-pencil"></h1></span> 
+0

感謝您的回覆。但它太醜陋了,寬度仍然沒有反應。 – DiPix

0

我使用col-md-*col-sm-*引導的響應類了你的代碼的新版本。

你可以試試嗎?

<div class="container"> 
    <div class="col-md-12 col-sm-12"> 
    <div class="row"><!-- Repeat this row for each line you want --> 
     <div class="col-md-2 col-sm-2"> 
     <h1 class="glyphicon glyphicon-th"></h1> 
     </div> 
     <div class="col-md-4 col-sm-4"> 
     <h3>Title</h3> 
     <p>consectetur adipiscing elit. Donec sit amet vestib.</p> 
     </div> 
     <div class="col-md-4 col-sm-4"> 
     <h3>Details</h3> 
     <p>Lorem ipsum dolor sit amet, consectetur adipis.</p> 
     </div> 
     <div class="col-md-2 col-sm-2"> 
     <h1 class="glyphicon glyphicon-pencil"></h1> 
     </div> 
     <div class="col-md-2 col-sm-2"> 
     <h1 class="glyphicon glyphicon-remove"></h1> 
     </div> 
    </div><!-- End repeat --> 
    </div> 
</div> 

小提琴:Here

+0

垂直線呢? – DiPix

+0

哎呀,忘了吧!即將推出:) – Mistalis

+0

@Mistalis在上面沒有必要聲明col-md- *。 col-sm- *值沒有變化。從引導站點:_Grid類適用於屏幕寬度大於或等於斷點大小的設備,並覆蓋面向較小設備的網格類。因此,例如將任何.col-md- *類應用於元素不僅會影響其在中型設備上的樣式,而且在不存在.col-lg- *類的大型設備上也會影響其樣式._ –

0

試試這個。

標記

<div class="wrapper"> 
    <div class="container"> 
     <div class="row"> 
      <div class="col-md-1"> 
       <h1 class="span glyphicon glyphicon-th"></h1> 
      </div> 
      <div class="col-md-9"> 
       <div class="row"> 
        <div class="col-md-6"> 
         <h3>Title</h3> 
         <p>consectetur adipiscing elit. Donec sit amet vestib.</p> 
        </div> 
        <div class="col-md-6"> 
         <h3>Details</h3> 
         <p>Lorem ipsum dolor sit amet, consectetur adipis.</p> 
        </div> 
       </div> 
      </div> 
      <div class="col-md-1"> 
       <h1 class="glyphicon glyphicon-pencil"></h1> 
      </div> 
      <div class="col-md-1"> 
       <h1 class="glyphicon glyphicon-remove"></h1> 
      </div> 
     </div> 
     <div class="row"> 
      <div class="col-md-1"> 
       <h1 class="span glyphicon glyphicon-th"></h1> 
      </div> 
      <div class="col-md-9"> 
       <div class="row"> 
        <div class="col-md-6"> 
         <h3>Title</h3> 
         <p>consectetur adipiscing elit. Donec sit amet vestib.</p> 
        </div> 
        <div class="col-md-6"> 
         <h3>Details</h3> 
         <p>Lorem ipsum dolor sit amet, consectetur adipis.</p> 
        </div> 
       </div> 
      </div> 
      <div class="col-md-1"> 
       <h1 class="glyphicon glyphicon-pencil"></h1> 
      </div> 
      <div class="col-md-1"> 
       <h1 class="glyphicon glyphicon-remove"></h1> 
      </div> 
     </div> 
     <div class="row"> 
      <div class="col-md-1"> 
       <h1 class="span glyphicon glyphicon-th"></h1> 
      </div> 
      <div class="col-md-9"> 
       <div class="row"> 
        <div class="col-md-6"> 
         <h3>Title</h3> 
         <p>consectetur adipiscing elit. Donec sit amet vestib.</p> 
        </div> 
        <div class="col-md-6"> 
         <h3>Details</h3> 
         <p>Lorem ipsum dolor sit amet, consectetur adipis.</p> 
        </div> 
       </div> 
      </div> 
      <div class="col-md-1"> 
       <h1 class="glyphicon glyphicon-pencil"></h1> 
      </div> 
      <div class="col-md-1"> 
       <h1 class="glyphicon glyphicon-remove"></h1> 
      </div> 
     </div> 
    </div> 
</div> 

CSS

[class*="col-"]{ 
    margin-bottom: -99999px; 
    padding-bottom: 99999px; 
} 
.wrapper { 
    background-color: #ccc; 
    width: 100%; 
} 
.container { 
    background-color: #fff; 
    margin: 0 auto; 
    max-width: 650px; 
} 
.container > .row{ 
    border: 1px solid #f00; 
    overflow: hidden; 
} 
.container > .row > div{ 
    border-right: 1px solid #f00; 
} 
.container > .row > div:last-child{ 
    border-right: none; 
} 

演示https://jsfiddle.net/codeandcloud/d5b0ztxm/7/show/

+0

目前是最佳答案。順便說一下,可以在列之間添加垂直線 - 或者太複雜了? – DiPix

0

添加這下面的代碼來調整您的垂直線,調整保證金和PADD根據你的計劃。爲了使它在移動設備上具有響應能力,那麼您必須使用媒體查詢工作。

.vertical-divider{ 
    clear: both; 
    position: relative; 
} 

.vertical-divider:after { 
    clear: both; 
    content: " "; 
    display: block; 
    height: 0; 
    visibility: hidden; 
} 


/* Very simple grid for example */ 
.containers { position: relative; width: 90%; margin: 20px auto; padding: 0; } 

.containers .column, .containers .columns { float: left; display: inline; margin-left: 10px; margin-right: 10px; } 

.containers .one-third.column { width: 10%; } 

.containers .two-thirds.column { width: 25%; } 
.containers .one-third.column:not(:first-child)::before{ 
    background: #ddd; 
    bottom: 0; 
    content: " "; 
    margin-left: -10px; 
    position: absolute; 
    top: 0; 
    width: 1px; 
} 
.containers .two-thirds.column ::before{ 
    background: #ddd; 
    bottom: 0; 
    content: " "; 
    margin-left: -10px; 
    position: absolute; 
    top: 0; 
    width: 1px; 
}