繁体   English   中英

HTML5边界半径反向填充

[英]Html5 Border-Radius Reverse Fill

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

在此处输入图片说明

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

在此处输入图片说明

  .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> 

任何建议都会很有帮助。

在此处输入图片说明

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

非常简单 您已经达到了将近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/

看看这个: 在此处输入图片说明 https://jsfiddle.net/sLy7fnzg/

本质上,请使用负边距将.div-user-header-list向上移动,并使用相对位置来启用z- .div-user-header-list

另外,要解决半边框问题,请从.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;
}
<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> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM