首页 > 解决方案 > HTML div 不会转到父 div 的底部

问题描述

我有个问题。我有一个 HTML 页面,我在其中显示图像和细节作为图像的覆盖。为此,我有以下代码:

.grid-pagina {
    width: 80%;
    margin: auto auto;
    display: grid;
    grid-template-columns: 45% auto;
    column-gap: 20px;
    padding-top: 30px;
}

.leftside {
    width: 100%;
    height: 90%;
    text-align: left;
}

.rightside {
    width: 50%;
    height: 90%;
    font-family: 'Roboto', sans-serif;
}

.country {
    top: 25px;
    right: 25px;
    position: absolute;

}

.country img {
    border-radius: 32px;
    height: 64px;
    width: 64px;
}


.title {
    font-size: 35px;
    margin-bottom: 10px;
    font-family: 'Roboto', sans-serif;
    color: red;
}

.image-container {
    position: relative;
    width: 100%;
    display: inline-block;
    background-color: blue;
}

.coverimage {
    border-radius: 30px;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
  min-width: 100%;
  min-height: 100%;
}

.activity-container {
    position: absolute;
    top: 0;
}

.activity {
    display: flex;
    align-content: center;
    justify-content: center;
    color: red;
    font-size: 20px;
}

.activity img {
    height: 50px;
}

.activity span {
    padding-left: 10px;
    margin: auto auto;
}



.user-info {
    position: absolute;
    bottom: 0;
    left: 0;
    background-color:red;
    vertical-align: bottom
}

.user-info .user-name {
    font-size: 30px;
    padding: 10px;
    font-weight: bold;
    color: white;
}

.user-info .user-details {
    font-size: 20px;
    padding: 10px;
    color: white;
}


.smalltitle {
    font-size: 25px;
    margin-top: 30px;
    color: red;
}

.hobbysmall img {
    height: 20px;
}

.hobbysmall {
    padding-right: 40px;
    display: inline-block;
}

.taalicon {
    height: 50px;
    width: 75px;
    padding-left: 15px;
    display: inline-block;
    margin-top: 30px;
}

.taalicon img {
    height: 100%;
    width: 100%;
}

.talen {
    display: inline-flex;
}

.bio p {
    width: 450px;
    overflow: hidden;
    height: 200px;
    line-height: 20px;
    word-wrap: break-word;
    padding-top: 20px;
}

.declinebutton {
    position: relative;
    margin-left: 15%;
}

.acceptbutton {
    margin-top: -20px;
    position: relative;
    margin-left: 5%;
}

.interesses {
    margin-top: 20px;
}

.bigbutton img {
    height: 100px;
    padding-top: 70px;
}
<div class="grid-pagina">
  <div class="leftside">
    <div class="title">
      Noorwegen
    </div>
    <div class="image-container">
      <img src="https://static.rondreis.nl/rondreis-storage-production/bezienswaardigheden-69-rome-jpg/1024x686/cover/eyJidWNrZXQiOiJyb25kcmVpcy1zdG9yYWdlLXByb2R1Y3Rpb24iLCJrZXkiOiJiZXppZW5zd2FhcmRpZ2hlZGVuXC82OVwvcm9tZS5qcGciLCJlZGl0cyI6eyJyZXNpemUiOnsid2lkdGgiOjEwMjQsImhlaWdodCI6Njg2LCJmaXQiOiJjb3ZlciJ9fX0=" class="coverimage"/>
      <div class="activity-container">
        <div class="activity">
          <img src="img/page/match_profiel/sun.png"> <span>Zonnig</span>
        </div>
        <div class="activity">
          <img src="img/page/match_profiel/icon_boat_red.png"> <span>Zonnig</span>
        </div>
        <div class="activity">
          <img src="img/page/match_profiel/icon_climb.png"> <span>Zonnig</span>
        </div>
      </div>

      <div class="country">
        <img src="img/flag/dutch.png">
      </div>

      <div class="user-info">
        <div class="user-name">
          Tim, 26 jaar
        </div>
        <div class="user-details">
          Man, 2000-3000
        </div>
      </div>
    </div>
  </div>
  <div class="rightside">
    <div class="smalltitle">
      Interesses
    </div>
    <div class="interesses">
      <div class="hobbysmall">
        <img src="img/page/match_profiel/icon_tag.png"> Boten
      </div>
      <div class="hobbysmall">
        <img src="img/page/match_profiel/icon_tag.png"> Boten
      </div>
      <div class="hobbysmall">
        <img src="img/page/match_profiel/icon_tag.png"> Boten
      </div>
    </div>
    <div class="talen">
      <div class="smalltitle">Taal(en)</div>
      <div class="taalicon">
        <img src="img/flag/dutch.png">
      </div>
      <div class="taalicon">
        <img src="img/flag/france.png">
      </div>
    </div>
    <div class="smalltitle">
      Over
    </div>
    <div class="bio">
      <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the
        industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type
        and scrambled it to make a type specimen book. It has survived not only five centuries, but also the
        leap into electronic typesetting, remaining essentially unchanged. </p>
    </div>
  </div>
</div>

问题是我想要图像左下角带有用户信息的 div。我认为如果我使用它会去那里bottom: 0;,但这会推动它。

我究竟做错了什么?

标签: htmlcss

解决方案


不知道图像大小是多少,.image-container也没有height: 100%。也不要忘记第一条规则:

html, body {
  height: 100%;
}

.grid-pagina {
  width: 80%;
  margin: auto auto;
  display: grid;
  grid-template-columns: 45% auto;
  column-gap: 20px;
  padding-top: 30px;
}

.leftside {
  width: 100%;
  height: 90%;
  text-align: left;
}

.rightside {
  width: 50%;
  height: 90%;
  font-family: 'Roboto', sans-serif;
}

.country {
  top: 25px;
  right: 25px;
  position: absolute;

}

.country img {
  border-radius: 32px;
  height: 64px;
  width: 64px;
}


.title {
  font-size: 35px;
  margin-bottom: 10px;
  font-family: 'Roboto', sans-serif;
  color: red;
}

.image-container {
  position: relative;
  width: 100%;
  display: inline-block;
  background-color: blue;
}

.coverimage {
  border-radius: 30px;
  top: 0;
  left: 0;
  width: 100%;
  min-width: 100%;
  min-height: 100%;
}

.activity-container {
  position: absolute;
  top: 0;
}

.activity {
  display: flex;
  align-content: center;
  justify-content: center;
  color: red;
  font-size: 20px;
}

.activity img {
  height: 50px;
}

.activity span {
  padding-left: 10px;
  margin: auto auto;
}



.user-info {
  position: absolute;
  bottom: 0;
  left: 0;
  background-color:red;
  vertical-align: bottom
}

.user-info .user-name {
  font-size: 30px;
  padding: 10px;
  font-weight: bold;
  color: white;
}

.user-info .user-details {
  font-size: 20px;
  padding: 10px;
  color: white;
}


.smalltitle {
  font-size: 25px;
  margin-top: 30px;
  color: red;
}

.hobbysmall img {
  height: 20px;
}

.hobbysmall {
  padding-right: 40px;
  display: inline-block;
}

.taalicon {
  height: 50px;
  width: 75px;
  padding-left: 15px;
  display: inline-block;
  margin-top: 30px;
}

.taalicon img {
  height: 100%;
  width: 100%;
}

.talen {
  display: inline-flex;
}

.bio p {
  width: 450px;
  overflow: hidden;
  height: 200px;
  line-height: 20px;
  word-wrap: break-word;
  padding-top: 20px;
}

.declinebutton {
  position: relative;
  margin-left: 15%;
}

.acceptbutton {
  margin-top: -20px;
  position: relative;
  margin-left: 5%;
}

.interesses {
  margin-top: 20px;
}

.bigbutton img {
  height: 100px;
  padding-top: 70px;
}
<div class="grid-pagina">
  <div class="leftside">
    <div class="title">
      Noorwegen
    </div>
    <div class="image-container">
      <img src="https://static.rondreis.nl/rondreis-storage-production/bezienswaardigheden-69-rome-jpg/1024x686/cover/eyJidWNrZXQiOiJyb25kcmVpcy1zdG9yYWdlLXByb2R1Y3Rpb24iLCJrZXkiOiJiZXppZW5zd2FhcmRpZ2hlZGVuXC82OVwvcm9tZS5qcGciLCJlZGl0cyI6eyJyZXNpemUiOnsid2lkdGgiOjEwMjQsImhlaWdodCI6Njg2LCJmaXQiOiJjb3ZlciJ9fX0=" class="coverimage"/>
      <div class="activity-container">
        <div class="activity">
          <img src="img/page/match_profiel/sun.png"> <span>Zonnig</span>
        </div>
        <div class="activity">
          <img src="img/page/match_profiel/icon_boat_red.png"> <span>Zonnig</span>
        </div>
        <div class="activity">
          <img src="img/page/match_profiel/icon_climb.png"> <span>Zonnig</span>
        </div>
      </div>

      <div class="country">
        <img src="img/flag/dutch.png">
      </div>

      <div class="user-info">
        <div class="user-name">
          Tim, 26 jaar
        </div>
        <div class="user-details">
          Man, 2000-3000
        </div>
      </div>
    </div>
  </div>
  <div class="rightside">
    <div class="smalltitle">
      Interesses
    </div>
    <div class="interesses">
      <div class="hobbysmall">
        <img src="img/page/match_profiel/icon_tag.png"> Boten
      </div>
      <div class="hobbysmall">
        <img src="img/page/match_profiel/icon_tag.png"> Boten
      </div>
      <div class="hobbysmall">
        <img src="img/page/match_profiel/icon_tag.png"> Boten
      </div>
    </div>
    <div class="talen">
      <div class="smalltitle">Taal(en)</div>
      <div class="taalicon">
        <img src="img/flag/dutch.png">
      </div>
      <div class="taalicon">
        <img src="img/flag/france.png">
      </div>
    </div>
    <div class="smalltitle">
      Over
    </div>
    <div class="bio">
      <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the
        industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type
        and scrambled it to make a type specimen book. It has survived not only five centuries, but also the
        leap into electronic typesetting, remaining essentially unchanged. </p>
    </div>
  </div>
</div>

预习

预习


推荐阅读