gpt4 book ai didi

html - 为什么我的文字没有居中对齐?

转载 作者:太空宇宙 更新时间:2023-11-04 11:01:08 25 4
gpt4 key购买 nike

我的文本没有对齐到它应该在的中心,显然你可以添加边距或填充或任何你喜欢的,但从长远来看,这并不能解决问题,特别是如果没有人知道标题是什么那里。

fiddle :http://jsfiddle.net/385zLos5/

HTML:

<!DOCTYPE html>

<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Raleway:100,200,300,400,500,600,700,800,900">
</head>
<body>
<main>
<div class="hover">
<div class="description">
<h3>Title</h3>
<a>This is a long description, I don't know what to write here.</a>
</div>
<img src="https://images.unsplash.com/photo-1445127040028-b1bdb9acd16e?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=5f10c1c850239222d20e96ae1b8b5862">
</div>
</main>
</body>

CSS:

* {
font-family: "Raleway", Century Gothic;
}

body {
margin: 0px;
width: 100%;
}

.hover {
width: 33.333333333333%;
float: left;
overflow: hidden;
}

.hover > .description {
text-align: center;
position: absolute;
}

.hover > img {
width: 105%;
filter: blur(5px);
transition: 0.3s ease;
margin: -5px -10px -10px -5px;
}

.hover:hover > img {
filter: blur(0px);
transition: 0.3s ease;
}

.hover > .description > h3,
.hover > .description > h3:after {
position: absolute;
color: #fff;
z-index: 3;
transition: 0.3s ease;

}

.hover:hover > .description > h3 {
transition: 0.3s ease;

}

.hover > .description > a,
.hover > .description > a:after {
position: absolute;
color: #fff;
z-index: 3;
transition: 0.3s ease;

}

.hover:hover > .description > a {
transition: 0.3s ease;

}

最佳答案

首先你需要在父级上设置position: relative;然后在absolute定位子级上设置width: 100%

* {
font-family: "Raleway", Century Gothic;
}

body {
margin: 0px;
width: 100%;
}

.hover {
width: 33.333333333333%;
float: left;
overflow: hidden;
position: relative;
}

.hover > .description {
text-align: center;
position: absolute;
width: 100%;
color: white;
z-index: 5;
}

.hover > img {
width: 105%;
filter: blur(5px);
transition: 0.3s ease;
margin: -5px -10px -10px -5px;
}

.hover:hover > img {
filter: blur(0px);
transition: 0.3s ease;
}

.hover:hover > .description > h3 {
transition: 0.3s ease;
}

.hover:hover > .description > a {
transition: 0.3s ease;
}
<main>
<div class="hover">
<div class="description">
<h3>Title</h3>
<a>This is a long description, I don't know what to write here.</a>
</div>
<img src="http://placehold.it/350x300/000000/ffffff">
</div>
</main>

关于html - 为什么我的文字没有居中对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34295954/

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