Creating responsive designs for both div elements

I have two div tags. The first one adjusts its height automatically according to the content inside, while the second one has a fixed height and contains the gmaps.js plugin for displaying Google maps. Without specifying a height for the second div, the map does not appear. Is there a way to make both divs have the same height at all times, even when resizing the window?

Here is the JSfiddle link: https://jsfiddle.net/ntq3xp6b/

CODE SNIPPET FROM JS FIDDLE

<div class="left">
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
</div>
<div class="right"></div>

CSS STYLES

.left{
    display:block;
    width:49.9%;
    float:left;
    background-color:red;
}

.right{
    display:block;
    width:49.9%;
    float:left;
    background-color:blue;
    height:300px;
}

Answer №1

To ensure the proper display of Google Maps, place them within a parent div that has a specific height. Next, set the height of each individual .box to 100%, and provide a min-height of 300px.

.parent {
  height: 400px;
}
.box {
  width: 49.9%;
  float: left;
  height: 100%;
  min-height: 300px;
}
.box.left {
  background-color: red;
}
.box.right {
  background-color: blue;
}
<div class="parent">
  <div class="left box">
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
  </div>
  <div class="right box"></div>
</div>

Answer №2

Perhaps consider including some padding at the top and bottom as well?

.wrapper {
  height: 500px;
}
.item {
  width: 45%;
  float: left;
  height: 100%;
  min-height: 350px;
  padding-top:15px
  padding-bottom:15px;
}
.item.left {
  background-color: green;
}
.item.right {
  background-color: purple;
}
<div class="wrapper">
  <div class="left item">
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
    <br/>
  </div>
  <div class="right item"></div>
</div>

Answer №3

If you're looking to make your boxes the same height, I recommend giving the jQuery matchHeight plugin a try.

 $(function() {
    $('.box').matchHeight();
});

This plugin will automatically set the height of all boxes to match the tallest one. Plus, it will adjust the height dynamically when the window is resized.

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

Any suggestions on the unique Zoom Button design in Google Map?

I have integrated the Google Maps JS API into a WordPress website and added a map to the contact page template. However, I am experiencing some strange behavior where the Zoom In and Zoom Out button style is not displaying as + and -. Does anyone have any ...

Accordion with Tooltips

Exploring the possibilities of Accordions and Tooltips, I aim to create an accordion element with a table containing information. The idea is to add a question mark icon on the right side, which will serve as a Tooltip when hovered over. After designing t ...

Animating the scroll - Transform the image on scroll to give the illusion of rotation

Currently working on a project for a client who wants the product they are selling to rotate as the user scrolls, similar to the effect seen on the Apple website: I have a folder filled with different frames of the rotating product. I'm uncertain abo ...

Utilizing AJAX to submit a combination of text fields and files in an HTML form

Just starting out with AJAX and JQuery, I'm curious if it's possible to send data from an HTML form, including a text file and two separate text boxes, via an AJAX request. So far, I've managed to send the data from the text boxes but not th ...

Execute a task on Mobile Safari (after a delay)

I'm currently experimenting with HTML5 on Mobile Safari for iOS 6 and I'm curious about executing JavaScript code after a certain amount of time has elapsed. One specific task I am interested in is redirecting to a different page after 60 seconds ...

Show a loading image after clicking on an image or button using JavaScript

I recently created an App using PhoneGap and JqueryMobile. Transitioning between multiple HTML pages by clicking on images seems to be causing slow loading times, leaving end users unaware of what's happening in the background. I am looking for a way ...

The border at the top of the table's header will be removed and the

I am trying to achieve a clean look with a solid blue line under my table header. However, the current styling on each th is causing little white separations in between each column. thead th { border-bottom: 4px solid #D3E6F5; padding-bottom: 20px ...

Aligning Text and images perfectly in a DIV container, and beyond

I am trying to center or align text and images at the bottom of a couple of tags, but vertical-align doesn't seem to be cooperating. Another challenge I have is creating a horizontal menu with a start image (e.g. menutop.png), followed by a filler ( ...

Tips for updating table pagination styles in Material-ui version 5.0 using React

I'm currently attempting to customize the table pagination in Material-ui V5.0 using React by adjusting the width, height, and color. However, I am facing an issue where the classes are not being accepted. The pagination relies on .MuiToolbar-root, so ...

Tips on displaying a div for a brief moment and then concealing it

Is it possible to create a div that will disappear after 10 seconds of the page loading using PHP or JavaScript? Here is an example of the code: <html> <head></head> <body> <div class="LOADING" id="LOADING" name="LOADING">&l ...

Create a hover effect for a list item that displays an image and text simultaneously

Is there a way to create an on-hover effect for my icon when hovering over a list item in my dropdown menu? I've shared a codepen link where you can see the issue I'm facing. Everything highlights except the image because I'm only changing ...

Position two div elements evenly with text enclosed in a container

I'm looking to incorporate two distinct blocks of text into a container https://i.stack.imgur.com/6mFZK.png Criteria: Text 1: positioned at the top left corner (85% of box size) Text 2: positioned at the bottom right corner (15% of box size) I&ap ...

Guide on how to style and arrange multiple checkboxes in both horizontal and vertical rows using CSS

Is it possible to align a collection of checkboxes both vertically and horizontally, even when the labels vary in size? I found an example that demonstrates vertical alignment. Click here to view. How can I neatly arrange these checkboxes so that they ar ...

Unleash the power of drag-and-drop functionality with cdkDrop

I am currently tackling a project that requires the implementation of a drop zone functionality where elements can be dragged from a list and dropped in a zone for free movement. I intend to utilize a cdkDropList for the zone due to its comprehensive list ...

JavaScript is used to retrieve the data, however, Internet Explorer is unable to display the data correctly

My web UI looks great in Firefox and Chrome, but for some reason, Internet Explorer is having trouble displaying the data correctly. I am using XMLHttpRequest to fetch data and display it dynamically in my UI. However, IE seems to have issues with this me ...

How can I modify the color of JavaFX text using CSS?

Looking to jazz up my JavaFX application with some custom CSS styling. Managed to link a stylesheet to my app using the following code: //Java code FXMLLoader loader = new FXMLLoader(MainApp.class.getResource("/path/to/fxml")); Scene sce ...

Unable to send email through Ajax/PHP contact form

It's quite amusing that it worked perfectly for one evening. After reaching out to my host, they assured me that there should be no issues with it not working. I even tried testing it in Firebug, but it appeared to be sending successfully. Additionall ...

changes in size in relation to the position of the parent element

Utilizing the transition:scale(1.2) property to conceal a div positioned in the lower left corner of the viewport. Currently, the scaling effect originates from the center as intended: View 'CURRENTLY' on Fiddle I aim to scale it as if the div ...

The process of sending a POST parameter to a page in PHP and opening it

When attempting to open a page using PHP, such as: $html = file_get_contents('https://hammihan.com/search.php'); I encountered an issue where the page was being redirected to https://hammihan.com/users.php due to an empty input for name. To addr ...

Automatically updating div content using a static HTML page

Is there a way to refresh the content of an HTML div tag every 5 minutes without having to reload the entire page? <div id="pie"> <script src="index.js">// this script should be reloaded every 5 minutes </script& ...