html - 我如何将 <hr> 标签移动到中心

标签 html css

我试过移动 <hr> tag to center ,它移动​​到中心但右方向不在中心。

Preview Image

/* start set fonts */

* {
  font-family: 'Montserrat', sans-serif;
  margin: 0;
  padding: 0;
}


/* start general page */

html body {
  background-color: #181333;
}


/* start container */

.container {
  width: 100%;
  background-color: #1e1939;
  position: absolute;
  top: 50%;
}


/* start title */

.title {
  display: block;
  margin: 5px;
  padding: 5px;
  color: #fefefe;
  text-align: center;
  letter-spacing: 15px;
}


/* start main line */

.main_line {
  display: block;
  width: 5%;
  position: absolute;
  left: 50%;
}
<div class="container">
  <h1 class="title">OUR TEAM</h1>
  <hr class="main_line"> </div>

有什么问题吗? , 提前致谢......................................................

最佳答案

只需使用 margin:auto 而不是 position:absolute。它快乐地生活在容器中:

.main_line {
  display: block;
  width: 5%;
  margin:auto
}

/* start set fonts */

* {
  font-family: 'Montserrat', sans-serif;
  margin: 0;
  padding: 0;
}


/* start general page */

html body {
  background-color: #181333;
}


/* start container */

.container {
  width: 100%;
  background-color: #1e1939;
  position: absolute;
  top: 50%;
}


/* start title */

.title {
  display: block;
  margin: 5px;
  padding: 5px;
  color: #fefefe;
  text-align: center;
  letter-spacing: 15px;
}


/* start main line */

.main_line {
  display: block;
  width: 5%;
  margin:auto
}
<div class="container">
  <h1 class="title">OUR TEAM</h1>
  <hr class="main_line"> 
</div>

关于html - 我如何将 <hr> 标签移动到中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55359891/

相关文章:

CSS - 当滚动到达底部时,滚动被后面的 div 消耗

css - 如何在CSS中实现material design motion

css - div 在调整大小时改变位置

javascript - 应用 JavaScript 脚本的更好方法

html - 在CSS中,真的需要 "table"中的 "table td { ... }"吗? "td"不能出现在表中吗?

html - 占位符中的字体和文本都很棒

javascript - 从不同的 javascript 文件中获取 localStorage 变量的值

javascript - 如何在函数后添加循环?

css - 无法覆盖用户代理设置的按钮样式

php - 不寻常的链接创建问题