html - 标题居中但副标题居中 "right"

标签 html css

我需要将标题居中,在下一行中,我必须写一个在标题右侧结束的副标题。示例:

                     Here is my title
                             subtitle

有人可以帮我吗?

最佳答案

您可以通过使用自定义数据属性和伪元素或使用简单的 css 来解决这个问题,这完全取决于您。 解决方案如下:

.page-title {
	text-align: center;
}
h1 {
	display: inline-block;
	position: relative;
}
h1:after {
	content: attr(data-subtitle);
	position: absolute;
	top: 100%;
	right: 0px;
}
.another h1 {
	margin-bottom: 40px;
}
.another span {
	position: absolute;
	top: 100%;
	right: 0px;
}
<div class="page-title">
	<h1 data-subtitle="subtitle">Here is my title</h1>
</div>
<div class="page-title another">
	<h1>Here is my title <span>subtitle</span></h1>
</div>

关于html - 标题居中但副标题居中 "right",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44903874/

相关文章:

javascript - html5gallery 在 Firefox 中不工作

javascript - 如何删除订单列表中的上下空格

javascript - 无法单击我的 'content' div 中的元素

firefox - Firefox/Opera 是否处理定位/多个背景图像?

html - 如何在 Body 标签内使用 CSS 强制将 html 内容包装为固定宽度?

css - 如何倾斜一个 div 并确保宽度始终为 50%?

html - html5 float 内容不起作用

php - 如何在 SQL 数据库中基于来自 php 的两个参数进行过滤

html - 如何选择两个一组的元素并应用公共(public)边框?

Javascript 从样式中删除特定属性