Making a div equal in height to an image

What I currently have is like this...

https://i.stack.imgur.com/7FeSi.png

However, this is what I am aiming for.

https://i.stack.imgur.com/fn9m0.png

The image dimensions are set up as follows...

#content img{
padding: 3%;
width: 60%;
height: 50%;
float: left;
}

I'm using %s to ensure responsiveness. Therefore, the exact height of the image in pixels is uncertain.

Trying to apply the same height and width configuration to the gray box only ends up filling it with text, as seen above.

#text{
padding: 3%;
margin-right: 3%;
margin-top: 3%;
width: 37%;
height: 50%;
float: left;
background-color: #333333;
color: #FFFFFF;
}

Any suggestions on how to solve this issue? Perhaps my approach to making it responsive is incorrect.

Thank you for your help.

UPDATE: This is the HTML code used...

<div id="content">
    <img src="projectphotos/1.jpg">
    <span class="arrows" style="float: right;"><i class="fa fa-angle-`double-right fa-3x"></i></span>`
    <div id="text">
        Test
    </div>
</div>

Answer №1

If you want to create a responsive layout, consider using the Flexbox feature.

body, html {margin: 0; padding: 0}
.content {
  display: flex;
}
.text {
  background: #333333;
  color: white;
  flex: 1;
  margin: 10px;
}
.image {
  flex: 2;
  margin: 10px;
}
img {
  width: 100%;
  vertical-align: top;
}
<div class="content">
  <div class="image">
    <img src="http://placehold.it/900x450">
  </div>
  <div class="text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nihil, id.</div>
</div>

Answer №2

simply include display: flex in the CSS for #content and take out the float: left from both elements.

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

Having trouble making changes to FontAwesome CSS using jQuery?

I am currently working on an MVC project where I am using Ajax to update a specific section of a View that contains a FontAwesome 5 icon. The FontAwesome icons are set using CSS classes, so my initial assumption was that it would be simple to remove and ad ...

Load a form using ajax and submit it using jQuery

For a while now, I have been facing challenges in figuring out what's going wrong with my code. The issue arises when I try to submit a form using jQuery that was loaded through ajax. The form loads perfectly fine within a div after invoking the ajax ...

Utilizing jQuery to assign a value to a SPAN tag

In my code, there is an element with the following syntax: <span id="userName.errors" class="errors">Enter Your User Name </span>. I am interested in utilizing jQuery to delete either the text 'Enter Your User Name' or any element tha ...

Is there a way to customize the scrollbar color based on the user's preference?

Instead of hardcoding the scrollbar color to red, I want to change it based on a color variable provided by the user. I believe there are two possible solutions to this issue: Is it possible to assign a variable to line 15 instead of a specific color lik ...

An error was encountered involving an unexpected token < at the beginning of a JSON file while using express with firebase

After setting up an authentication system in express using firebase auth, I established an endpoint in my express server: app.post('/users/login', (req, res) => { console.log('logging in...'); firebase.auth().signInWithEmail ...

Creating a responsive navigation menu using Bootstrap 4 by merging data from various MySQL tables

I am struggling to create a bootstrap 4 nav-menu using the provided SQL query and code snippets. Below are the tables: TABLE menu -------------------------------------- | id | title | url | | 1 | Home | index.php | | 2 | M ...

Storing various duplicates of items in local storage

Looking for help with storage settings in HTML/JavaScript as I work on a mobile not taking app using Phonegap. My goal is to allow users to input a note name and content, save them into a jquery mobile list, and see them on the home screen. However, I&apos ...

Angular state correctly maps to the controller but is not reflected in the HTML

I'm currently in the process of setting up a basic Angular application, something I've done many times before. I have defined a home state and another state for a note-taking app, but I am facing an issue where neither state is displaying or inje ...

Utilizing XPath in Selenium: Extracting text from elements based on their adjacent elements

I'm facing an issue where I am unable to retrieve the text value from one end. Here is a snippet for better understanding: <div class=""> <span class="address_city">Glenwood</span> <span class="address_state">GA</span> ...

The origin of the distribution file diverges from the source path of the development

Currently, I have implemented a task runner with Gulp to export all my folders into a distribution folder. However, an issue arises when exporting images to the distribution folder as the path name differs from what is specified in my source files. For ins ...

json_encode has stopped functioning (now)

Recently, I encountered a strange issue. I've been trying to display chart data, but the JSON_ENCODE function that is supposed to convert my data into JSON format is not returning anything. It was working fine before when I had less data, but now it&a ...

Fading colored images and backgrounds using Javascript

Although js and html are not my strong points, I am attempting to create two simple effects on a single page. As the user scrolls down the page, I want the background image or color to change as different divs come into view and then move off the screen. ...

What is the best way to place an icon in the lower right corner of a design

I have encountered an issue while building the testimonial section below. The problem arises when the amount of text in each block is not the same, causing the quote icon to be displayed improperly in the bottom right corner. Sometimes, it even extends out ...

get the value of the last selected element using jQuery

I am facing an issue where I cannot retrieve the selected value from my second select element. Even though I have selected the second option in the dropdown, it keeps returning the value of the first option as empty. Here is a snippet of the HTML code: & ...

Tips for shifting objects from a horizontal row to a designated vertical column when switching to a smaller display

I am currently utilizing bootstrap to enhance my website layout for mobile view. The main challenge I'm facing involves transitioning items from a row to a column in a specific order. In this case, I have two items in a row and I would like the first ...

Making the Bootstrap 4 card-footer expand to occupy the remaining height of the column

I'm currently developing a project that incorporates bootstrap cards. There are 3 cards, each for a different column, and I need them to have equal heights. Here is how they currently look: The B and C cards should occupy the remaining height of thei ...

Returning a button to its original state

Currently, I am working on styling the video controls on my website and have run into a small issue. The video section consists of a video list and a video player. When an li element from the list is clicked, the source of the video player changes to the ...

Modifying linked dropdown selections with jQuery

I'm trying to create a recurrent functionality where I have 3 select elements. When the first select is changed, it should update the second and third selects accordingly. If the second select is changed, then it should also affect the third select. ...

Utilize Javascript to Populate Form Fields Based on "Selected Name"

I am currently facing a challenge in using javascript to automatically populate a form, specifically when it comes to setting the value for the country field. <form action="/payment" method="post" novalidate=""> <div class="input_group"> ...

What factors influence the timing of Chrome's spell-check feature for a particular word?

Currently, I am troubleshooting a bug in our code that is related to text input behavior. The issue at hand is that in one field, when you start typing on Chrome, the word does not get red underlined until you press space. However, in another field, Chrom ...