gpt4 book ai didi

html - 中心对齐文本

转载 作者:行者123 更新时间:2023-11-28 02:35:45 25 4
gpt4 key购买 nike

此页面的主要 h1p 标签拒绝居中。我是一个新手,正在学习,这可能是我忽略的简单事情;但是我不能把我的手指放在上面!

我已经尝试了多种方法来将这个(.content.header,甚至 *)都设置为 text -align: center; 但没有任何效果。甚至 *!所以必须有什么东西“阻止”这个?

提前感谢您提供的任何提示!

*{
box-sizing: border-box;
text-align: center;
}

body {
margin: 0;
font-family: sans-serif;
font-size: 20px;
line-height: 1.5;
color: #333;
overflow-x: hidden;
}

.v-header{
height: 100vh;
display: flex;
align-items: center;
color: #fff;
}

.container {
max-width: 960px;
padding-left: 1rem;
padding-right: 1rem;
margin: auto;
text-align: center;
}

.video-wrap {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100vh;
overflow: hidden;
}

.video-wrap video {
min-width: 100%;
min-height: 100%;
}

.overlay {
height: 100%;
width: 100%;
position: absolute;
top: 0;
left: 0;
background: #225470;
z-index: 1;
opacity: 0.55;
}

.content {
z-index: 2;
}

.content h1 {
font-size: 50px;
margin-bottom: 0px;
}

.content p {
font-size: 25px;
display: block;
padding-bottom: 20px;
}

.btn {
background: #34b3a0;
color: #fff;
font-size: 15px;
padding: 15px 20px;
text-decoration: none;
}

.section {
padding: 20px 0px;
}

.section-b {
background: #34b3a0;
color: #fff;
}

@media(max-width: 960px) {
.container {
padding-right: 30px;
padding-left: 30px;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>

<body>
<!-- Container section will contain the entire landing page -->
<header class= "v-header container">
<!-- Video-Wrap section will contain the video -->
<div class= "video-wrap">
<video src="images/media2.mp4" autoplay="true" loop="true"></video>
</div>
<!-- Overlay section will be over the video, styled with CSS -->
<div class= "overlay"> </div>
<!-- Content will contain the actual content on the landing page with links to other pages -->
<div class="content">
<h1>Coffee R Us</h1>
<p>If you like coffee, you'll love us!</p>
<a href="#" class= "btn">About us</a>
<a href="#" class= "btn">Our Menu</a>
</div>

</header>

<!-- Sections will appear BELOW the wrapper video -->
<section class="section-a">
<div>
<h1>Section A - Thing 1</h1>
<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint laborum veniam quae non nesciunt enim deleniti soluta molestias molestiae dolorem.</p>
</div>
</section>

<section class="section-b">
<div>
<h1>Section B - Thing 1</h1>
<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint laborum veniam quae non nesciunt enim deleniti soluta molestias molestiae dolorem.</p>
</div>
</section>

</body>

</html>

最佳答案

margin: 0 auto; 添加到 .content 以使其居中 - 这是所有这些文本被包裹的元素,它不会跨越整个窗口宽度,所以你必须将它居中。

*{
box-sizing: border-box;
text-align: center;
}

body {
margin: 0;
font-family: sans-serif;
font-size: 20px;
line-height: 1.5;
color: #333;
overflow-x: hidden;
}

.v-header{
height: 100vh;
display: flex;
align-items: center;
color: #fff;
}

.container {
max-width: 960px;
padding-left: 1rem;
padding-right: 1rem;
margin: auto;
text-align: center;
}

.video-wrap {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100vh;
overflow: hidden;
}

.video-wrap video {
min-width: 100%;
min-height: 100%;
}

.overlay {
height: 100%;
width: 100%;
position: absolute;
top: 0;
left: 0;
background: #225470;
z-index: 1;
opacity: 0.55;
}

.content {
z-index: 2;
margin: 0 auto;
}

.content h1 {
font-size: 50px;
margin-bottom: 0px;
}

.content p {
font-size: 25px;
display: block;
padding-bottom: 20px;
}

.btn {
background: #34b3a0;
color: #fff;
font-size: 15px;
padding: 15px 20px;
text-decoration: none;
}

.section {
padding: 20px 0px;
}

.section-b {
background: #34b3a0;
color: #fff;
}

@media(max-width: 960px) {
.container {
padding-right: 30px;
padding-left: 30px;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>

<body>
<!-- Container section will contain the entire landing page -->
<header class= "v-header container">
<!-- Video-Wrap section will contain the video -->
<div class= "video-wrap">
<video src="images/media2.mp4" autoplay="true" loop="true"></video>
</div>
<!-- Overlay section will be over the video, styled with CSS -->
<div class= "overlay"> </div>
<!-- Content will contain the actual content on the landing page with links to other pages -->
<div class="content">
<h1>Coffee R Us</h1>
<p>If you like coffee, you'll love us!</p>
<a href="#" class= "btn">About us</a>
<a href="#" class= "btn">Our Menu</a>
</div>

</header>

<!-- Sections will appear BELOW the wrapper video -->
<section class="section-a">
<div>
<h1>Section A - Thing 1</h1>
<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint laborum veniam quae non nesciunt enim deleniti soluta molestias molestiae dolorem.</p>
</div>
</section>

<section class="section-b">
<div>
<h1>Section B - Thing 1</h1>
<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint laborum veniam quae non nesciunt enim deleniti soluta molestias molestiae dolorem.</p>
</div>
</section>

</body>

</html>

关于html - 中心对齐文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47424115/

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