Safari fails to set a div to 100% of its parent's height

Currently, I am developing a website where the layout of a section is structured as follows:

<div class="col-md-6">
    <section class="right" data-type="background" data-speed="30" style="background: url(<?php echo get_field('book_image')['url']; ?>);">
    </section>
</div>

In this scenario, the parent div has a height of 2976px in Safari. However, the child element does not adjust its size accordingly, even when the height property is applied to it.

I have tested this issue on Chrome and Safari on macOS: Chrome worked fine, but Safari did not perform as expected.

Is there a way to resolve this without utilizing JavaScript? Thank you :)

-- Update

The site is built using Bootstrap4, but the right class only includes styling properties for the div. See below

  .right {
    max-width: 50vw;
    height: 100%;
    background-size: 60vh !important;
    background-repeat: no-repeat;
  }

-- Update #2.

Below is a snippet showcasing the problem:

.left {
  padding: 0;
  background: #000; /*debugging*/
  height: 200px; /*debugging*/
}

.right {
  height: 100%;
  background-size: 60vh !important;
  background-repeat: no-repeat;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" />

<div class="container-fluid">
  <div class="row">
    <div class="col-6 left">
    </div>
    <div class="col-6">
      <section class="right" data-type="background" data-speed="30" style="background: red;"></section>
    </div>
  </div>
</div>

(or view on JSFiddle: Click here

Answer №1

One useful tip is to visit the website CANIUSE to check which CSS properties are supported by different browsers. In my opinion, using jQuery or JavaScript to adjust the height of a div dynamically when the page loads or is resized is the most effective solution. Keep in mind that there might not be a perfect solution for achieving cross-browser support. If you need assistance with jQuery, feel free to reach out when necessary.

Answer №2

One issue is that the main parent div does not have a specified height property. While Chrome may be able to figure out the height of the containers, Safari (and possibly other browsers) cannot. To resolve this, you need to set a height for the 2nd div within your .row (which is the parent of .right) as well.

Here is how you can style it:

.right-parent {
  height: 200px;
}

This is how the markup should look like:

<div class="col-6 right-parent">
  <section class="right" data-type="background" data-speed="30" style="background: red;"></section>
</div>

Check out the demo for more details.

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

Python Selenium encountering issue with selecting search bar

I have been attempting to use Selenium to search for courses on and scrape the results. However, all the selectors I have tried so far have failed, resulting in empty arrays when printed. I am confused as to why these selectors are failing and what is the ...

The concept of CSS background-position

Hey there, I have a query regarding a sprite image that contains icons with both normal and hover effects. Here is the current CSS code I am using: .wi{ background-image:url(images/icons/small/wi.png); background-repeat:no-repeat; display:blo ...

The .media object in Bootstrap 3 does not experience overflow issues with .dropdown elements

Dropdown menu not displaying fully https://i.sstatic.net/G38cL.png I have a dropdown menu but it seems to cut off halfway through displaying its content. <div class="media-body"> <h4 class="panel-heading" style="margin:0;"> <div ...

Swap the content of one div with another div using client-side code only

Currently, I am in the process of developing my personal website. To enhance user experience, I have implemented a vertical navigation bar on the left side of the page. My goal is to replace the content of a specific div with content from other HTML files ...

What could be causing my CSS navigation toggle button to malfunction?

My attempt at creating a toggle button for tablets and phones seems to be failing. Despite the javascript class being triggered when I click the toggle button, it is not functioning as expected... https://i.stack.imgur.com/j5BN8.png https://i.stack.imgur. ...

Instructions for integrating a select query within another select query in Codeigniter

I have a question regarding two tables shown below: /* questionnaire table */ | q_id | q_title | | ------- | ---------------------- | | 1 | What is your name? | | ------- | ---------------------- | | 2 | What is your gend ...

What could be causing the misalignment of the Datepicker calendar in Material UI?

I have integrated a datepicker using the library "@mui/x-date-pickers/DatePicker". import { DatePicker } from "@mui/x-date-pickers/DatePicker"; import { AdapterMoment } from "@mui/x-date-pickers/AdapterMoment"; import { Locali ...

Creating a vertical line at the bottom using CSS

Is it possible to add a centered line to the bottom of the "numberCircle" in a responsive table created with twitter-bootstrap? I would like it to look like this image: https://i.sstatic.net/WKgFu.jpg Thank you .numberCircle { border-radius: 50%; ...

How can I dynamically adjust the font size of content in a React Material-UI Button when it's unexpectedly

In my web application project, I have created multiple choice questions where each answer is displayed within a single button: <Button fullWidth={true} variant="contained" onClick={(answer) => this.handleAnswer(this.state.answers[0].tex ...

Customize your Bootstrap hamburger menu with a unique open and close button design

Currently, I am in the process of creating a hamburger menu with Bootstrap and I have managed to customize the open and close buttons according to my preferences. However, I am facing an issue where the hamburger icon is not displaying properly. See the c ...

Replacing an array in Perl with the contents of a SQL database: A step-by-step guide

Update: (Check Revised Code at the bottom) The code is now functioning properly to retrieve data from 2 databases with some additional cleaning required. However, I'm facing a challenge where the code previously used: next unless $currentuser ~~ @las ...

Container that displays vertical scroll while permitting floating overflows

Is there a way to set up a container so that when the window size is too small, it displays a scroll bar to view all elements that don't fit in one go? At the same time, can the child containing floating elements be allowed to extend beyond the bounda ...

Container containing sliding content underneath

I've designed a grid with separate boxes that reveal related content when clicked. The display of this content is achieved using jQuery's slideToggle feature. The setup functions smoothly, with each row containing clickable boxes that unveil the ...

Maintaining the image's aspect ratio while cropping it to fit within the maximum or minimum height

Is there a way to make an image responsive by resizing it while keeping its aspect ratio intact at all sizes? I want the height of the image to stay fixed above 650px, cropping the top and bottom to maintain the ratio without stretching. Additionally, I do ...

Dynamically change the fill color of an SVG using styled-components

I've been attempting to target the fill property of my SVG using CSS in styled-components without any luck. Here is my SVG: <svg width="65" height="19" viewBox="0 0 65 19" fill="none" xmlns="http://www. ...

Enhance your website with footer animations using jQuery!

I am implementing a sticky footer on my website to keep the footer at the bottom using CSS. I want the footer to initially be collapsed and expand when the user clicks on a button, swapping the "expand" link with a different container div inside the footer ...

What is the best way to retrieve AJAX post data from the request in Symfony2?

My goal is to efficiently upload a file using jquery-file-upload (blueimp) and include some data in a cross-domain environment. To achieve this, I have utilized code from the basic.html file provided by jqueryfileupload on the client side. Additionally, I ...

How can I create an input field that only reveals something when a specific code is entered?

I am currently developing a website using HTML, and I would like to create an admin section that requires a password input in order to access. After consulting resources on w3schools, I attempted the following code: <button onclick="checkPassword()" i ...

The aria-label attribute does not seem to be functioning properly in Chrome and Firefox when using NVDA screen

Within my code, I have a straightforward textbox element: <input type="text" aria-label="First Name" title="First Name" /> Upon hovering over the textbox, I am displaying the tooltip First Name. I attempted to utilize both aria-label and aria-labe ...

Pause autoplay in Bootstrap v5.0 Carousel when a carousel item is clicked

I've been attempting to disable the carousel autoplay using jQuery after clicking on a carousel item, but all my efforts have been unsuccessful. Can anyone provide some assistance? Thank you! This is what I've tried so far: $(".carousel-i ...