通过html和CSS通过多层创建透明边框

时间:2019-02-14 08:10:13

标签: javascript html css

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

Java


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

    /* 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> 

   

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

您可以使用类似此图像或透明图像的放射状背景:

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