2015-05-13 112 views
1

Example 1帶邊框的帶角度的div

我想用傾斜的div來開發上述設計。

Example 2

到目前爲止,我所做的一樣多,如上圖所示。

下面是代碼我迄今所做的:

.brd1, .brd3, .brd8{ 
 
    background-color: #4c4c4c; 
 
} 
 
.brd, .brd-nl{ 
 
    height: 60px; 
 
} 
 
.brd2, .brd4, .brd5, .brd7{ 
 
    background-color: #289de9; 
 
} 
 
.brd2{ 
 
    border-left: 5px solid #b31989; 
 
    width: 94%; 
 
    float: left;  
 
} 
 
.brd2:before{ 
 
    border-bottom: 61px solid transparent; 
 
    border-left: 45px solid #289de9; 
 
    right: 7px; 
 
    content: ''; 
 
    width: 0px; 
 
    height: 0px; 
 
    top: 0px; 
 
    position: absolute;  
 
} 
 
.brd3:after{ 
 
    border-top: 60px solid transparent; 
 
    border-right: 45px solid #4c4c4c; 
 
    left: -30px; 
 
    content: ''; 
 
    width: 0px; 
 
    height: 0px; 
 
    top: 0px; 
 
    position: absolute;  
 
} 
 
.brd6{ 
 
    background-color: #3c6bb1; 
 
    width: 94%; 
 
} 
 
.brd6:after{ 
 
    border-top: 60px solid transparent; 
 
    border-left: 40px solid #3c6bb1; 
 
    right: 12px; 
 
    content: ''; 
 
    width: 0px; 
 
    height: 0px; 
 
    top: 0px; 
 
    position: absolute;  
 
} 
 
.brd7:before{ 
 
    border-bottom: 61px solid transparent; 
 
    border-right: 45px solid #289de9; 
 
    left: -30px; 
 
    content: ''; 
 
    width: 0px; 
 
    height: 0px; 
 
    top: 0px; 
 
    position: absolute; 
 
} 
 
.brd7{ 
 
    border-right: 5px solid #b31989;; 
 
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/> 
 
<div class=""> 
 
    <div class=""> 
 
     <div class="brd brd1 col-lg-1 col-md-1 col-sm-1"></div> 
 
     <div class="brd col-lg-5 col-md-5 col-sm-5 col-xs-12"> 
 
      \t <h3 class="brd2"></h3> 
 

 
     </div> 
 
     <div class="brd col-lg-5 col-md-5 col-sm-5 col-xs-12"> 
 
      \t <h3 class="brd3"> \t \t \t \t \t \t \t \t 
 
    \t \t \t \t </h3> 
 

 
     </div> 
 
     <div class="brd brd4 col-lg-1 col-md-1 col-sm-1"></div> 
 
    </div> 
 
    <div class="clear"></div> 
 
    <div class="space-1"></div> 
 
    <div class=""> 
 
     <div class="brd-nl brd5 col-lg-1 col-md-1 col-sm-1"></div> 
 
     <div class="brd-nl col-lg-5 col-md-5 col-sm-5 col-xs-12"> 
 
      \t <h3 class="brd6"></h3> 
 

 
     </div> 
 
     <div class="brd-nl col-lg-5 col-md-5 col-sm-5 col-xs-12"> 
 
      \t <h3 class="brd7"></h3> 
 

 
     </div> 
 
     <div class="brd-nl brd8 col-lg-1 col-md-1 col-sm-1"></div> 
 
    </div> 
 
</div>

我需要補充的是傾斜的邊框。

+1

檢查中提到的形狀http://stackoverflow.com/questions/23428286/create-border-arrow- with-css – ketan

+0

我不是天才,但是不可能用新的css來設置背景,以便像在div中的95%權利,讓5%的背景顏色不同?你似乎也看到了它的樣子,不知道你是否能找到代碼? – kingkapd

+0

這就是我正在做的事情:https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Using_multiple_backgrounds – kingkapd

回答

4

這是我的嘗試(在Chrome 42.0.2311.135測試):

http://codepen.io/anon/pen/BNKzgG

成角度div S被4個不同的linear-gradients製成,一些寬度通過vw單位計算。紅色邊框通過藍色梯度內的顏色步驟或第二個梯度重疊實現。

我也簡化了您的標記儘可能和你願意,你可以添加儘可能多的項目(儘量以取消對codepen標記)

標記

<ul> 
    <li>Injection mould making</li> 
    <li>Service and repair</li> 
    <li>Jigs and fixtures</li> 
    <li>Custom machining</li> 
</ul> 

CSS(相關)

ul li { 
    float: left; 
    width: 45%; 
    position: relative; 
    background-repeat: no-repeat !important; 
    ... 
} 

/* linear gradients for angled effect and red lines */ 

ul li:nth-child(4n-3) { 

    background: 
     /* vertical red line */ 
     linear-gradient(to right, 
      red 0px, 
      red 5px, 
      transparent 5px), 

     linear-gradient(135deg, 
      #0b3a5e 0, 
      #0b3a5e calc(100% - 30px),  
      transparent calc(100% - 30px)); 
} 

ul li:nth-child(4n-2) { 

    background: 
     linear-gradient(135deg, 
      transparent 25px, 
      red 25px, 
      red 28px, 
      #2f98e9 28px); 
} 

ul li:nth-child(4n-1) { 

    background: 
     linear-gradient(45deg, 
     #276da2 0, 
     #276da2 calc(100% - 33px), 
     red calc(100% - 33px), 
     calc(100% - 30px), 
     transparent calc(100% - 30px)); 
} 

ul li:nth-child(4n) { 

    background: 
     /* vertical red line */ 
     linear-gradient(to left, 
      red 0px, 
      red 5px, 
      transparent 5px), 

     linear-gradient(45deg, 
      transparent 25px, 
      #0b3a5e 25px); 
} 

... 

/* blocks aside */ 

ul li:after, 
ul li:before { 
    content: ""; 
    position: absolute; 
    z-index -1; 
    top: 0; 
    width: calc(5vw + 12px); 
    height: 100%; 
} 

/* calculate correct position */ 

ul li:nth-child(2n):after { 
    right: calc(-5vw - 15px); 
} 

ul li:nth-child(2n + 1):before { 
    left: calc(-5vw - 15px); 
} 

/* colour assignment */ 

ul li:nth-child(4n-3):before, 
ul li:nth-child(4n):after { 
    background: #0b3a5e; 
} 

ul li:nth-child(4n-2):after, 
ul li:nth-child(4n-1):before { 
    background: #2f98e9; 
} 

最終結果 enter image description here

注意,爲了簡單起見,我沒有指定任何廠商前綴calclinear-gradient。如果您需要支持特定的舊瀏覽器,請插入其前綴版本。

+0

嗨,其實我需要那個紅色邊框。 –

+0

我需要開發第一個圖像。 但我只能開發第二個。謝謝.. –

+0

這正是我需要的。非常感謝你。 :) –

2

你可以使用普通的CSS來獲得那些有角度的邊框。

#upper{ 
 
    width: 100px; 
 
height: 0px; 
 
border-bottom: 24px solid #2f98e9; 
 
border-left: 20px solid transparent; 
 
    margin-top:50px; 
 
    } 
 
#lower{ 
 
    width: 100px; 
 
height: 0px; 
 
border-top: 24px solid #0b3a5e; 
 
border-left: 20px solid transparent; 
 
margin-top:5px; 
 
} 
 
#lupper{ 
 
    width: 100px; 
 
height: 0px; 
 
border-bottom: 24px solid #2f98e9; 
 
border-right: 20px solid transparent; 
 
    } 
 
#llower{ 
 
    width: 100px; 
 
height: 0px; 
 
border-top: 24px solid #0b3a5e; 
 
border-right: 20px solid transparent; 
 
margin-top:5px; 
 
}
<div id="lupper"></div> 
 
<div id="llower"></div> 
 
<div id="upper"></div> 
 
<div id="lower"></div>

使用他們在任何你需要讓你的形象

+0

嘗試在'lower' div – fcalderan

+0

上插入文本,如果您想要其中的任何文本,您可以簡單地將其他div與內聯保持一致,並在該div中添加您的內容。 – Jayababu

+0

嗨,其實我需要那個紅色的邊框。 –