gpt4 book ai didi

html - 为什么我的 div 在页面内部垂直居中而不是它的父 div?

转载 作者:太空宇宙 更新时间:2023-11-03 21:26:10 24 4
gpt4 key购买 nike

我试图让我所有的页面内容在我的网站上垂直居中。目前正在浏览平板电脑/手机版本,文本的下半部分有很多空白区域,所以我希望所有内容都垂直居中。我遇到的问题是,当我使用转换“技巧”(它在我关于 .about-content 的媒体查询代码中)时,它排在页面中间而不是父 div,.about-right。

我在这里做错了什么?更适用的 CSS 位于工作表底部附近的媒体查询中。

我正在尝试解决的问题(图片)- http://i988.photobucket.com/albums/af6/jtbitt/ipad-text_zpss35j9ty4.png

这是我使用变换技巧时发生的情况(图片)- http://i988.photobucket.com/albums/af6/jtbitt/ipad-text-middle-page_zps1srfn7bq.png

HTML -

<section id="about" ng-controller="aboutController">    
<div class="container-fluid">

<div class="row about-row">

<div class="about-left col-xs-12 col-md-6">
</div>

<div class="about-right col-xs-12 col-md-6">
<div class="about-content">
<div class="about-content-title">
<h1><strong>I'M JAY.</strong></h1>
</div>

<div class="about-content-info">
<p ng-if="about.firstParagraph">An entrepenurial minded, Full Stack Developer. Whenever I'm up against a challenge that I care about, it gives me a rush. Focusing on the big picture is important to me, but I never forget the smaller details. Anything that is not challenging is boring, and makes me yawn. Anything that is seemingly impossible interests me a lot. I'm read to get to work.</p>

<p ng-if="!about.firstParagraph">Currently seeking a Javascript position, using the MEAN stack, in New York City. Being innovative, ambitious, and hard working are values that are very important to me. I want to join a company that has similar values and has goals of reaching ridiculous levels of success, not just modest realistic ones. I love working with a solid team.</p>
</div>

<div class="about-button">
<button ng-if="about.firstParagraph" class="label label-success" ng-click="about.switchParagraph()">MORE =></button>
<button ng-if="!about.firstParagraph" class="label label-success"><a href="/portfolio">VIEW SKILLS</a></button>
</div>

<div class="about-personal-info">
<h4>Email: jaybittner@gmail.com</h4>
</div>

<div class="about-icon">
<a href="{{ profile.url }}" ng-repeat="profile in about.profiles"><img ng-src="{{ profile.icon }}" /></a>
</div>
</div>

</div>

</div>

</div>
</section>

CSS -

#about {
height: 100%;
width: 100%;
background: rgba(0,97,65,1);
background: -moz-linear-gradient(left, rgba(0,97,65,1) 0%, rgba(54,135,95,1) 7%, rgba(36,123,85,1) 22%, rgba(0,97,65,1) 53%, rgba(34,121,84,1) 76%, rgba(54,135,95,1) 90%, rgba(54,135,95,1) 100%);
background: -webkit-gradient(left top, right top, color-stop(0%, rgba(0,97,65,1)), color-stop(7%, rgba(54,135,95,1)), color-stop(22%, rgba(36,123,85,1)), color-stop(53%, rgba(0,97,65,1)), color-stop(76%, rgba(34,121,84,1)), color-stop(90%, rgba(54,135,95,1)), color-stop(100%, rgba(54,135,95,1)));
background: -webkit-linear-gradient(left, rgba(0,97,65,1) 0%, rgba(54,135,95,1) 7%, rgba(36,123,85,1) 22%, rgba(0,97,65,1) 53%, rgba(34,121,84,1) 76%, rgba(54,135,95,1) 90%, rgba(54,135,95,1) 100%);
background: -o-linear-gradient(left, rgba(0,97,65,1) 0%, rgba(54,135,95,1) 7%, rgba(36,123,85,1) 22%, rgba(0,97,65,1) 53%, rgba(34,121,84,1) 76%, rgba(54,135,95,1) 90%, rgba(54,135,95,1) 100%);
background: -ms-linear-gradient(left, rgba(0,97,65,1) 0%, rgba(54,135,95,1) 7%, rgba(36,123,85,1) 22%, rgba(0,97,65,1) 53%, rgba(34,121,84,1) 76%, rgba(54,135,95,1) 90%, rgba(54,135,95,1) 100%);
background: linear-gradient(to right, rgba(0,97,65,1) 0%, rgba(54,135,95,1) 7%, rgba(36,123,85,1) 22%, rgba(0,97,65,1) 53%, rgba(34,121,84,1) 76%, rgba(54,135,95,1) 90%, rgba(54,135,95,1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#006141', endColorstr='#36875f', GradientType=1 );
background-repeat: no-repeat;
color: #101010;
border-bottom: 3px solid black;
}

#about .container-fluid, #about .row {
height: 100%;
}

.about-left {
height: 100%;
background-image: url('../../images/jay-ocean.jpg');
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
border-right: 3px solid #101010;
}

.about-right {
padding-top: 24vh;
text-align: center;
}

.about-content {
width: 50%;
margin-left: auto;
margin-right: auto;
}

.about-content-title h1{
font-size: 3.1vw;
margin-bottom: 0.6vh;
}

.about-content-info p {
font-size: 1vw;
word-spacing: 0.3vw;
margin-bottom: 0.7vh;
}

.about-button button {
margin-bottom: -0.1vh;
}

.about-personal-info h4 {
margin-bottom: 0.7vh;
}

.about-button button {
color: gray;
border: 1px solid #101010;
background-color: #101010;
font-size: 0.7vw;
}

.about-button a {
color: gray;
}

.about-personal-info h4 {
font-size: 1vw;
word-spacing: 0.3vw;
}

.about-icon img {
height: 3.5vh;
width: 1.75vw;
border-radius: 10px;
border: 1px solid #101010;
margin: 3px;
}

@media only screen and (max-width: 992px) {
.about-left {
height: 50%;
border-bottom: 3px solid black;
}

.about-right {
padding-top: 0;
}

.about-content {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 70%;
}

.about-content-title h1 {
font-size: 5vw;
}

.about-content-info p {
font-size: 2.5vw;
}

.about-button button {
font-size: 2.5vw;
}

.about-personal-info h4 {
font-size: 2.5vw;
}

.about-icon img {
height: 3vh;
width: 3vw;
}
}

最佳答案

问题是您正在为您的 .about-content 类使用 position:fixed。这会使您的内容相对于浏览器窗口对齐,而不是相对于它的父窗口。因此,如果您的页面可以滚动,那么该文本将固定在浏览器屏幕的中间。

要解决此问题,请将您的 .about-content 类改为使用 position: absolute。并且您还需要在父元素上设置 position: relative,因为 position:absolute 元素会相对于它自己定位最近定位的祖先。

参见 https://developer.mozilla.org/en-US/docs/Web/CSS/position?redirectlocale=en-US&redirectslug=CSS%2Fposition用于描述各种位置值。

关于html - 为什么我的 div 在页面内部垂直居中而不是它的父 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32576300/

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