簡體   English   中英

邊界半徑背后的背景顏色

[英]Background-color behind a border-radius

我想知道,是否可以在邊界半徑后面設置背景顏色?

我想達到這個效果: 在此輸入圖像描述

我用這個HTML:

<div class="content-header" tabindex="-1">
    <span class="html">TITLE</span>
</div>
<div class="content-txt-v2" tabindex="-1">
  <p>
  Content
  </p>        
</div>

我使用這個CSS:

.content-header {
    height: 18px;
    line-height: 18px;
    background-color: #4C741B;
    margin-top: 20px;
    float: left;
    -moz-border-radius: 10px 10px 0px 0px;
    -webkit-border-radius: 10px 10px 0px 0px;
    -khtml-border-radius: 10px 10px 0px 0px;
    border-radius: 10px 10px 0px 0px;    
    padding: 0px 14px;
    font-weight: bold;
    font-size: 14px;
    color:#fff;
}
.content-txt-v2 {
    clear: both;
    width: 669px;
    padding: 0 10px;
    margin: 0px auto;
      border: 2px solid #E9EAE3;
    -moz-border-radius: 20px 10px 10px 10px;
    -webkit-border-radius: 20px 10px 10px 10px;
    -khtml-border-radius: 20px 10px 10px 10px;
    border-radius: 20px 10px 10px 10px;
    float:left;
    background-color:red;
}

我在JSFIDDLE中添加了上面的代碼

我試圖設置我的content-txt-v2 div的背景顏色,但沒有成功。 誰能引導我朝着正確的方向前進? 只有兩個div可能嗎? 或者我應該添加更多對象?

這很難做到,但你可以偽造它: https//jsfiddle.net/85c8ss94/1/

.content-header {
    height: 30px;
    line-height: 18px;
    background-color: #4C741B;
    margin-top: 20px;
    float: left;
    -moz-border-radius: 10px 10px 0px 0px;
    -webkit-border-radius: 10px 10px 0px 0px;
    -khtml-border-radius: 10px 10px 0px 0px;
    border-radius: 10px 10px 0px 0px;    
    padding: 0px 14px;
    font-weight: bold;
    font-size: 14px;
    color:#fff;
    margin-bottom: -12px;
}
.content-txt-v2 {
    clear: both;
    width: 669px;
    padding: 0 10px;
    margin: 0px auto;
    border: 2px solid #E9EAE3;
    -moz-border-radius: 20px 10px 10px 10px;
    -webkit-border-radius: 20px 10px 10px 10px;
    -khtml-border-radius: 20px 10px 10px 10px;
    border-radius: 20px 10px 10px 10px;
    float:left;
    background-color:red;
}

你為什么不做這樣的事情? 它給你所需的輸出,沒有太多的頭痛!

 * { box-sizing: border-box; } .content-header { height: 18px; line-height: 18px; background-color: #4C741B; margin-top: 20px; float: left; -moz-border-radius: 10px 10px 0px 0px; -webkit-border-radius: 10px 10px 0px 0px; -khtml-border-radius: 10px 10px 0px 0px; border-radius: 10px 10px 0px 0px; padding: 0px 14px; font-weight: bold; font-size: 14px; color: #fff; z-index: 10; /* z-index same as red bar*/ position: relative; } .content-header:after { position: absolute; top: 100%; left: 0; content: ''; background: #4C741B; width: 18px; height: 18px; display: block; z-index: 5; /* z-index less than red bar*/ } .content-txt-v2 { clear: both; width: 669px; padding: 0 10px; margin: 0px auto; border: 2px solid #E9EAE3; -moz-border-radius: 20px 10px 10px 10px; -webkit-border-radius: 20px 10px 10px 10px; -khtml-border-radius: 20px 10px 10px 10px; border-radius: 20px 10px 10px 10px; float: left; background-color: red; position: relative; /* for giving z-index */ z-index: 10; /* z-index equal to title block */ } 
 <div class="content-header" tabindex="-1"> <span class="html">TITLE</span> </div> <div class="content-txt-v2" tabindex="-1"> <p> Content </p> </div> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM