如何在像图像中的边框中包装H2和<p>标记:

时间:2018-05-31 05:01:15

标签: css border

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

enter image description here

1 个答案:

答案 0 :(得分:1)

你可以尝试下面的代码。

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