繁体   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