2016-05-17 268 views
-1

我想要一個帶有內部垂直文本的堆疊酒吧。我沒有把它放在正確的位置。這是我想要的: bars with angled text堆疊酒吧css

這是我的代碼和輸出:

.colWrapper{ 
 
    height:200px; 
 
    width:100px; 
 
    position:relative; 
 
    border:1px solid #ccc; 
 
} 
 
.barContainer{ 
 
    position:absolute; 
 
    bottom:0; 
 
    width:100%; 
 
} 
 
.bar{ 
 
    widith:100%; 
 
    padding:10px; 
 
    transform: rotate(90deg); 
 
    text-align:center; 
 
    margin:0 
 

 
}
<div class="colWrapper"> 
 
    <div class="barContainer"> 
 
     <div class="bar" style="background-color:#b4cde2;">Software</div> 
 
     <div style="clear:both;"></div> 
 
     
 
     <div class="bar" style="background-color:#7ca7cc;">Banking</div> 
 
     
 
    </div> 
 
</div>

回答

1

您需要使用-90deg而且,使用transform-origin

.colWrapper { 
 
    height: 200px; 
 
    width: 100px; 
 
    position: relative; 
 
    border: 1px solid #ccc; 
 
} 
 
.barContainer { 
 
    bottom: 0; 
 
    width: 100%; 
 
} 
 
.bar { 
 
    padding: 10px; 
 
    transform: rotate(-90deg); 
 
    text-align: center; 
 
    margin: 0; 
 
    left: -25px; 
 
    transform-origin: right bottom; 
 
    position: absolute; 
 
    width: 100px; 
 
    bottom: 120px; 
 
} 
 
.bar:first-child { 
 
    left: -80px; 
 
}
<div class="colWrapper"> 
 
    <div class="barContainer"> 
 
    <div class="bar" style="background-color:#b4cde2;">Software</div> 
 
    <div class="bar" style="background-color:#7ca7cc;">Banking</div> 
 
    </div> 
 
</div>

第二種方法:

.colWrapper { 
 
    height: 200px; 
 
    width: 100px; 
 
    position: relative; 
 
    border: 1px solid #ccc; 
 
} 
 
.barContainer { 
 
    bottom: -5px; 
 
    width: 100%; 
 
    transform: rotate(-90deg); 
 
    position: absolute; 
 
    left: 5px; 
 
} 
 
.bar { 
 
    padding: 10px; 
 
    text-align: center; 
 
    margin: 0 0 15px; 
 
    sposition: absolute; 
 
} 
 
.bar:first-child { 
 
    left: -80px; 
 
}
<div class="colWrapper"> 
 
    <div class="barContainer"> 
 
    <div class="bar" style="background-color:#b4cde2;">Software</div> 
 
    <div class="bar" style="background-color:#7ca7cc;">Banking</div> 
 
    </div> 
 
</div>

+1

謝謝您的回答,我們幾乎達到,但我希望它像堆積圖,你可以請參閱我附有影像。 –

1

您還可以看看寫作模式和Flex-箱。

https://developer.mozilla.org/fr/docs/Web/CSS/writing-mode

div { 
 
    display: inline-flex; 
 
    flex-flow: column wrap; 
 
    height: 320px; 
 
    width: 270px; 
 
    vertical-align: middle; 
 
} 
 
span { 
 
    padding: 20px 5px; 
 
    background: #1E84C6; 
 
    -webkit-writing-mode: vertical-lr; 
 
    /* old Win safari */ 
 
    writing-mode: vertical-lr; 
 
    writing-mode: tb-lr; 
 
    text-align: right; 
 
    margin: 10px; 
 
    height: 100px; 
 
    width: 60px; 
 
    font-size: 30px; 
 
    line-height: 60px; 
 
} 
 
span:nth-child(3) { 
 
    height: 260px; 
 
} 
 
a { 
 
    display: inline-block; 
 
    text-decoration: none; 
 
    letter-spacing: 2px; 
 
    text-transform: uppercase; 
 
    font-family: helvetica; 
 
    color: white; 
 
} 
 
div + div a { 
 
    transform: scale(-1, -1); 
 
    /* reverse writing direction optionnal*/ 
 
    btext-align: left; 
 
    transform-origin: 1em 1.25em; 
 
} 
 
span:nth-child(2) { 
 
    background: #283F4F; 
 
} 
 
span:nth-child(4) { 
 
    background: #1DC685; 
 
} 
 
​-
<div> 
 
    <span> <a href>one</a></span> 
 
    <span> <a href>two</a></span> 
 
    <span> <a href>three</a></span> 
 
    <span> <a href>four</a></span> 
 
    <span> <a href>five</a></span> 
 
</div> 
 
or 
 
<div> 
 
    <span> <a href>one</a></span> 
 
    <span> <a href>two</a></span> 
 
    <span> <a href>three</a></span> 
 
    <span> <a href>four</a></span> 
 
    <span> <a href>five</a></span> 
 
</div> 
 
and so on ...

+0

感謝您回答它真正的WOW ..但我希望它更具交互性,我不希望它具有固定值,因爲後來我想將它與動態值進行轉換。謝謝。 –

+0

@KiranJuvvalapalli我想你只需要更新值,像素爲%或使用最小寬度/最小高度。代碼現在是你的;)玩它。這裏有一支筆可以用live和fork http://codepen.io/gc-nomade/pen/jqozRB玩,你可以從右下角的導出按鈕下載一個zip文件 –