Flexbox - creating a dynamic column layout with text that does not wrap

I need assistance in creating a flexbox layout with three columns. The left and right columns should have fixed widths, while the center column needs to have a fluid width to occupy the available space. However, the text within the center column is long and I want it to display ellipsis instead of wrapping.

Unfortunately, preventing the text from wrapping causes issues as the column does not adjust to the available space and overflows the parent element.

img {
    max-width: 100%;
}
#container {
    display: flex;
    max-width: 900px;
}
.column.left {
    width: 350px;
    flex: 0 0 350px;
}
.column.right {
    width: 350px;
    flex: 0 0 350px;
}
.column.center {
   // Need fluid width here
}

h1 {
 white-space: nowrap;
 overflow: hidden;
 text-overflow: ellipsis;
}
<div id="container">
  <div class="column left">
    <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150" alt="">
  </div>
  <div class="column center">
    <h1>
     This is long text. If overflow use ellipsis
    </h1>
  </div>
  <div class="column right">
    <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150" alt="">
  </div>
</div>

Visit this fiddle for reference: http://jsfiddle.net/2Lp8d80n/

Any assistance would be highly appreciated.

Answer №1

To achieve the desired layout, simply apply flex: 1 and overflow: hidden to the .center column.

Furthermore, when setting flex: 0 0 350px;, there is no necessity to explicitly define the width property since it is fixed at 350px, essentially indicated by the flex-basis.

img {
  max-width: 100%;
}
#container {
  display: flex;
  max-width: 900px;
}
.column.left {
  flex: 0 0 350px;
}
.column.right {
  flex: 0 0 350px;
}
.column.center {
  flex: 1;
  overflow: hidden;
}
h1 {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
<div id="container">
  <div class="column left">
    <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150" alt="">
  </div>
  <div class="column center">
    <h1>
     LONG LONG TEXT LONG LONG TEXT LONG LONG TEXT
    </h1>
  </div>
  <div class="column right">
    <img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150" alt="">
  </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

What is the best way to detect when I switch to a different tab than a specified tab using HTML and jQuery?

Here is the HTML code I am working with: <div id="tabsWithStyle"> <ul> <li><a href="#data1">Data 1 TAB</a></li> <li><a href="#data2">Data 2 TAB</a></li> <li>< ...

AngularJS - Troubleshooting View Scrolling Problem with CSS

One issue I'm facing is that when the content within my view causes a scrollbar to appear, it scrolls into whitespace even though the view's overflow is hidden. I suspect it might be a CSS problem related to my positioning system. Unfortunately, ...

Personalized pop-up experience with AngularJS

I am currently working on creating a filter in AngularJS without relying on jQuery. To achieve this, I am using a custom directive to generate a popup that includes a checkbox. However, I have encountered a couple of issues. 1. I have created two popups u ...

Retrieve the ID of the image element using Jquery from a collection of images within a div container

I'm encountering a simple issue that I can't seem to solve. I am working on a basic slider/gallery with the following functionalities: 1) "If button 1 is clicked, image one will appear." 2) "Clicking on button 2 will make IMAGE 1 slide left and I ...

Incorporate a Bootstrap panel featuring a stylish border design and perfectly centered text

I am attempting to design two panels in Bootstrap with centered text and different fonts. Similar to the layout shown in the image below https://i.sstatic.net/aVGwV.png Here is my code: <div class="row"> <div class="col-lg-6&q ...

"Discover the secrets of flipping a webpage just like turning the pages of

I recently designed a basic website with 4 separate pages. The homepage includes navigation links for each page, such as - Page1 page2 Page3 Page4 My goal now is to create a feature where clicking on any of these links will open the corresponding page wi ...

Leveraging universal SCSS variables within an AstroJS endeavor

Hello, I'm a beginner when it comes to using AstroJS. In my project structure, there is a folder named styles inside the src folder. Inside this folder, there is a file called global.scss where I have defined some global SCSS variables in HEX format: ...

The CSS outline properties vary between input elements and input elements in focus

I'm encountering an issue with a box and its associated CSS outline style. When the box is focused, it should display a blue outline (which is working fine). However, upon form validation, if there is an error, the .error class is added which should c ...

Is it possible to adjust the spacing between items within a div to a precise measurement?

It may seem like a simple task, but I'm unsure of the best approach. In my header, I have 4 links along with a logo positioned to the left. All of these links are contained within a div called main-header-right. Is there a way to add spacing between t ...

Toggle the visibility of a div and reset the input field when there is a change

In my form, I have two input fields named 'Apartment' and 'Bachelor'. Depending on the selected value, certain divs will be shown. If 'Apartment' is selected, related divs and select fields for apartments should show. The issu ...

What are some ways to customize the appearance of Stripe credit card form fields?

I've successfully implemented stripe using this HTML code and Bootstrap 4. <div class="form-control" id="card-element"></div> As a result, I get the displayed output: https://i.sstatic.net/Aw653.png However, I am loo ...

Learn how to implement a feature in your chat application that allows users to reply to specific messages, similar to Skype or WhatsApp, using

I am currently working on creating a chatbox for both mobile and desktop websites. However, I have encountered an obstacle in implementing a specific message reply feature similar to Skype and WhatsApp. In this feature, the user can click on the reply butt ...

"Tailwind - where your brand shines with a sleek, modern logo that stands

I have a specific title width that I need to adhere to, and I'm looking to place a logo after the last word in the title. When the title is too lengthy, it wraps onto a second line. For example: My Title (insert logo here) Check out this CodePen us ...

The function elem.colResizable does not exist

I am attempting to create resizable table columns in AngularJS using the following directive: myApp.directive('colResizeable', function() { return { restrict: 'A', link: function(scope, elem) { setTimeout(function() { ...

When it comes to the CSS `:visited` pseudo-class, I have

I'm having trouble changing the color of the anchor tag and blurring the image after visiting the link. Despite my CSS code, only the color is changing and the image remains unchanged. Here's my CSS code: <style> .image123{ paddin ...

Tips for generating a <div> element with multiple children using a loop

section, I have configured a div element with a class named div class = "postWindow". When it comes to the HTML code, here is an example: <div class = "postWindow"> <div class = "userName">Initial Name</div> <div class = "p ...

Place a picture within a specified View

I am encountering an issue with my profile image in the header component. The source of the image is coming from the database as a string array. However, when I fetch the user picture from the database, it appears slightly cut off from the top, giving the ...

Aligning a label in the center of a horizontal layout's vertical axis

Struggling with centering a QLabel vertically in a QHBoxLayout. Here's the relevant part of my code: QFrame* topBar = new QFrame(); topBar->setStyleSheet("background-color: #2c3d50;border-bottom: 3px solid #2c92b6;"); topBar->setSizePolicy(QSiz ...

I'm noticing that my style.css changes are only showing up after a hard refresh, but then they revert back to an older version when I refresh normally

Apologies for the lengthy title. Here's the issue: I have a WordPress website with a custom theme and its corresponding child theme. Previously, updating the style.css file of the child theme would show the changes immediately after a website refresh ...

Allow the height of one DIV to dynamically adjust based on the height of another DIV

On my webpage, I currently have the following code: <div class="container-fluid"> @Html.Partial("_SearchLeftSide") @Html.Partial("_SearchRightSide") </div> The first partial contains the following content: <div class="col-sm-3" st ...