为什么将child定位为其相关父级的绝对值将其推送到父div之外?

问题描述 投票:0回答:1

我试图使用图像上的绝对位置和父亲的位置相对移动父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;
}
html css css-grid
1个回答
0
投票

text-align: center正在应用于.projectImageSection

left: 0;上设置.peakChoiceImage以移动到相对定位父级左侧的图像。

© www.soinside.com 2019 - 2024. All rights reserved.