Designing a webpage with three columns, where the width of each column is determined by its content and the final

Struggling to accomplish what I believed would be a simple task in HTML/CSS, but continuously facing obstacles in achieving the desired layout.

My objective is to create a three-column layout where three different pieces of content are displayed as part of a continuous sentence with an image in the middle. The challenge lies in adapting the column widths based on varying text lengths and image sizes, ensuring that the last column fills up the remaining space for the text to break appropriately.

Refer to the diagram below for an illustration of the intended layout:

https://i.sstatic.net/iVdmQ.jpg

An interactive example showcasing how each component should respond to different image sizes can be viewed here: xd.adobe.com/view/9a63781a-2514-4d75-926f-429d287c5f4e-cf30

As depicted in the design specifications:

  1. Short text (adjusted column width based on text length)
  2. Landscape or Portrait Image (image size set in CSS with column width based on image width)
  3. Longer text (third column width occupies available space left by first two columns)

Find my code snippet and fiddle link provided below for reference:

HTML:

    <div id="container">            
        
            <span class="part_one">Some text, column adjusts to text length,</span>
                    
            <span class="part_two">
                <img src="https://images.pexels.com/photos/1169754/pexels-photo-1169754.jpeg"><span class="comma">,</span>      
            </span>
                    
            <span class="part_three">"This section contains only text and fills the remaining space after accommodating text length and image width. It is positioned aligned to bottom of the image, regardless of its height. All lines overflow and break accordingly if the text is lengthy.</span>

    </div> 

CSS:

    #container {
        width: 97%;
        margin: 1rem 1.4rem; 
    }
    
    .part_one {
      vertical-align: top; 
    }
    
    .part_two {
      margin: 0.3vw 0.2vw 0 0.1vw;
    }
    
    .part_two img {
      max-width: 46%;
    }
    
    .comma {
        margin: 0 0.4vw;
    }

The issue arises when the last column fails to break correctly and instead moves to the line below the image. Is there a more efficient way to structure this using flexbox?

Answer №1

Utilizing CSS-Grid for layout is an effective solution. [Expand to full view]

It's worth noting that the design lacks responsiveness due to the image width being set to auto and not adjusting to different screen sizes (unless specifically coded to do so).

#wrapper {
  width: 95%;
  margin: 1.5rem auto;
  display: grid;
  grid-template-columns: max-content auto 1fr;
}

.section_one {
  vertical-align: top;
}

.section_two {
  margin: 0.4vw 0.3vw 0 0.2vw;
}

.section_three {
  grid-row: 2;
  grid-column: 3;
}
<div id="wrapper">            
    
        <span class="section_one">Text content with flexible column length.</span>
                
        <span class="section_two">
            <img src="http://www.fillmurray.com/284/196"><span class="comma">,</span>      
        </span>
                
        <span class="section_three">This area will only contain text and adjust to fit remaining space based on previous content and image width. Positioned at the bottom of the image, regardless of its height. Text wraps and breaks appropriately when lengthy.</span>

</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

Is it expected for every element to return true when checking their visibility with isDisplayed() after performing a get() method

Why are WebDriver get() and isDisplayed() methods not functioning as expected? According to the documentation: This is done using an HTTP GET operation, and the method will block until the load is complete As seen in similar questions such as Wait fo ...

The select tag containing the ng-model attribute fails to display the preset default value from the controller

Within the pagination feature, a dropdown menu has been included to allow users to select the number of items displayed on each page. However, there seems to be an issue with the default values that have been set in the controller not displaying correctly. ...

Could you make sure to adjust all the columns, as the 2nd and 3rd columns are

Please take a look at the preview of my pricing table code below. You'll notice that the 2nd and 3rd columns are not aligned properly. I need help fixing the code to ensure all 3 columns are level. Check out the codes below: <html> <head> ...

The Bootstrap icon is causing some complications

I'm experiencing some issues with my Bootstrap settings as I'm still learning how to use Bootstrap. I attempted to design a button using Bootstrap and wanted to add an icon to it, but unfortunately, I couldn't get it to work. Despite trying ...

Improper height of MathJax in the div element

I'm currently investigating why the MathJax render block is giving me an incorrect height for the div. Here's the code snippet: <div class="text-field" id='inner-text'>\(\sqrt{b^{a}\frac{\partial y}{& ...

Adding additional information to the end of a table using JQuery

<table id="myTable0" name="myTable0"> <tbody> <tr> </tr> </tbody> </table> <table id="myTable1" name="myTable1"> <tbody> <tr> </tr> </tbody> </table> I am seeking a solution in JQuer ...

I am interested in parsing the HTML content and replacing it with the specific text that is needed

<!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title id="title1">Amazon Home</title> </head> <body> <p id="p1">Hello World</p> <form action="Translate" method="post"> ...

Having trouble with the width:auto attribute in IE7?

CSS #wrapper .tn{ width:auto; height:20px; line-height:20px; float:left; padding:5px 2px 5px 5px; margin:0 5px 10px; font-weight:bold; background:#f0f0f0; } HTML <div id="wrapper"> ...

A fragmented rendering of a gallery featuring a CSS dropdown menu

Hey there! I'm a newbie coder seeking some assistance. Recently, I stumbled upon a tutorial online that taught me how to create a drop-down menu. However, whenever I hover over "Gallery" on my website, things go haywire and the layout gets all messed ...

Is there a way to modify a document without altering its original location?

I attempted to load an entire page using ajax, with the doctype and html tags removed. However, when I tried setting it with the following code: document.documentElement.innerHTML=xmlhttp.responseText; Google Chrome returned an error message: An invalid ...

What could be causing the lack of responsiveness in my font size when adjusting to different screen sizes?

My understanding was that using font-size: 4em; would result in a relative size, but I am facing an issue where the font size remains constant regardless of window size. This causes overlap and makes the text look unattractive. Specifically, the text in qu ...

Shuffling HTML content into sets of three rows

We have been working on randomizing a series of listings, arranging them in rows of 3 items each. Our goal is to display the entire list in a random order while breaking the line after every 3 entries. Although we have successfully implemented the layout u ...

What is the best way to align bars at the bottom of a CSS vertical bar chart?

Currently, I am exploring the functionality of two distinct bar charts that I designed using HTML and CSS: one horizontal and the other vertical. Is there a way to shift the bars in my vertical bar chart from the center down to the bottom? https://i.sstat ...

Bootstrap Collapse features instantaneous smooth transitions

Utilizing Bootstrap (3.3.6) collapse feature, the collapsible DIVs are positioned in between form inputs\labels. However, there seems to be a slight snap or jitter when these DIVs expand\hide. To view the code for this issue, please visit: https ...

Adding a click function to a div individually when they share the same class in HTML

My goal is to include 4 unique divs inside a timeline container: This is how I envision the structure: <div id="timeline" > <div class="timeline-bar t-1"></div> <div class="timeline-bar t-2"> ...

How to Position Two Child Divs in the Center of a Parent Div

I have been searching extensively, but I can't seem to find a solution to my problem. Let me explain with a simple example. I have two child div elements within a parent div, and I want them to be centered horizontally inside the parent div. Here is t ...

Tips for eliminating the default margin without using a float

Exploring the world of divs and buttons led me to an interesting discovery: removing a float creates a natural margin. Upon entering this styling: body { background: gray; } button { font-size: 17px; color: white; margin-l ...

What is the best way to store client-uploaded files on the client-side using Bootstrap forms and Express server code?

Essentially, the user submits a file for upload, which is then saved on the client-side (I believe this is handled by PHP), and the upload form I am utilizing is a Bootstrap HTML form. On the server side, I am writing my code with Express. I'm feeling ...

Troubleshooting: jQuery unable to retrieve input value on initial page load

Has anyone experienced an issue with getting input value using jQuery? It seems to only work on the second instance when the button is pressed, after going back to the page: Here's the HTML code: <input type="text" class="form-control email_inpu ...

The layout of my website does not adjust properly to different screen resolutions on desktop computers

Hey there! I just finished building a website with HTML, CSS, Jquery, and PHP within 3 months. For the design and layout, I utilized CSS. However, upon testing on small screens, I noticed that some parts of the website require horizontal scrolling to view ...