html - 创建一个内部有文字的边框

标签 html css

我想在附件中创建一个带有文本的边框。我尝试了不同的解决方案,但找不到也适用于移动版本的解决方案。

有没有人有想法?

例子

example

最佳答案

div {
  height: 50px;
  width: 600px;
  border: 2px solid black;
  border-radius: 35px;
}
    
h1 {
  text-align: center;
  padding: 0 10px;
  width: 200px; /* Might to adjust this based on screen, using css media query */
  margin-top: 30px; /* Might need to play around with this value based on text size */
  margin-left: auto;
  margin-right: auto;
  background: white;
}
<div>
      <h1>This is a title</h1>
</div>

基于此 Text in Border CSS HTML ,唯一的问题是必须设置背景颜色以遮挡边框,这在您的情况下可能不相关。

关于html - 创建一个内部有文字的边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51835206/

相关文章:

javascript - 使用 react Hook 更改点击时的文本颜色

html - 为什么这个 flex table 适用于 chrome,但不适用于 IE 11?

javascript - 向符号添加类使符号出现在下一行

javascript - HTML 选项卡未显示在网络表单中 (ASP.NET)

css - 了解这些列表选择器的差异

jquery - nivo slider - 向 slider 添加文本

html - 所列元素的元素符号点未对齐

html - 在 CSS 中创建图形

html - 处理多个后代选择器的最有效方法?

html - 在 CSS 中模拟选项卡