A dynamic and versatile solution for achieving uniform column heights across different web browsers using child elements

Get straight to the point.

I'm looking for a solution to create a responsive two-column layout like the one shown in the image below.

https://i.sstatic.net/mHhfc.png

The width ratio of the .left and .right columns should always be 75/25% relative to the .parent, and their heights should remain synchronized.

The .left column should contain an image that adjusts in size based on the viewport, while the .right column should have three child elements (.cta) taking up exactly 1/3 of the height of .parent each.

The requirements for an acceptable solution are:

  • Support for a wide range of devices and browsers (IE9+ is acceptable)
  • Compatibility with vendor-specific browsers used by brands like HTC
  • No use of flexbox
  • Avoid using JavaScript to set explicit heights for .left and .right columns

The closest solution I've found involves using display: table-cell; to keep the heights of .left and .right in sync. However, this method doesn't work in IE due to conflicts between parent and child containers when defining dimensions as percentages. This causes the .right container to expand to full height in all browsers except IE.

See example on Codepen

HTML

<div class="parent">
  <div class="left">
    <div class="image-container"><img class="image" src="http://placehold.it/1300x780" alt="" /></div>
  </div>
  <div class="right">
    <div class="cta">
      <a>LINK #1</a>
    </div>
    <div class="cta">
      <a>LINK #2</a>
    </div>
    <div class="cta">
      <a>LINK #3</a>
    </div>
  </div>
</div>

CSS

.parent {
  display: table;
  width: 90%;
  height: 100%;
  margin: 0 auto;
}

.parent > div {
  display: table-cell;
  height: 100%;
  vertical-align: top;
  text-align: center;
}

.left {
  width: 75%;
}

.image {
  display: block;
  width: 100%;
  height: auto;
}

.right {
  width: 25%;
  background: #bbb;
}

.cta {
  display: table;
  width: 100%;
  height: 33.33%;
  font-family: Helvetica, Arial, sans-serif;  
  overflow: hidden;
  background: #bbb;
  color: #fff;
  text-transform: uppercase;
  text-align: center;
}

.cta a {
  display: table-cell;
  vertical-align: middle;
  height: 100%;
  cursor: pointer;
}

If all else fails, there's always JavaScript as a backup solution. It's frustrating that in 2016 we still need hacks to achieve such simple layouts.

Answer №1

If you want compatibility across different browsers, except for dinosaurs, then using inline-block along with a touch of calc() might solve your issue:

* {
  box-sizing: border-box;
  margin:0;
}
.parent div div a,
.parent div  div {
  border: solid 1px;
}
.parent div.left {
  padding: 1em;
  border: solid 1px;
}
.parent div {
  display: inline-block;
  vertical-align: top;
  width: 100%;
}
.parent {
  width: 70%;/* for demonstration purposes, try running it in full page mode too */
  margin: auto;
  background:yellow;
}
img {
  width: 100%;
  display: block;
}
.parent .left {
  width: 75%;
}
.parent .right {
  width: 25%;
}
.parent div div a {
  margin: 0.88em;
  display: block;
  text-align: center;
  /* if floating pseudo do
  overflow:hidden;*/
}
.parent div div a:before {
  content: '';
  padding-top: calc(60% - 0.5em);/* is calc() allowed ?  if not keep 60% and remove margin:1em from links */
  /* float:left; or use vertical-align */
  display: inline-block;
  vertical-align: middle;
}
<div class="parent">
  <div class="left">
    <div class="image-container">
      <img class="image" src="http://placehold.it/1300x780" alt="" />
    </div>
  </div><!-- correcting white-space disturbance -->
  <div class="right">
    <div class="cta">
      <a>LINK #1</a>
    </div>
    <div class="cta">
      <a>LINK #2</a>
    </div>
    <div class="cta">
      <a>LINK #3</a>
    </div>
  </div>
</div>

http://codepen.io/anon/pen/VjpdZE

IE11 compatibility example: https://i.sstatic.net/4ZrRa.jpg

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

Click anywhere on the body to conceal this element

I am currently working on a website where I have implemented a hidden menu that is functioning correctly. However, I want to make it so that when the menu is visible, users can click anywhere on the body to hide it. Unfortunately, my current code is not w ...

"Encountering a glitch with masterpage.cs in Aspx.net and C#

Currently facing a perplexing issue while developing a website using aspx.net and c#. The following code snippet is on my masterpage: protected void Page_Load(object sender, EventArgs e) { if (HttpContext.Current.Request.Url.AbsolutePath == "/ ...

Listening for JS events on a CSS class called "int-only" which only accepts

Having an issue: I'm encountering a problem with this PHP code: <?php for($i = 0; $i < sizeof($floating_ips_json["floating_ips"]); $i++){ ?> <tr class="details-control-<?php echo $i; ?> cursor-pointer"> <t ...

I'm having trouble adjusting the link color in my footer text while navigating Wordpress for the first time

As someone who is new to Wordpress, I am struggling with changing the link color in the footer text. Despite spending hours on it, I just can't seem to figure it out. The files I have been working with are style.css and bootstrap.min.css. I feel lik ...

`Text-overflow ellipsis should function consistently across both Firefox and Chrome browsers`

A design has been created to showcase captions for articles and their respective statuses. The article name box has a fixed width, with text-overflow:ellipsis applied to trim excessively long names. Additionally, a light grey dotted line is added at the en ...

What is the process for customizing styles within the administrative area of a Wordpress website, such as modifying the shade of the admin toolbar?

Can someone provide guidance on changing the color of a specific dashicon in the WordPress admin toolbar? I've tried adjusting the color using the browser inspector, but I can't seem to get it to work when I add the code to my stylesheet. #admin ...

Navigation is failing to float in the correct position

Having issues with my navigation positioning, specifically when it reaches the breakpoint. There's a strange gap on the right side that I can't seem to fix by adjusting padding or margin settings. I'm relatively new to this so please bear wi ...

What is the process of adding CSS effects to a button when a keypress activates it?

Do you have a CSS style that transforms the look of a button when clicked on-page? Want to extend this effect to when the button is activated via keyboard? (In essence, browsers allow activating a button by pressing Tab to give it focus and then hitting S ...

The Cascading of Bootstrap Card Designs

Looking for some assistance with my TV Show Searcher project that is based on an API. The functionality is complete, but I'm struggling to get the Bootstrap cards to stack neatly without any empty space between them. I want it to resemble the image ga ...

Creating a visually appealing chart similar to Excel can be achieved using JavaScript with a whopping 64382 lines of JSON data. No need for Chart.js or any additional tools - simply rely on JavaScript, HTML, and CSS to

I have a project that is due in just a few hours and I need to create a detailed chart using a large set of 64382 lines of JSON data. My knowledge of javascript is limited, so I am struggling to come up with ideas on how to approach this task. While I have ...

Prevent scrolling in a full-screen modal using CSS

I came across a beautiful fullscreen modal that is purely based on CSS. The only issue I encountered was that the modal isn't scrollable. I attempted various solutions but haven't been successful. Here's the script I am using: ...

How can I eliminate the empty spaces surrounding an image?

How can I remove the extra space around an image that is placed inside a bootstrap column? On the desktop version, I was able to solve the issue by setting -1rem margins on the left and right. I tried adjusting the body margin and padding to 0, as well as ...

Ways to eliminate unused classes from JQuery UI

We have successfully implemented JQuery UI library for enhancing our interface. However, since we no longer need to support outdated browsers like IE6, classes such as .ui-corner-all, .ui-corner-top, .ui-corner-left, .ui-corner-tl are unnecessary and clu ...

Tips for positioning buttons in a circular arrangement around an image

I am having trouble creating a responsive menu around a circular image. When the screen resolution changes, the buttons do not stay aligned next to the circle picture and their position shifts. How can I ensure that these image buttons stay aligned with th ...

Expanding the size of a text area input within a form using CSS and

How can I adjust the size of the text area in the Comment section to match the full width of the section, starting from the beginning instead of the middle? You can find the code here. HTML <body bgcolor="#00BCD4"> <div> <h1>Co ...

Struggling to align text to the far left within a text area using Bootstrap

When I accidentally place my cursor earlier in the text area, it starts writing from that point, leaving some unwanted spaces at the beginning. I prefer it to start from the extreme left, similar to how it behaves in input boxes. Below is the code snippet ...

How to create a full-page background image using Bootstrap?

Take a look at this example: In the provided example, there is a background landing page that expands to fit the width of the viewport, remains responsive, and does not take up the full width of the page. How can you utilize bootstrap to manually code an ...

A minimalist dropdown menu using only HTML and CSS with an onclick function

I have been working on creating an onclick dropdown menu for mobile devices that should disappear when viewed on wider screens, but I've encountered an issue where the links in the menus are not clickable even though the @media query is set up correct ...

How come my picture is clinging to the bottom of the container?

I am facing an issue where my "vertical rule" is sticking to the bottom of the container when placed to the right of the image. <div> <div style="display:inline-block; width:210px;"> <img src="res/img/PlayBtn.png" style="top:- ...

Stencil - React Integration Does Not Support Global CSS Styling

As per the guidance provided in the Stencil docshere, I have established some global CSS variables within src/global/variables.css. This file is currently the sole CSS resource in this particular directory. Upon attempting to incorporate my components int ...