我正在尝试将一个div放置在页面的中间,将另一个div放置在页面的末尾。
我知道了,但是我无法将第一个放在中间。
我尝试为content_text设置不同的自我诊断能力,但我尝试过的所有方法都没有。
希望你们能帮助我。 :)
html,body{
height:100%;
margin:0;
}
.content {
align-items: center;
background: rgb(0, 0, 0); /* Fallback color */
background: rgba(0, 0, 0, 0.5); /* Black background with 0.5 opacity */
color: #f1f1f1; /* Grey text */
display: flex;
flex-direction: column;
height: 100vh;
justify-content: space-between;
position: absolute; /* Position the background text */
width: 100%; /* Full width */
}
/* HELPERS */
.img-bg {
display:block;
height:100%;
object-fit: cover;
width:100%;
}
<!doctype html>
<html class="no-js" lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Iraitz Puente</title>
</head>
<body>
<div class="row fullWidth">
<div class="content">
<div class="content_text">
<h1>THIS MUST BE CENTERED</h1>
</div>
<div class="content_arrow">
<h1>END</h1>
</div>
</div>
</div>
</body>
</html>
答案 0 :(得分:1)
如果将content
设置为justify-content: flex-end;
,则可以将absolute
定位应用于需要居中的元素,然后使用top: 50%
和{ {1}}:
transform: translateY(-50%);
html,body{
height:100%;
margin:0;
}
.content {
align-items: center;
background: rgb(0, 0, 0); /* Fallback color */
background: rgba(0, 0, 0, 0.5); /* Black background with 0.5 opacity */
color: #f1f1f1; /* Grey text */
display: flex;
flex-direction: column;
height: 100vh;
justify-content: flex-end;
position: absolute; /* Position the background text */
width: 100%; /* Full width */
}
.content_text {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
/* HELPERS */
.img-bg {
display:block;
height:100%;
object-fit: cover;
width:100%;
}
答案 1 :(得分:0)
只需从.content类中删除[{'individualInfo': {'entityCode': 1, 'sourceCode': 4},
'individualIdentifier': [{'identityTypeCode': 7}, {'identityTypeCode': 8}]},
{'individualInfo': {'entityCode': 3, 'sourceCode': 6},
'individualIdentifier': [{'identityTypeCode': 9}, {'identityTypeCode': 10}]}]
样式
答案 2 :(得分:0)
html,body{
height:100%;
margin:0;
}
.content {
background: rgb(0, 0, 0); /* Fallback color */
background: rgba(0, 0, 0, 0.5); /* Black background with 0.5 opacity */
color: #f1f1f1; /* Grey text */
display: flex;
flex-direction: column;
height: 100vh;
justify-content: center;
align-items: center;
width: 100%; /* Full width */
}
/* HELPERS */
.img-bg {
display:block;
height:100%;
object-fit: cover;
width:100%;
}
<!doctype html>
<html class="no-js" lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Iraitz Puente</title>
</head>
<body>
<div class="row fullWidth">
<div class="content">
<div class="content_text">
<h1>THIS MUST BE CENTERED</h1>
</div>
<div class="content_arrow">
<h1>END</h1>
</div>
</div>
</div>
</body>
</html>
答案 3 :(得分:-2)
<style>
.content {
align-items: center;
background: rgb(0, 0, 0);
background: rgba(0, 0, 0, 0.5);
color: #f1f1f1;
display: flex;
flex-direction: column;
height: 100vh;
justify-content: center;
position: absolute;
width: 100%;
}
.contact .content_text,.contact .content_arrow{
margin-top: auto;
}
</style>