css - 如何像图像 : 那样在边框中包裹 H2 和 <p> 标签

标签 css border

<分区>

有没有一种简单的方法可以在 h2 和 p 标签上使用 css 实现与此图像相同的设计?

enter image description here

最佳答案

你可以试试下面的代码。

.box {
  margin-top : 50px; 
  border : 1px solid #000; 
  padding : 15px;
  width : 500px; 
  margin-left : auto; 
  margin-right : auto; 
  position : relative;
}

.title {
  position: absolute; 
  top: -20px; 
  font-size: 24px; 
  background: #fff; 
  padding: 3px 0; 
  width: 300px; 
  text-align: center; 
  left: calc(50% - 150px);
}
<html>
<head>
</head>
<body>
<div class="box">
	<div class="title">&lt;h2&gt;Sample Text&lt;/h2&gt;</div>
	<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</body>

关于css - 如何像图像 : 那样在边框中包裹 H2 和 <p> 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50616934/

上一篇:css - 渲染阻塞和 CSS

下一篇:css - 更改 ionic 2中警报 Controller 的样式和文本修改

相关文章:

javascript - 如何用 javascript 调整这个 css 对象?

html - 如何通过绝对定位在其父元素之后但在其祖父元素之前获得伪元素?

html - 如果有空间,如何将div垂直 float 到下一个

CSS - 像这样制作边框的最佳方式(以网站链接为例)

javascript - 如何逻辑划分TD cell

html - CSS - 溢出滚动不起作用

reporting-services - 如何在 SSRS 中删除表格边框

java - 在 Java 中的 JList 中设置边框

javascript - 使用javascript更改文本框边框颜色

jquery - 使用CSS边框在div之间画线