Aligning CSS columns with consistent heights and specified widths

My goal is to create two columns with equal height, but with specified percentage widths.

One column needs to have vertically aligned text. I attempted to use display: table-cell, but struggled to set the width properly.

Here is an image demonstrating what I am aiming for: https://i.sstatic.net/9SCAx.png

Any suggestions or ideas on how to achieve this?

Answer №1

If you're looking to achieve a responsive layout, consider utilizing CSS Flexbox. Take a look at the code snippet provided below:

.container {
  display: flex;
  align-items: center;
}

.container img {
  flex: 0.6;
}

.container .content {
  flex: 0.4;
}
<div class="container">
  <img src="http://placehold.it/200x300" alt="" />
  <div class="content">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quasi quis hic suscipit recusandae ad veritatis dolorem expedita placeat rerum architecto provident ipsa, consequuntur, assumenda vitae explicabo sapiente laboriosam cum cupiditate.</div>
</div>

Hopefully, this solution proves helpful for your requirements!

Answer №2

To ensure optimal browser compatibility, consider utilizing the display: table; and display: table-cell; properties.

.outer {
  display: table;
  width: 100%;
}
.inner {
  display: table-cell;
  vertical-align: middle;
  text-align: center;
  height: 200px;
}
.sixty {
  width: 60%;
  background-color: gray;
}
.forty {
  width: 40%;
  background-color: pink;
}
<div class="outer">
  <div class="inner sixty">
    this is an image<br>
    width = 60%
  </div>
  <div class="inner forty">
    this is some text<br>
    width = 40%<br>
    text = vertically aligned
  </div>
</div>

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

A straightforward angular implementation of a non-complicated slider interface

I am working on a web page that needs to display a large list of items. To manage the size, I want to show only 3 items at a time and include next/previous buttons for navigation. Although I am new to Angular, I was able to retrieve and display all the it ...

Creating a basic popup with jQuery: A step-by-step guide

Currently in the process of creating a webpage. Wondering how to create a popup window with an email label and text box when clicking on the mail div? ...

Transitioning the image from one point to another

I am currently working on a unique single-page website and I have been experimenting with creating dynamic background animations that change as the user scrolls. Imagine my website is divided into four different sections, each with its own distinct backgro ...

Encase a table cell containing a lengthy word

I attempted to implement the solution outlined here: How to wrap table cell at a maximum width in full width table However, I am facing difficulties in wrapping the line containing "xxxxxxxxxxxxx". <table class="my-list table table-bordered table-hove ...

Gradient transition effect changing background color from bottom to top

I am facing an issue where I have a block and I want the background color to animate from bottom to top on hover. Can you please help me identify what is causing this problem? Your assistance is greatly appreciated. .right-block--wrapper { backgroun ...

Ensure that the background div extends all the way to the bottom of the page

Is there a clever CSS technique that allows a div to extend all the way to the bottom of the screen without displaying any visible content inside? Or am I better off using JavaScript for this purpose? Thank you, Richard ...

Show an image when hovering over a dot using CSS - without hovering directly on the image

I'm currently working on a merchandising page that involves photoshopping several products onto a background image. I want customers to be able to hover over a dot positioned on each product to reveal its information and provide a link similar to . Ho ...

Modify the color of the text to be white

How can I modify the code below to change the text color to white? The original code is inspired by this question. I am unsure about how the text color was originally set to blue. .footer-background { padding-top: 20px; padding-bottom: 20px; bac ...

Struggling to align the footer of your webpage and ensure it adjusts proportionally with the window size?

After trying several codes that have worked before, I ran into a problem when attempting to place two div side by side for the footer. No matter what code I tried, I couldn't get it centered and responsive to the user window ratio. Even after consulti ...

Step-by-step guide on triggering a button using another button

I have a unique question that sets it apart from others because I am looking to activate the button, not just fire it. Here is my syntax: $("#second_btn").click(function(){ $('#first_btn').addClass('active'); }) #first_btn ...

Update the CSS dynamically using JavaScript or AngularJS

Is there a way to dynamically modify this CSS style using JavaScript or in an Angular framework? .ui-grid-row.ui-grid-row-selected > [ui-grid-row] > .ui-grid-cell{ background-color: transparent; color: #0a0; } .ui-grid-cell-focus ...

What is the best way to add a border to the <map coordinates>?

Is there a way to add a border around the active link section of an image defined by coordinates? I have been able to show an outline when the user clicks using outline-color and href, but now I need a default border around the specified coordinates. I am ...

My website footer is falling short and not reaching the bottom of the page

I've encountered an issue where my footer is not extending all the way down the website, despite trying various solutions. Here's what I attempted: I used the following CSS properties: min-height: 100%; max-height: 100%; I included these prope ...

Utilizing a local video file as a video background in HTML and CSS

I've hit a roadblock while attempting to set a video on my computer as the background. The video file is named "runbg.avi" and it resides in the same folder as my HTML and CSS files. After scouring through numerous websites, I encountered a couple of ...

Creating a variety of themes with unique color palettes for Angular Material along with custom-designed components

One of the goals for my app is to have multiple themes, including Angular Material themes, with the ability to define custom colors for specific components and elements that are not part of Angular Material. It's important that when I change a theme, ...

Search for an element by its class name after adding it using the append

My current situation involves the following code: $('body').append("<div class='bar'></div>"); var trial = $('.bar'); I am unable to locate bar. What mistake have I made in this scenario? ...

Optimal alignment of fixed sidebar

I am currently working on making my sidebar sticky on my website . I have implemented a script in the footer that changes the sidebar from a static position to fixed once the page reaches a certain point. The functionality is working correctly, but I am en ...

Tips for beginners on determining the best placement for CSS properties on a webpage

As a newcomer to CSS, I have encountered some issues when working with properties in different sections of code. For example: P1: Please review the implementation of #menu and #menu a. The code can be found here. P2: Also, take a look at #menu a specific ...

Using a PHP classes array as the name attribute of an HTML select tag

I have a requirement to implement a similar structure in PHP as we do with structs in C. I am aware that in PHP, we use classes for this purpose. However, I need to utilize an array of these classes for naming select tags. Below is my code snippet: <?p ...

Facebook is failing to detect any meta tags in the header of my React web application

After checking my code on https://validator.w3.org/, everything seems fine. However, I noticed that Facebook is not reading most of the content from the head section - not even a single meta tag. On the other hand, Google is able to read all the content fr ...