我试图使用图像上的绝对位置和父亲的位置相对移动父div内部的图像但是当我这样做时它将它推到父div之外。下面是html / css
<div class="work">
<h2 class='workHeader'>work</h2>
<div class="container">
<div class="aboutProject">
<h3 class="projectTitle">Peak Choice</h3>
<p class="projectDescription">
Peak Choice provides real-time data to make choosing where your next Colorado Ski trip easier.
</p>
</div>
<div class="projectImageSection">
<img class='peakChoiceImage' src="/img/peakchoicemockup.png">
</div>
</div>
</div>
.work {
/*position: absolute;*/
text-align: center;
width: 100%;
}
.workHeader {
margin-top: 1rem;
margin-bottom: 2rem;
}
.container {
display: grid;
grid-gap: 3px;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(auto);
grid-template-areas:
"c i"
"c i";
}
.projectImageSection {
/*background-color:#ABECF0;*/
position: relative;
/*overflow: hidden;*/
}
.peakChoiceImage {
position: absolute;
height: auto;
width: 25rem;
}
text-align: center
正在应用于.projectImageSection
在left: 0;
上设置.peakChoiceImage
以移动到相对定位父级左侧的图像。