[英]How do i vertically align the text in the center of jumbotron?
I'm trying to vertically align the text in the center of my jumbotron but the code i previously used which involved absolute positioning and 50% from top and bottom doesn't seem to work for this 我正在尝试将文本垂直对齐到巨型机的中心,但是我之前使用的涉及绝对定位和上下上下50%的代码似乎对此不起作用
Here is my html 这是我的html
<div class="jumbotron">
<div class="container">
<h1 class="text-center"><span class="first">UZER</span><span class="last">JAMAL</span></h1>
<p class="text-center" id="respon">Responsive web designer</p>
<p class="text-center" id="langs">HTML - CSS - BOOTSTRAP - JQUERY</p>
</container>
</div>
and CSS 和CSS
.jumbotron{
height:100vh;
background:url('./Images/Jumbo.jpg') no-repeat center;
-webkit-background-size: cover;
-moz-background-size:cover;
-o-background-size:cover;
background-size:cover;
width:100%;
position:absolute;
top:0;
z-index:-100;
}
h1{
margin-bottom: -0.7em;
}
h1 .first{
color:white;
font-family:secretcode;
font-size:2em;
}
h1 .last{
color: #bd902e;
font-family:aku;
font-size:1.7em;
}
.jumbotron #respon{
font-family:geosans;
color:white;
font-size:4em;
margin-bottom:-0.2em;
}
.jumbotron #langs{
font-family:geosans;
color:#bd902e;
font-size:2em;
}
Also is there a way to bring the h1 and p vertically closer to each other without using negative margin? 还有没有办法使h1和p在垂直方向上彼此更靠近而不使用负余量? I don't think using -0.7em is the right way to do it
我不认为使用-0.7em是正确的方法
Code Jsfiddle.net 代码Jsfiddle.net
Try This 尝试这个
.jumbotron{
height:100vh;
background:url('./Images/Jumbo.jpg') no-repeat center;
-webkit-background-size: cover;
-moz-background-size:cover;
-o-background-size:cover;
background-size:cover;
width:100%;
position:absolute;
top:0;
z-index:-100;
display:flex;
display-direction:column;
justify-content:center;
align-items:center;
}
You can do it with top:50%
and transform: translate(-50%, 0)
css property 您可以使用
top:50%
进行transform: translate(-50%, 0)
css属性
.jumbotron {
height: 100vh;
background: url('./Images/Jumbo.jpg') no-repeat center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
width: 100%;
position: absolute;
top: 50%;
transform: translate(-50%, 0);
z-index: -100;
}
Example : https://jsfiddle.net/zhuv5ukb/1/ 范例: https : //jsfiddle.net/zhuv5ukb/1/
line-height:0
是我想要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.