Help! The CSS height property is not working properly and I'm not sure how to resolve

I'm facing an issue with the height property of a specific div and I can't seem to fix it.
SCSS:

            .security{
                border: 3px #1D3176 solid;
                display: flex;
                h2{
                    position: absolute;
                    width: 25%;
                    left: 70%;
                }
                img{
                    position: absolute;
                    width: 25%;
                    left: 5%;
                }
                .intro{
                    position: relative;
                    width: 25%;
                    left: 70%;
                    top: 40px;
                }
                h4{
                    position: absolute;
                    width: 30%;
                    left: 35%;
                }
                .text{
                    position: relative;
                    width: 30%;
                    left: 10%;
                    top: 50px;
                }
            }
            .human-rights{
                border: 3px #1D3176 solid;
                display: flex;
                h2{
                    position: absolute;
                    width: 25%;
                    left: 5%;
                }
                img{
                    position: absolute;
                    left: 35%;
                    width: 30%;
                }
                .intro{
                    position: relative;
                    width: 25%;
                    left: 5%;
                    top: 40px;
                }
                .a{
                    position: absolute;
                    width: 25%;
                    left: 70%;
                }
                .text1{
                    text-align: center;
                    position: relative;
                    width: 25%;
                    left: 46%;
                    top: 50px;
                }
                .b{
                    position: absolute;
                    width: 25%;
                    left: 70%;
                    top: 100px;
                }
                .text2{
                    text-align: center;
                    position: relative;
                    width: 25%;
                    left: 20%;
                    top: 150px;
                }
            }

HTML:

        <div id="sec-counc" class="security">
                <h2>Security Council</h2>
                <img id="sec-counc-img" src="imgs/SecCounc.png" alt="Security council committee">
                <div class="intro">The SC is the only committee, which can pass legally binding 
                    resolutions and deploy humanitarian and military missions, but it is also the 
                    only one where some countries posses veto powers. The challenge is making the best 
                    of the former, while working around the latter.</div>
                <h4>Topic 1:</h4>
                <div class="text">Resolving the political crisis in the Federal Democratic 
                    Republic of Ethiopia relating to the uprisings in the Tigray, Oromia, 
                    and Benishangul-Gumuz regions.</div>
            </div>
            <div class="human-rights">
                <h2>Human Rights Council</h2>
                <img src="imgs/HumanRightsCounc.png" alt="Human right council committee">
                <div class="intro">The United Nations was founded on the prospect of the promotion of human rights. 
                    Unfortunately, most member countries did not get the memo, and continue to violate the human rights. 
                    The HCR has special authorization to launch public awareness campaigns, and send communications 
                    (official letters, which inform of human rights violations, and encourage their stoppage, being 
                    sent to governments, IGOs, NGOs, and companies). It is up to the delegates to make the most of
                    these limited tools.</div>
                <h4 class="a">Topic 1:</h4>
                <div class="text1">Addressing the violations of human rights caused by 
                    inter-racial hatred especially in multi-ethnic states.</div>
                <h4 class="b">Topic 2:</h4>
                <div class="text2">Addressing the status of human rights of drug dealers and drug users.</div>
            </div>

The borders should show the height of the elements, but they don't match as intended: https://i.sstatic.net/ibInX.png I am trying to achieve the layout where the yellow picture is one element and the blue picture appears below it consistently. Hard coding the height with "npx" doesn't work due to scaling issues. Any help would be greatly appreciated.

Answer №1

Avoid using position: absolute for adjusting element positions as it can lead to responsive issues and difficulties in re-positioning.

Instead, I suggest utilizing flex for re-positioning elements effectively.

.flexbox {
  border: 3px #1D3176 solid;
  display: flex;
  padding: 1rem;
}

.flex-item {
  flex: 1 1 0;
  padding: 0 1rem;
}

.topic {
  margin: 1rem 0;
}

.center-text {
  text-align: center;
}

.intro {
  text-align: justify;
}

h4 {
  margin: 0.5rem 0;
}

img {
  width: 100%;
}
<div id="sec-counc" class="security flexbox">
  <div class="flex-item">
    <img id="sec-counc-img" src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/52/Emblem_of_the_United_Nations.svg/120px-Emblem_of_the_United_Nations.svg.png" alt="Security council committee">
  </div>
  <div class="flex-item">
    <h4 class="center-text">Topic 1:</h4>
    <div class="text center-text">Resolving the political crisis in the Federal Democratic Republic of Ethiopia relating to the uprisings in the Tigray, Oromia, and Benishangul-Gumuz regions.</div>
  </div>
  <div class="flex-item">
    <h2 class="center-text">Security Council</h2>
    <div class="intro">The SC is the only committee, which can pass legally binding resolutions and deploy humanitarian and military missions, but it is also the only one where some countries posses veto powers. The challenge is making the best of the former, while working
      around the latter.</div>
  </div>

</div>
<div class="human-rights flexbox">
  <div class="flex-item">
    <h2 class="center-text">Human Rights Council</h2>
    <div class="intro">The United Nations was founded on the prospect of the promotion of human rights. Unfortunately, most member countries did not get the memo, and continue to violate the human rights. The HCR has special authorization to launch public awareness campaigns,
      and send communications (official letters, which inform of human rights violations, and encourage their stoppage, being sent to governments, IGOs, NGOs, and companies). It is up to the delegates to make the most of these limited tools.</div>
  </div>
  <div class="flex-item">
    <img src="https://reliefweb.int/sites/reliefweb.int/files/resources/1024px-United_Nations_Human_Rights_Council_Logo.svg_.png" alt="Human right council committee">
  </div>
  <div class="flex-item">
    <div class="topic">
      <h4 class="a center-text">Topic 1:</h4>
      <div class="text1 center-text">Addressing the violations of human rights caused by inter-racial hatred especially in multi-ethnic states.</div>
    </div>
    <div class="topic">
      <h4 class="b center-text">Topic 2:</h4>
      <div class="text2 center-text">Addressing the status of human rights of drug dealers and drug users.</div>
    </div>
  </div>

</div>

Check out the SCSS version here https://jsfiddle.net/zu08hfva/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

No modifications to the CSS can be made within the "alterations" section of the Console drawer in Chrome

Is there a way to easily track and summarize all of my live CSS changes in the Chrome browser? I've searched on Stack Overflow, but haven't found a solution that works for me. This specific answer seems like it could be the most helpful for achie ...

Using array map to create a centered table in a React web application

In my React project, I created a table using the array.map function. However, I'm facing an issue where the output of array.map is always aligned to the left, even before the table itself. I want to center the entire table. JSX: <div className=&qu ...

Arranging divs within a wrapper, ensuring that one of them displays a vertical scrollbar when the content exceeds the space available

I'm currently facing a challenge with defining the height of the description box in order to achieve the layout shown. I am trying to find a solution without relying on javascript. https://i.stack.imgur.com/3j278.png At present, the wrapper and titl ...

Minimize all the open child windows from the main Parent window

I would like to implement a functionality where, upon logging in, the user is directed to a Main Page that opens in a new window. This Main Page contains two buttons, each of which will open a specific report associated with it in a new window when clicked ...

What could be causing the Javascript Dynamic HTML5 Table to not display on the page?

I have a program that calculates the total price of products based on a specified quantity and updates an HTML table with these values. To demonstrate this, I am constantly taking input using an infinite loop. <!DOCTYPE html> <html> ...

How can I convert an HTML Div to CSS styling?

Currently, I am attempting to transform the following HTML code snippet into CSS. While I understand that you can utilize div in CSS, I am uncertain if it is possible to use an href with CSS. Here is the code in question: <div id="menubar1"> <a ...

JQuery Mobile Listview Filter Not Working: Troubleshooting Tips

Recently diving into the world of jquery mobile, I've managed to successfully create a homepage and a sub-page labeled "bible_studies," complete with a dynamic list generated through AJAX. Everything seems to be functioning perfectly except for one i ...

JS form validation malfunctioning

XHTML <form name="suggestion" method="post" action="suggestion.php" class="elegant-aero" onSubmit="return validate()" > <label> <span>Message :</span> <textarea id="Message" name="m ...

Rendering HTML5 and CSS3 on Internet Explorer 8

My coding knowledge is limited, but I am conducting research for our front-end developers. Our goal is to revamp our portal application using CSS 3 and HTML 5 in order to achieve an adaptive layout that can accommodate different browser widths. The curre ...

Manipulating Width in CSS

I am facing a challenge with the HTML code below where an automated software inserts the initial CSS style g2f0 <div class="linelevel row"> <div class="g2f0 col-sm-6 form-group"> <label for="name">Name</label> < ...

JavaScript personalized video controls. Silence the video by manipulating the input range element

As a newcomer to javascript, I am working on creating custom video controls using js. One issue I am facing is with a span element that contains a mute/unmute icon. When I hover over this span element, a child element appears with an input range bar for ad ...

Tips for Excluding Content Retrieved Through file_get_contents?

Currently, I am storing the source code of a webpage in a variable called $html using the following line: $html = file_get_contents('http://www.google.com'); When I use <textarea><?php echo htmlentities($html); ?></textarea> ...

Getting the ID name from a select tag with JavaScript - A quick guide!

Can you help me retrieve the id name using JavaScript when a selection is made in a select tag? I have tried running this code, but it only alerts undefined. For instance, if I select bbb in the select tag, I should be alerted with 2 Any suggestions on ...

a dynamic framework that fills out several forms

I am in search of a way to streamline the data entry process for my awards database. Currently, my "people" table consists of five fields: peopleid first middle last display For example, an entry could look like this: peopleid 120 first William middl ...

How can a single item from each row be chosen by selecting the last item in the list with the radio button?

How can I ensure that only one item is selected from each row in the list when using radio buttons? <?php $i = 1; ?> @foreach ($products as $product) <tr> <td scope="row">{{ $i++ }}</td> <td>{{ ...

After applying CSS, I am unable to click on the radio buttons

Even after selecting the other two, it still defaults to the first one. Here is my code: input[type=radio] { display:none; } input[type=radio] + label:before { content: ""; display: inline-block; ...

What is the method for moving one div above or below another div using the scroll bar?

Here's the scenario I'm facing: I have rows with buttons that, when clicked, reveal a set of options. The challenge is that depending on where the row is located on the page, the settings need to open either above or below the button. When the b ...

Loading screen while all files and audio are being loaded

My JavaScript code is responsible for displaying and playing audio on my website. Unfortunately, the load time of the page is quite slow. To address this issue, I decided to follow a tutorial on installing a preloader, which can be found at . Although I ...

Looking to adjust the fill pattern dynamically

I previously implemented this code: Is there a way to modify the fill image on my 3 buttons to display in 3 distinct colors instead? ...

A guide to filling an irregular shape (such as a star) based on a percentage using CSS in a React project

I am currently working on developing a React component that showcases a rating percentage using a star icon with two different shades. For example, if the input rating is 79%, I want to display a star with 79% of it in gold color and the remaining 21% in ...