html - 我如何使这个标题居中?
问题描述
我如何使这个标题居中?我已经尝试了一切,但没有任何效果。;-;
@import url(https://fonts.googleapis.com/css?family=Open+Sans:400,400italic,600,600italic,700italic);
* {
margin: 0;
padding: 0;
}
html,
body {
max-width: 100%;
overflow-x: hidden;
overflow-y: hidden;
}
body {
background: #2c3e50;
font-size: 80%;
font-family: 'Open Sans', sans-serif;
}
.bg {
z-index: -1;
width: 100%;
height: 100%;
position: absolute;
background: linear-gradient( 45deg, #f17c58, #e94584, #24aadb, #27dbb1, #ffdc18, #ff3706);
background-size: 600% 100%;
animation: gradient 16s linear infinite;
animation-direction: alternate;
}
@keyframes gradient {
0% {
background-position: 0%;
}
100% {
background-position: 100%;
}
}
main {
position: relative;
height: 240px;
margin: auto;
padding: 20px;
resize: both;
}
.btn-grp {
height: 68px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
a {
text-decoration: none;
color: #fff;
}
a:hover {
color: #2ecc71;
}
.btn {
text-align: center;
cursor: pointer;
font-size: 24px;
position: relative;
background-color: #f39c12;
border: none;
padding: 20px;
width: 200px;
-webkit-transition-duration: 0.4s;
transition-duration: 0.4s;
text-decoration: none;
overflow: hidden;
}
.btn:hover {
background: #fff;
box-shadow: 0 2px 10px 5px #97b1bf;
color: #000;
}
.btn:after {
content: '';
background: #f1c40f;
display: block;
position: absolute;
opacity: 0;
transition: all 0.8s;
}
.btn:active:after {
padding: 0;
margin: 0;
opacity: 1;
transition: 0s;
}
.down {
Position: absolute;
Bottom: 85%;
}
<html lang="en">
<head>
</head>
<body>
<div class="bg"></div>
<div class="down">
<h1>Welcome</h1>
</div>
<main>
<div class="btn-grp">
<a href="#" target="_blank">
<button class="btn" id="btn-home">Home</button>
</a>
<a href="#" target="_blank">
<button class="btn" id="btn-dl">Download</button>
</a>
</div>
</main>
</body>
</html>
解决方案
@import url(https://fonts.googleapis.com/css?family=Open+Sans:400,400italic,600,600italic,700italic);
* {
margin: 0;
padding: 0;
}
html,
body {
max-width: 100%;
overflow-x: hidden;
overflow-y: hidden;
}
body {
background: #2c3e50;
font-size: 80%;
font-family: 'Open Sans', sans-serif;
}
.bg {
z-index: -1;
width: 100%;
height: 100%;
position: absolute;
background: linear-gradient(
45deg,
#f17c58,
#e94584,
#24aadb,
#27dbb1,
#ffdc18,
#ff3706
);
background-size: 600% 100%;
animation: gradient 16s linear infinite;
animation-direction: alternate;
}
@keyframes gradient {
0% {
background-position: 0%;
}
100% {
background-position: 100%;
}
}
main {
position: relative;
height: 240px;
margin: auto;
padding: 20px;
resize: both;
}
.btn-grp {
height: 68px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
a {text-decoration: none; color: #fff;}
a:hover {color: #2ecc71;}
.btn {
text-align: center;
cursor: pointer;
font-size: 24px;
position: relative;
background-color: #f39c12;
border: none;
padding: 20px;
width: 200px;
-webkit-transition-duration: 0.4s;
transition-duration: 0.4s;
text-decoration: none;
overflow: hidden;
}
.btn:hover {
background: #fff;
box-shadow: 0 2px 10px 5px #97b1bf;
color: #000;
}
.btn:after {
content: '';
background: #f1c40f;
display: block;
position: absolute;
opacity: 0;
transition: all 0.8s;
}
.btn:active:after {
padding: 0;
margin: 0;
opacity: 1;
transition: 0s;
}
.down {
Position: absolute;
Bottom: 85%;
width: 100%;
text-align: center;
}
<html lang="en">
<head>
</head>
<body>
<div class="bg"></div>
<div class="down">
<h1>Welcome</h1>
</div>
<main>
<div class="btn-grp">
<a href="#" target="_blank">
<button class="btn" id="btn-home">Home</button>
</a>
<a href="#" target="_blank">
<button class="btn" id="btn-dl">Download</button>
</a>
</div>
</main>
</body>
</html>
只为 .down 类更改了 css,如下所示:
.down {
Position: absolute;
Bottom: 85%;
width: 100%;
text-align: center;
}
推荐阅读
- node.js - 可以在本地连接到 mongodb atlas,但不能在实时服务器上连接
- python - wxpython - 垂直拆分水平 BoxSizer
- r - 如何在purrr中获得最接近参考词的词
- jquery - jQuery - 试图理解“成功错误”和“完成失败”之间的区别
- java - 如何从 application.yml 文件中注入属性?
- c# - 绑定导致传递给 Rect.ctor 的负值
- java - 在 Android Studio 中导入模块后出错
- reactjs - 如何修复 redux-observable 参数'action$'隐式具有'any'类型
- r - 如何将多个输入(旋钮)添加到单个滑块?
- python - 评估步骤的权重衰减 - Tensorflow