【问题标题】:Create a transparent border through multiple layers with html and css [duplicate]使用html和css通过多层创建透明边框[重复]
【发布时间】:2019-07-08 04:55:43
【问题描述】:

我从一个设计团队收到了下面的设计,我不确定在粉色添加按钮和导航栏之间创建透明边框/边距的最佳方法是什么。

Navbar design


我的 html 和 css 包含在下面,但我不希望使用具有特定颜色的边框,而是希望边框通过导航栏是透明的(如果这有意义的话)。我这样做的原因是导航栏和按钮将用于具有不同背景颜色的不同页面,因此具有固定的边框颜色并不理想。

    /* Remove default html margin */

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    background-image: linear-gradient(147deg, #6c318f, #262262);
}

/* Place the navbar at the bottom of the page, and make it stick */

.navbar {
    background-color: white;
    overflow: hidden;
    position: fixed;
    box-sizing: border-box;
    bottom: 0;
    width: 100%;
}

/* Style the links inside the navigation bar */

.navbar a {
    display: block;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
    box-sizing: border-box;
    width: 20%;
}
.float-left {
    float: left;
}
.float-right {
    float: right;
}

/* Remove inherent hover color for link */

.navbar a.active {
    color: white;
}

/* Bottom navbar icon */

.bottom-nav-icon {
    width: 24px;
    height: 24px;
    object-fit: contain;
    opacity: 0.4;
}

/* Active/Hover bottom navbar icon */

.bottom-nav-icon.active, .bottom-nav-icon:hover {
    opacity: 1;
}

/* Circular button */

.buy-button {
    position: fixed;
    /* fix the button to the bottom centre and show above other elements*/
    right: 0;
    left: 0;
    bottom: 28px;
    margin-right: auto;
    margin-left: auto;
    z-index: 5;
    /* style the button */
    background-color: #ec008c;
    color: white;
    text-align: center;
    display: inline-block;
    width: 56px;
    height: 56px;
    font-size: 16px;
    border-radius: 50%;

    /* create border around button - this is where I am stuck */
    border: 2px solid #262262;
}
        <!DOCTYPE html>
<html>

<head>
    <title>emoyeni</title>

    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="stylesheet" href="styles.css">
</head>

<body>

    <button class="buy-button">+</button>

    <div class="navbar">
        <a href="#home" class="active float-left">
            <img src="img/baseline-bar-chart-24-px.svg" class="bottom-nav-icon active">
        </a>
        <a href="#news" class="float-left">
            <img src="img/baseline-textsms-24-px.svg" class="bottom-nav-icon">
        </a>
        <a href="#contact" class="float-right">
            <img src="img/baseline-account-balance-wallet-24-px.svg" class="bottom-nav-icon">
        </a>
        <a href="#contact" class="float-right">
            <img src="img/baseline-notifications-24-px.svg" class="bottom-nav-icon">
        </a>
    </div>

</body>

</html> 

   

【问题讨论】:

  • 你不能有一个特定的颜色,你可以在需要的特定页面上覆盖它吗?

标签: javascript html css


【解决方案1】:

您可以使用与此类似的径向背景或透明图像:

.navbar {
  background:radial-gradient(circle at top, transparent 34px,#fff 34px,#fff 33px);
  overflow: hidden;
  position: fixed;
  box-sizing: border-box;
  bottom:0;
  height:60px;
  width: 100%;
}

.buy-button {
  position: fixed;
  /* fix the button to the bottom centre and show above other elements*/
  left: calc(50% - 20px);
  bottom: 30px;
  margin-right: auto;
  margin-left: auto;
  z-index: 5;
  /* style the button */
  background-color: #ec008c;
  color: white;
  text-align: center;
  display: inline-block;
  width: 56px;
  height: 56px;
  font-size: 16px;
  border-radius: 50%;
  /* create border around button - this is where I am stuck */
  border: 2px solid transparent;
}
img {
height:30px;
width:auto;
} 
body {
background:url(https://images.unsplash.com/photo-1520987623799-101883d6585a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=614&q=80) no-repeat center top;
}
<button class="buy-button">+</button>

<div class="navbar">
  <a href="#home" class="active float-left">
    <img src="https://cdn3.iconfinder.com/data/icons/human-resources-management/512/business_man_office_male-512.png" class="bottom-nav-icon active">
  </a>
  <a href="#news" class="float-left">
    <img src="https://cdn3.iconfinder.com/data/icons/human-resources-management/512/business_man_office_male-512.png" class="bottom-nav-icon">
  </a>
  <a href="#contact" class="float-right">
    <img src="https://cdn3.iconfinder.com/data/icons/human-resources-management/512/business_man_office_male-512.png" class="bottom-nav-icon">
  </a>
  <a href="#contact" class="float-right">
    <img src="https://cdn3.iconfinder.com/data/icons/human-resources-management/512/business_man_office_male-512.png" class="bottom-nav-icon">
  </a>
</div>

【讨论】:

    【解决方案2】:

    只需在边框颜色中使用transparent 值即可:

     border: 2px solid transparent;
    

    .navbar {
      background-color: white;
      overflow: hidden;
      position: fixed;
      box-sizing: border-box;
      bottom: 0;
      width: 100%;
    }
    
    .buy-button {
      position: fixed;
      /* fix the button to the bottom centre and show above other elements*/
      right: 0;
      left: 0;
      bottom: 28px;
      margin-right: auto;
      margin-left: auto;
      z-index: 5;
      /* style the button */
      background-color: #ec008c;
      color: white;
      text-align: center;
      display: inline-block;
      width: 56px;
      height: 56px;
      font-size: 16px;
      border-radius: 50%;
      /* create border around button - this is where I am stuck */
      border: 2px solid transparent;
    }
    <button class="buy-button">+</button>
    
    <div class="navbar">
      <a href="#home" class="active float-left">
        <img src="img/baseline-bar-chart-24-px.svg" class="bottom-nav-icon active">
      </a>
      <a href="#news" class="float-left">
        <img src="img/baseline-textsms-24-px.svg" class="bottom-nav-icon">
      </a>
      <a href="#contact" class="float-right">
        <img src="img/baseline-account-balance-wallet-24-px.svg" class="bottom-nav-icon">
      </a>
      <a href="#contact" class="float-right">
        <img src="img/baseline-notifications-24-px.svg" class="bottom-nav-icon">
      </a>
    </div>

    【讨论】:

    • 我试过了,但问题是透明边框通过按钮后面的白色导航栏不透明 - 因此导航栏和浮动按钮之间的间隙不像设计中那样可见。
    • 您的代码运行不正常,能否请您提供一个带有正确位置图标的代码?如果可以,我们也会帮助您解决这个问题...
    • 抱歉 - 编辑了代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-17
    • 2016-02-01
    • 1970-01-01
    • 2013-04-20
    • 2015-04-01
    • 2017-09-20
    • 1970-01-01
    相关资源
    最近更新 更多