html如何实现这个边框样式,边框中间显示文字

新手上路,请多包涵

图片描述

阅读 9.9k
5 个回答

html

<div class="item">
  <h3> 这里显示文字</h3>
</div>

css

 *{box-sizing: border-box; padding: 0;margin: 0;}
body{
  padding: 50px
}
.item{
  width: 500px;
  height: 200px;
  margin: 0 auto;
  padding: 15px;
  border:2px solid rgba(63,174,174,1);
  border-radius: 20px;
  position: relative;
  h3{
    position: absolute;
    top: -15px;
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    padding: 0 50px;
    z-index: 2;;
  }
  &:before,&:after{
    content: '';
    position: absolute;
    top: -7px;
    width: 12px;
    height: 12px;
    border-radius: 6px;
    background-color: rgba(63,174,174,1);
    z-index: 3;
  }
  &:before{
    left: 135px;
  }
  &:after{
    right: 135px
  }
}
  <fieldset>
    <legend>这里显示文字</legend>
    这里显示内容
  </fieldset>
fieldset{
  width: 500px;
  min-height: 200px;
  border-radius: 10px;
  border: 2px solid #4fbaba;
}
legend{
  position: relative;
  text-align: center;
  padding: 0 50px;
}
legend:before, legend:after{
  content: '';
  display: table;
  position: absolute;  
  top: 0;
  width: 20px;
  height: 20px;
  border-radius: 10px;
  background: #4fbaba;
}
legend:before{
  left: 0;
}

legend:after{
  right: 0;
}

clipboard.png

codepen地址

<div class="container">
      <div class="blueBorder">
         <div class="blueRadius">

         </div>
          <div class="blueRadius">
           
         </div>
         <div class="text">
           这里显示文字
         </div>
      </div>
    </div>
.container{
  width: 100%;
  height: 100%;
  display: flex;
  justify-content:center;
  background-color: #ffffff;
}
.blueBorder{
  width: 400px;
  height: 150px;
  border:2px solid rgba(63,174,174,1);
  border-radius: 20px;
  position: relative;
}
.blueBorder div{
  position: absolute;
}
.blueRadius{
  width: 12px;
  height: 12px;
  border-radius: 6px;
  background-color: rgba(63,174,174,1);
}
.blueRadius:first-child{
  top: -6px;
  left: 50px;
}
.blueRadius:nth-child(2){
  top: -6px;
  right: 50px;
}
.text{
  width: 272px;
  top: -10px;
  left: 62px;
  height: auto;
  text-align: center;
  background-color: #ffffff
}

clipboard.png

要简单粗暴的话做个背景图就行了,要项目需要考虑性能优化在意那么几十几百毫秒的加载时间的话就按其他回答那样用css写吧。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题