html - 如何使边框在一部分透明?

标签 html css

<分区>

我有这个代码:https://codepen.io/aceraven777/pen/dyPGBeX

HTML:

<html>
  <body>
    <div class="box">
      <div class="title-container">
        <h1>title</h1>
      </div>
      <p>this is the description</p>
    </div>
  </body>
</html>

CSS:

body {
  background: url('https://images.pexels.com/photos/255379/pexels-photo-255379.jpeg');
      background-size: cover;
  padding-top: 30px;
}

.box {
  border: 2px solid white;
  width: 100px;
  margin: auto;
  padding: 30px;
  position: relative;
}

.box .title-container {
  position: absolute;
  top: -22px;
  left: 0;
  width: 100%;
  text-align: center;
}

.box .title-container h1 {
  background-color: transparent;
  margin: 0;
  padding: 3px 10px;
  display: inline;
}

这是 HTML 的输出:

enter image description here

请记住,这里我使用的是背景图片,而不是纯色背景。

在标题部分,我希望边框不撞到标题,我希望边框对那部分是透明的,如何实现?

最佳答案

您需要的是 HTML fieldset .

 <fieldset>
  <legend style="text-align: center;">Personalia:</legend>
  Name: <input type="text"><br>
  Email: <input type="text"><br>
  Date of birth: <input type="text">
 </fieldset>

关于html - 如何使边框在一部分透明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59263424/

上一篇:html - 如何在 CSS 网格间隙之间填充文本?

下一篇:javascript - 打开时 Bootstrap 选项卡不显示事件

相关文章:

javascript - 使用 JavaScript onclick 更改堆叠图像的可见性

javascript - 无法使用 jQuery 更改按钮的值

html - 提高一个 div 在另一个之上

jquery - 页面加载零不透明度,但使用渐进增强方法?

javascript - 如何使用 jquery 将 css 应用于 div 选择器中的所有 html 元素

html - Wordpress 将图像放大 4/3

css - 如何在 CSS 中将灰色覆盖在图像上

javascript - JavaScript 文本框

html - chrome mobile 中点击按钮上的蓝色突出显示?

html - 如何将 mime 类型添加到 htaccess 文件?