简体   繁体   English

如何对齐多个 <h1> 标签

[英]how to align multiple <h1> tags

I wanted to make a header with a title in the center "Resources", left another title "HTML" and right another with "CSS" but I can not align them to put them in the right place and then add a border-right and border-left to separate the left and right title from the title to the center. 我想在标题“ Resources”的中间制作一个标题,另一个标题为“ HTML”,另一个标题为“ CSS”,但是我无法对齐它们以将其放置在正确的位置,然后添加右边框和border-left将左右标题从标题到中心分开。

For the moment I have this: 目前我有这个:

 header { border: 2px solid white; border-radius: 20px; background-color: rgba(0, 0, 0, 0.2); color: white; } h1 { display: inline-block; font-size: 30px; font-family: Arial, sans-serif; } h1.html { padding-left: 2%; } h1.res {} h1.css { padding-right: 2%; } 
 <header> <h1 class="html">HTML</h1> <h1 class="res">Ressources</h1> <h1 class="css">CSS</h1> </header> 

Because of the display: inline-block; 由于显示:inline-block; it works better but I do not know how to do it. 它效果更好,但我不知道该怎么做。

It would be simpler to replace the <h1> tags with <span> elements because they are inline by default. <span>元素替换<h1>标记会更简单,因为默认情况下它们是inline的。 The left and right separation can be accomplished several ways. 左右分离可以通过几种方式完成。 See example below. 请参见下面的示例。

 .header { text-align: center; border-radius: 20px; background-color: rgba(0,0,0,0.2); color:white; font-family: Arial, Helvetica, sans-serif; font-weight: bolder; font-size: 24px; } .header span:nth-child(1) { float: left; width: 33%; border-right: 2px solid white; } .header span:nth-child(3) { float: right; width: 33%; border-left: 2px solid white; } 
 <div class='header'> <span>HTML</span> <span>RESOURCES</span> <span>CSS</span> </div> 

You can use a flex layout to position the headings. 您可以使用弹性布局来放置标题。 Add this to your existing header ruleset: 将此添加到现有的header规则集中:

header {
  display: flex;
  justify-content: space-between;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM