中心div与位置绝对?

时间:2015-05-15 00:50:53

标签: css

我想知道如何把这个div放在中心。

https://jsfiddle.net/eLjy45zq/

我尝试添加自动保证金,但它不会将其置于屏幕上。我也希望它能够快速响应。我不想添加固定宽度,因为我希望边框顶部/底部线与单词的长度相匹配。另外,有没有办法让顶线和底线加倍?

   .name {
  font-family: 'PT Sans', sans-serif;
  font-size: 80px;
  border-top: 1px solid black;
  border-bottom: 1px solid black;
  position: absolute;
  margin-left: auto;
  margin-right: auto;
}

2 个答案:

答案 0 :(得分:4)

2015-05-06 04:07:37.386 [INFO]Process:102 - Application submitted Successfully ==== 1
<APPLICATION><FirstName>***</FirstName><StudentSSN>***</StudentSSN><Address>*******</Address><ParentSSN>*********</ParentSSN>   <APPLICATIONID>2</APPLICATIONID></APPLICATION>
2015-05-06 04:07:39.386 [INFO] Process:103 - Application completed Successfully ==== 1
2015-05-06 04:07:37.386 [INFO]Process:104 - Application submitted Successfully ==== 1
<APPLICATION><FirstName>***</FirstName><StudentSSN>*********</StudentSSN><Address>*****</Address><ParentSSN>*********</ParentSSN>   <APPLICATIONID>2</APPLICATIONID></APPLICATION>
2015-05-06 04:07:39.386 [INFO] Process:105 - Application completed Successfully ==== 1

https://jsfiddle.net/eLjy45zq/2/

创建一个包装器并使用.wrapper { position: fixed; top: 30px; left: 0px; width: 100%; text-align: center; } .name { font-family: 'PT Sans', sans-serif; font-size: 80px; border-top: 1px solid black; border-bottom: 1px solid black; display: inline-block; } 来使线条按您希望的方式工作。

(添加位置:固定到包装器,根据需要更改)

答案 1 :(得分:-1)

这里你使用position:fixed;就像在你的例子和&amp;也适用于position:absolute;

使用这些元素并居中时,您可以使用left:0px;right:0px;并设置margin:0;

fiddle

&#13;
&#13;
.name {
  font-family: 'PT Sans', sans-serif;
  font-size: 80px;
  border-top: 1px solid black;
  border-bottom: 1px solid black;
  position: fixed;
  margin: 0 auto;
  left: 0px;
  right: 0px;
  width: 500px;
  text-align: center;
}
&#13;
<div class="name">Lorem Ipsum</div>
&#13;
&#13;
&#13;