2014-10-03 117 views
5

我有一個小部件,其中不能將包裹在另一個div中。刪除部分邊框

我的問題是如何從標題/標題欄中刪除邊框,但仍然保留在DIV的其餘部分?下面的例子。

僅向.body添加邊框是不可行的,因爲如果最終用戶向小部件div的底部/頂部添加了填充部分,則會導致事件中斷。

Image issue

<div class="widget"> 
    <div class="header">Header Title</div> 
    <div class="body">My Content</div> 
</div> 


.widget { 
    height: 100px; 
    width: 130px; 
    border: 3px solid blue; 
    position: absolute; 
    overflow: hidden; 
} 
.header { 
    width: 100%; 
    min-height: 24px; 
    max-height: 24px; 
    display: block; 
    background-color: grey; 
    color: white; 
} 
.body { 
    width: 100%; 
    height: calc(100% - 24px); 
} 

http://jsfiddle.net/botwfngv/

+1

http://jsfiddle.net/botwfngv/1/ – Cheery 2014-10-03 18:12:20

+0

謝謝! – 2014-10-03 18:13:35

+0

不幸的是,'overflow:hidden;'應該被移除,否則你不能覆蓋父子的邊界。 – Cheery 2014-10-03 18:15:10

回答

4
.widget { 
    height: 100px; 
    width: 130px; 
    border: 3px solid blue; 
    position: absolute; 
} 
.header { 
    width: 100%; 
    min-height: 24px; 
    max-height: 24px; 
    display: block; 
    background-color: grey; 
    color: white; 
    margin: -3px; 
    padding: 3px; 
} 
.body { 
    width: 100%; 
    height: calc(100% - 24px); 
} 

http://jsfiddle.net/botwfngv/2/

+0

只需將「margin」和「padding」更改爲「-3px」和「3px」以適應「border」。 +1 – melancia 2014-10-03 18:16:38

+0

@MelanciaUK是的,高分辨率屏幕,看不到細節的小細節))Thanx – Cheery 2014-10-03 18:17:29

+0

加分點,如果你可以找出爲什麼bootstrap打破這個.. = \ http://jsfiddle.net/botwfngv/3/ – 2014-10-03 19:01:08

0

可以實現通過CSS2的結果而已,只是添加邊框的body,而不是整個widget

.widget { 
    width: 130px; 
    position: absolute; 
    padding: 25px; 
} 

.header { 
    width: 100%; 
    min-height: 24px; 
    max-height: 24px; 
    display: block; 
    background-color: grey; 
    color: white; 
    padding: 3px; 
    position: absolute; 
    top: 0; 
    left: 0; 
    right: 0; 
} 

.body { 
    width: 100%; 
    height: 100px; 
    border: 3px solid blue; 
    border-top-width: 0; 
    position: absolute; 
    bottom: 0; 
    left: 0; 
    right: 0; 
    top: 30px; 
} 

JSFiddle Demo

+0

重新閱讀這個問題。 – 2014-10-06 22:52:55

+0

@White Oooops先生,我的錯。我已經更新了我的答案......(注意我已添加到「小部件」的「padding」。 – dashtinejad 2014-10-07 04:44:47