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: 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

Distinguish the disparities between mobile and desktop devices

I need a solution for adjusting the layout of a component based on the device it is viewed on. For mobile devices, I want the content to stack vertically like in this example: https://codesandbox.io/s/material-demo-forked-ktoee?file=/demo.tsx. However, o ...

Experiencing difficulties positioning svg text path in the center using CSS on desktop devices

I've looked into other SVG text questions, but I'm struggling to understand my mistake. Currently, I'm working on a live site at and implementing the following code: <svg class="svg-width desktop" style="margin:auto"> <path ...

Images in assets folder are not showing up in Vue Bootstrap

I'm attempting to showcase an image similar to the example provided in this guide Below is the code I am using: <template> <b-container fluid class="p-4 bg-dark"> <b-row> <b-col> <b-img rounded="ci ...

Surprising margin discrepancy of 10px found while utilizing float property in CSS

Encountered an issue with the CSS property "float". There is a 10px margin at the top of the page. How can this be fixed? I tried adding an empty div to the parent div with id="background1", but it did not work. I also found this article https://css-trick ...

The width of the HTML page seems to adjust or shift when I click on

I'm encountering an issue with my navbar. Whenever I open the dropdown menu, the width of my page changes but returns to normal when it is closed. <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="styl ...

Generate a Calendar Table using JavaScript in the Document Object Model (DOM

I have set up a table with 6 rows and 5 columns. The purpose of the table is to represent each month, which may have varying numbers of days. I want each column to display dates ranging from 1-30 or 1-31, depending on the specific month. Here's what ...

Adapting JavaScript functions from IE to work on Firefox and Chrome: A comprehensive guide

I have encountered an issue with a function that retrieves the selected text range within a contenteditable div. While it works perfectly fine in Internet Explorer, it doesn't seem to work in Firefox and Chrome. Could someone kindly provide guidance ...

Implementing text wrapping within input elements for optimal print.css layout

Can you help me with a print.css issue I'm experiencing? I am currently working on my print stylesheet and I've encountered a challenge where I need to word wrap input fields to ensure all the text is displayed correctly. Despite trying various ...

Attempting to ensure that the social media icons are perfectly centered in between the separators on the page

After adding new menu separators, the alignment of my social media icons has been thrown off and I need them to be centered. I'm not sure why this happened or how to fix it. I attempted to add some CSS but had no success. My website can be found at . ...

Layering elements using the z-index property in Internet Explorer 7,

Issue with text placement in a dialog div only occurring in IE 7. To see the problem, visit this page and click on any of the text boxes on the left side. Attempts to fix by adjusting z-index in the skin.css file for div.dialogFromAndTo did not resolve ...

Issue with the left margin of the background image

I am currently facing an issue with a series of background images that are supposed to fade in and out behind my content. These images are centered, wider than the content itself, and should not affect the width of the page. However, there is an unexpected ...

How to modify an array in an HTML document using BeautifulSoup

Running a Python script, I am trying to access a local HTML file containing a JavaScript array inside a script tag that needs updating. Here is the test code snippet: from bs4 import BeautifulSoup html = ''' <script> var myArray ...

Animate objects as they move along the page

Modern websites often incorporate animations into their designs. I had the idea to animate elements as we scroll down the page, using a combination of JQuery, HTML, and CSS. <div class="noanimate imgleft"> </div> <div class="noanimate img ...

Passing a JavaScript variable to a URL parameter can be achieved by

Can anyone advise me on passing JavaScript string variables and displaying them in the URL? For instance, let's say the URL is "xyc.com". Upon populating a variable (a), I wish for that variable to appear in the address bar as URL = "xyc.com/?a=". Cur ...

The MUI snackbar element lingers in the DOM even after it has been closed

Having created a global modal with the intention of only utilizing it when necessary, I've encountered an issue where the snackbar div persists in the DOM. This persistence is causing certain elements to become blocked as they appear beneath this div. ...

How to customize the color of the clock symbol in a MUI TextField set to type 'time'

<TextField id="endTime" label="End Time" onChange={onEndTimeChange} type="time" defaultValue="16:00" className={classes.textField} /> By using the attribute 'type="time"', an ic ...

What could be the reason my dropdown menu is not appearing on hover?

Currently, I am in the process of developing a menu using angularJS and google app script within a dialog box. I have been referring to this sample code for guidance. Instead of pasting all my code here, I can summarize what I have come up with: var a ...

What could be causing the span class data to not be retrieved by the getText method

Looking to retrieve the value of a span class called 'spacer-right big project-card-measure-secondary-info' <span class="spacer-right big project-card-measure-secondary-info">1</span> snippet of code: browser.waitForEl ...

What is the best way to display and conceal elements depending on the chosen option using jQuery?

Can you help me figure out why this code isn't working as expected? <Script> $('#colorselector').change(function() { $('.colors').hide(); $('#' + $(this).val()).show(); }); </Script> < ...

Avoid connecting HTML input elements with both JavaScript and Java models

I am troubleshooting an issue with my login page code. <div ng-show="!loggedIn()"> <form ng-submit="login()"> Username: <input type="text" ng-model="userName"/> Password: <input ...