gpt4 book ai didi

css div 将多行文本垂直和水平居中并带有背景图像

转载 作者:行者123 更新时间:2023-11-28 04:49:54 24 4
gpt4 key购买 nike

我搜索了 Stackoverflow,但找不到有效的解决方案。

似乎很难在 div 中垂直和水平居中。

我正在使用这个 CSS:

.title {
font-family: "Book Antiqua", "Palatino Linotype", Palatino, serif;
font-size: 400%;
}

.subtitle {
font-family: "Book Antiqua", "Palatino Linotype", Palatino, serif;
font-size: 150%;
}

.subnote {
font-family: "Book Antiqua", "Palatino Linotype", Palatino, serif;
font-size: 75%;
}

.outer {
display: table;
position: absolute;
height: 100%;
width: 100%;
}

.middle {
display: table-cell;
vertical-align: middle;
}

.innie {
width: 1000px;
height: 515px;
background-image: url("bkgrnd3.png");
position:absolute;
left:50%;
top:50%;
margin: -257px 0 0 -500px;
text-align: center;
}

和这个 html:

<!DOCTYPE html>
<html>
<head>
<title>Timothy Eldon Official</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="eldon.css">
</head>
<body>
<div class="outer">
<div class="middle">
<div class="innie">
<span class="title">
Timothy Eldon
</span>
<br/>
<span class="subtitle">
Author
</span>
<br/>
<span class="subnote">
(amateur)
</span>
</div>
</div>
</div>
</body>
</html>

它使页面上的所有内容相对居中,但我无法使文本垂直居中。

似乎有很多想法,但我尝试了几种,但没有任何效果。

最佳答案

这里很简单 DEMO .. 希望对您有所帮助。

HTML

<div>
<span>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</span>
</div>

CSS

div {
display: table;
width: 250px;
height: 500px;
text-align: center;
border: 1px solid red;
}

span {
display: table-cell;
vertical-align: middle;

}

关于css div 将多行文本垂直和水平居中并带有背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34912619/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com