Skip to main content
sambegdouri
Inspiring
June 25, 2017
Answered

How to make child element "truly" flexible in height???? Child won't adjust.

  • June 25, 2017
  • 1 reply
  • 689 views

Hey everyone,

So I have a problem with some child elements, as you will see from the screen shots, and video that is subsequent. Do note, this for MOBILE view.

I know the difference between height: auto/100%. However, one of the parents (also child) elements does not resize to the size of its parent element.

As a result, one child element, a "back-to-top" button is placed half way up of the parent element, and not at the bottom of its brothers/sisters elements (same level).

here is the code, screenshots, and a video to help express my problem in further detail. Thank you to every/anyone who can help me with this issue.

<section id="whatsavaiable" class="section_3 section_all">

    <div class="main_area_container">

         <div class="main_area available_area">

            <div class="h2_heading_container">

                      <h2 class="title_heading h2_what_is_available">WHAT&apos;S AVAILABLE</h2>

            </div>

 
          <div class="section_3_text_wrapper">

                <div class="sam_b_english two_cols">

                      <div class="p_text_container">

                                <h3>General English</h3>

                                <h3>&bull;</h3>

                                <h3>Converstation</h3>

<h3>&bull;</h3>

  <h3>Business</h3>

  <h3>&bull;</h3>

  <h3>Academic</h3>

  <h3>&bull;</h3>

  <h3>IELTS training</h3>

                      </div>

                 </div>

                      <br class="br_not_need"><br class="br_not_need">

                
                   <div class="sam_b_korea provide_korean two_cols">

                      <div class="p_text_container">

  <h3>일반 영어</h3>

  <h3>&bull;</h3>

  <h3>회화</h3>

  <h3>&bull;</h3>

  <h3>비즈니스 영어</h3>

  <h3>&bull;</h3>

  <h3>고급 영어 &lpar;입시&rpar;</h3>

  <h3>&bull;</h3>

  <h3>IELTS 교육</h3>

                      </div>

                </div>

               
               <div class="back_to_top_container">

                      <a href="#top"><div class="back_to_top_icon"></div></a>

                </div>

           </div>
     </div>

  </div>

</section>

GLOBAL

.p_text_container {

  position: relative;

  width: 70%;

  top: 5vh;

  display: block;

  margin: 0 auto;

  text-align: center;

}

.icon_container{

  position: relative;

  width: 100%;

  display: block;

  margin: 0 auto;

  top: 10vh;

}

.back_to_top_icon {

  background-image: url(../assets/icons/back_to_top.svg);

  background-repeat: no-repeat;

  position: relative;

  top: 0;

  margin: 0 auto;

  height: 40px;

  width: 40px;

  text-align: center;

  vertical-align: middle;

}

@media (min-width:320px) and (max-width:435px){

main {

  position: relative;

  top: 0;

  clear: both;

  height: auto;

}

.section_all {

  position: relative;

  top: 0;

  clear: both;

  margin: 0 auto;

  height: auto;

}

.main_area_container {

  position: relative;

  height: auto;

  padding-top: 15vh;

  padding-right: auto;

  padding-bottom: 0px;

  padding-left: auto;

  clear: both;

}

h2 {

  margin: 0 auto 10px auto;

  font-size: 36px;

}

.p_text_container {

  height: 100%;

  clear: both;

  margin: 0 auto;

  display: block;

  width: 85%;

  top: 0;

}

.p_text_container p {

  position: relative;

  top: 0;

  margin: 0 auto;

  font-size: 16px;

  height: 100%;

  text-align: center;

}

.back_to_top_icon {

  position: relative;

  margin: 20px auto;

  top: 0;

}

}

This topic has been closed for replies.
Correct answer osgood_

You would want to make your 'back_to_top_container' have a position of absolute NOT relative.

<div class="back_to_top_container">

<a href="#top"><div class="back_to_top_icon"></div></a>

</div>

Then make your 'section_all' <section> container - position: relative;

You can then just move your 'back_to_top_container' <div> right after the opening tag of the 'section_all' <section> tag and remove the relative positioning from 'back_to_top_icon'

<section id="whatsavaiable" class="section_3 section_all">

<div class="back_to_top_container">

<a href="#top"><div class="back_to_top_icon"></div></a>

</div>

CSS:

.back_to_top_container {

position: absolute;

bottom: 0;

}

Works every time, assuming you have it set up correctly. Example code below. I've set a specific height on the section has it has no content but you wont need to, let the content determine the natural height.

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Relative/Absolute Positioning</title>

<style>

.section_all {

position: relative;

height: 500px;

background-color: yellow;

}

.back_to_top_container {

position: absolute;

width: 100%;

bottom: 0;

text-align: center;

}

</style>

</head>

<body>

<section id="whatsavaiable" class="section_3 section_all">

<div class="back_to_top_container">

<a href="#top"><div class="back_to_top_icon">Back To Top</div></a>

</div>

<!-- end back_to_top_container -->

</section>

<!-- end section_all -->

</body>

</html>

1 reply

osgood_Correct answer
Legend
June 25, 2017

You would want to make your 'back_to_top_container' have a position of absolute NOT relative.

<div class="back_to_top_container">

<a href="#top"><div class="back_to_top_icon"></div></a>

</div>

Then make your 'section_all' <section> container - position: relative;

You can then just move your 'back_to_top_container' <div> right after the opening tag of the 'section_all' <section> tag and remove the relative positioning from 'back_to_top_icon'

<section id="whatsavaiable" class="section_3 section_all">

<div class="back_to_top_container">

<a href="#top"><div class="back_to_top_icon"></div></a>

</div>

CSS:

.back_to_top_container {

position: absolute;

bottom: 0;

}

Works every time, assuming you have it set up correctly. Example code below. I've set a specific height on the section has it has no content but you wont need to, let the content determine the natural height.

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Relative/Absolute Positioning</title>

<style>

.section_all {

position: relative;

height: 500px;

background-color: yellow;

}

.back_to_top_container {

position: absolute;

width: 100%;

bottom: 0;

text-align: center;

}

</style>

</head>

<body>

<section id="whatsavaiable" class="section_3 section_all">

<div class="back_to_top_container">

<a href="#top"><div class="back_to_top_icon">Back To Top</div></a>

</div>

<!-- end back_to_top_container -->

</section>

<!-- end section_all -->

</body>

</html>