HTML5边界半径反向填充

时间:2018-12-27 06:14:33

标签: html css html5 css3

我想按照以下设计图片实现下拉按钮。请参阅下拉菜单,仅在按钮中间之后才开始。我的问题是按钮具有透明背景,以利用根父div的背景图像。

enter image description here

到目前为止,我已经实现了以下图像。就像我上面说的,我想在边界半径之外获得白色边缘。

enter image description here

    .dropdown-header {
      border-top-left-radius: 20px;
      border-top-right-radius: 20px;
      width: 210px;
      height: 185px;
      margin: auto;
    }
    
    
    .div-user-header {
      width: 210px;
      margin: auto;
      position: relative;
    
      border-top-left-radius: 20px;
      border-top-right-radius: 20px;
    
    }
    
    .div-user-header-1 {
      width: 206px;
      height: 24px;
      border: 2px solid #9CB2C7;
      border-radius: 20px;
      display: inline-block;
      text-align: center;
      padding-top: 5px;
    
    }
    
    .div-user-header-1 a {
      text-decoration: none;
      color: #FCCC00;
      display: block;
    
    }
    
    
    .div-user-header-list {
      position: absolute;
      background-color: white;
      height: 170px;
      width: 210px;
    
    
    }
    
    .div-user-header-2 a {
      text-decoration: none;
      font-size: 12px;
      color: #8C8C8C;
    }
    
    .div-user-header-2 {
      height: 40px;
      padding: 12px 15px;
    
    
    }
    
    .div-user-header-3 a {
      text-decoration: none;
      font-size: 12px;
      color: #8C8C8C;
    }
    
    .div-user-header-3 {
      height: 40px;
      padding: 12px 15px;
    
    }
    
    .div-add-profile-card {
    
      padding: 0px 15px;
    }
    
    .div-add-profile-card a {
      text-decoration: none;
      color: #8C8C8C;
      font-size: 10px;
      padding: 12px;
      display: block;
      border-top: 1px solid #D6D6D6;
    }
    <div class="dropdown-header">
        <div class="div-user-header">
          <div class="div-user-header-1">
            <a href="#profileuser01">ProfileUser 01</a>
          </div>
          <div class="div-user-header-list">
            <div class="div-user-header-2">
              <img src="../../../assets/images/avtar2.png" width="34px" height="34px" style="padding-right: 5px; vertical-align: middle" />
              <a href="#profileuser02">ProfileUser 01</a>
            </div>
            <div class="div-user-header-3">
              <img src="../../../assets/images/user-02.png" width="30px" height="30px" style="padding-right:5px; vertical-align: middle" />
              <a href="#profileuser03">ProfileUser 02</a>
            </div>
            <div class="div-add-profile-card">
              <a href="add profile card"> + Add Profile Cards</a>
            </div>
          </div>
        </div>

任何建议都会很有帮助。

4 个答案:

答案 0 :(得分:1)

enter image description here

使用::after ::before个伪元素作为下拉菜单,并应用图像中标记的单独的background-image。应用position:absolute,然后根据设计在左上角和右上角对齐。

答案 1 :(得分:1)

这很简单。您已经达到了将近99%。只需将以下样式添加到.div-user-header-list的CSS中,如下所示:

.div-user-header-list {
    position: absolute;
    background-color: white;
    height: 170px;
    width: 210px;
    padding-top: 20px;
    margin-top: -20px;
    z-index: -1;
}

在此处查看更新的小提琴:https://jsfiddle.net/8ukj3wy1/1/

答案 2 :(得分:0)

检查此一项: enter image description here https://jsfiddle.net/sLy7fnzg/

基本上使用负边距将.div-user-header-list向上移动,并使用相对定位来启用z索引。

另外,要解决半边框问题,请从.div-user-header-1删除边框,然后将整个元素作为::before添加到.div-user-header,如下所示:

.div-user-header::before {
    content: "";
    background: #9CB2C7;
    width: 210px;
    height: 30px;
    display:block;
    position: absolute;
    top: 0;
    left: 0;
    border-radius: 20px;
    z-index: 1;
}

答案 3 :(得分:-2)

<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://fonts.googleapis.com/css?family=Varela+Round" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">

    <style>
    body{
        background-color: grey;
    }
        .dropdown-header {
      border-top-left-radius: 20px;
      border-top-right-radius: 20px;
      width: 210px;
      height: 203px;
      margin: auto;
      overflow: hidden;
      /*background-color: #fff;*/
    }

    .div-user-header-list:before,
    .div-user-header-list:after {
        content: "";
        position: absolute;

        height: 10px;
        width: 20px;

        bottom: 0;
    }
        .div-user-header-list:before {
        /*right: -20px;*/
        left: 1px;
        top: -10px;
        border-radius: 0 0 0 10px;
        -moz-border-radius: 0 0 0 10px;
        -webkit-border-radius: 0 0 0 10px;

        -webkit-box-shadow: -10px 0 0 0 #fff;
        box-shadow: -10px 0 0 0 #fff;
    }

    .div-user-header-list:after {
        /*left: -20px;*/
        right: 1px;
        top: -10px;
        border-radius: 0 0 10px 0;
        -moz-border-radius: 0 0 10px 0;
        -webkit-border-radius: 0 0 10px 0;

        -webkit-box-shadow: 10px 0 0 0 #fff;
        box-shadow: 10px 0 0 0 #fff;
    }
    .div-user-header {
      width: 210px;
      margin: auto;
      position: relative;

      border-radius: 20px;      

    }

    .div-user-header-1 {
      width: 206px;
      height: 24px;
      border: 2px solid #9CB2C7;
      border-radius: 20px;
      display: inline-block;
      text-align: center;
      padding-top: 5px;

    }

    .div-user-header-1 a {
      text-decoration: none;
      color: #FCCC00;
      display: block;

    }


    .div-user-header-list {
      position: absolute;
      background-color: white;
      height: 170px;
      width: 210px;
        /*margin-top: -14px;
    z-index: -9;
    padding-top: 14px;*/

    }

    .div-user-header-2 a {
      text-decoration: none;
      font-size: 12px;
      color: #8C8C8C;
    }

    .div-user-header-2 {
      height: 40px;
      padding: 12px 15px;


    }

    .div-user-header-3 a {
      text-decoration: none;
      font-size: 12px;
      color: #8C8C8C;
    }

    .div-user-header-3 {
      height: 40px;
      padding: 12px 15px;

    }

    .div-add-profile-card {

      padding: 0px 15px;
    }

    .div-add-profile-card a {
      text-decoration: none;
      color: #8C8C8C;
      font-size: 10px;
      padding: 12px;
      display: block;
      border-top: 1px solid #D6D6D6;
    }   


    </style>

</head>    

<body>

<div class="dropdown-header">
        <div class="div-user-header">
          <div class="div-user-header-1">
            <a href="#profileuser01">ProfileUser 01</a>
          </div>
          <div class="div-user-header-list">
            <div class="div-user-header-2">
              <img src="../../../assets/images/avtar2.png" width="34px" height="34px" style="padding-right: 5px; vertical-align: middle" />
              <a href="#profileuser02">ProfileUser 01</a>
            </div>
            <div class="div-user-header-3">
              <img src="../../../assets/images/user-02.png" width="30px" height="30px" style="padding-right:5px; vertical-align: middle" />
              <a href="#profileuser03">ProfileUser 02</a>
            </div>
            <div class="div-add-profile-card">
              <a href="add profile card"> + Add Profile Cards</a>
            </div>
          </div>
        </div>
</body>
</html>