Learn how to showcase columns with diverse styles using the power of flexbox!

How can I create a paragraph element with 3 columns?

.foo {
  display: flex;
  align-items: center;
}
.column {
  border: 3px solid blue;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
<p class="foo">
  <span class="first column">first</span>
  <span class="second column">second</span>
  <span class="third column">third</span>
</p>

Here are the rules:

  • All 3 columns should display in a single row, even if they contain large characters.
  • The first column's max-width is set to 70%.
  • The second column's max-width is 50px.
  • If the first and second columns fill up the entire row, the third column may not be displayed.

I am struggling with using flexbox to achieve this layout. Could someone please provide a solution?

Answer №1

.foo {
    display: flex;
}

.first  { flex: 0 1 70%; }        /* cannot expand, can shrink, maximum width 70% */

.second { flex: 0 1 50px; }       /* cannot expand, can shrink, maximum width 50px */

.column {
    border: 1px solid blue;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
<p class="foo">
    <span class="first column">first first first first first first first first first first first first first first first first first first first</span>
    <span class="second column">second second second second second second second second second </span>
    <span class="third column">third third third third third third</span>
</p>

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

Using Powershell to divide HTML elements

I have a unique HTML file that I created myself (stored locally) where all the content is on one long line: <html><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>server - path</ ...

Activate unresponsive state when clicked

Struggling to implement a mobile responsive menu, my primary issue is the navigation buttons not toggling upon clicking. Here's what I have so far in terms of HTML and JQuery: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery. ...

Navigation issues in Internet Explorer appear to be causing problems

I've been working on a new website template design and decided to incorporate a click navigation menu for added functionality (with a javascript fallback for accessibility). I found the menu design on Toddmotto.com and it worked perfectly in most bro ...

Transform a text node into an HTML element with the help of JQuery

Consider this HTML snippet: <div> Lorem ipsum <span>dolor sit</span> amet <span>consectetur adipiscing elit</span> eiusmod tempor </div> To select the text nodes [Lorem ipsum, amet, eiusmod tempor], ...

Font Awesome icons displayed using the <i class="icon-ok"></i> markup are not styled correctly and do not respond to events in Chrome

I implemented Font-Awesome, an iconic font designed for use with Twitter Bootstrap. Here is the markup: <i class="icon-remove reset-preference-button"></i> And here is the CSS: .reset-preference-button { cursor: pointer; } For JavaScript f ...

Is it possible to utilize a function to manipulate the [checked] attribute of a checkbox and toggle it between true and false?

I'm trying to update the checkbox's [checked] property by calling a method, but even though the method is being called, the checkbox status doesn't change. HTML <div*ngFor="let vest_style of VEST_STYLE"> <input type="checkbox" ...

Maintain the basic structure while ensuring divs are properly aligned

Behold, my div structure! ONE // at the top level TWO THREE // two divs side by side in the middle level FOUR // residing at the bottom <div id="ONE"> <div></div> <div><img src="logo.png"></div> </div> < ...

What is the best method to override the CSS transition effect with JavaScript?

I am trying to implement a CSS transition where I need to reset the width of my box in advance every time my function is called. Simply setting the width of the box to zero makes the element shrink with animation, but I want to reset it without any animati ...

The Battle of Semantics and Manipulating the DOM

How do you feel about using semantic markup versus DOM manipulation? Consider this example where there is an error message displayed under a field: <label for="email">Email:</label> <input type="email" name="email" id="email"> <div c ...

What is the reason for initializing this Knockout.js component in a seemingly random order?

I am feeling completely lost... Currently, I am working on creating a list using Knockout.js components, templates, and custom elements. However, I am facing an issue where the steps I define in my Viewmodel are being initialized in a random order within ...

"Utilize Bootstrap 4 to create a 5-column row layout featuring lengthy text

I'm familiar with how bootstrap 4 uses col instead of col-xs, but I've encountered an issue. When the text within a column is too long to fit on a small screen, the columns begin to stack below each other. Is there a way to prevent this and set t ...

Enhanced Firefox functionality with support for multiple columns

It has come to my attention that Internet Explorer 9 and older versions do not support multiple columns. However, even with the latest version of Firefox, I am experiencing issues with this website loading correctly. Do you have any insight into what might ...

Deciphering image coordinates provided for incorporating an animated image component into a form

Is there a way to store the X:Y coordinates of a user click on an animated image by examining the php $_POST array? My issue is that I am able to retrieve input submission data from static images, but not from the animated one. Below is the full HTML page ...

How to Implement a Dropdown Menu in HTML and CSS for Navigation Bars

Currently, I am in the process of creating a website at www.bossfakeid.co.uk. I am looking to add a dropdown menu to the "Products" section of the navbar. I found a dropdown menu solution that I would like to implement from this link: http://codepen.io/wil ...

Responsive design in Android does not function as intended

My goal is to create a responsive design for my website, but I am encountering issues with importing the CSS files into the HTML. When I try to view the site in both the Windows version of Chrome and the Android version, all I see is a white screen. I am c ...

Struggling to locate the reCAPTCHA button using Selenium

My current challenge involves dealing with a recapture using selenium. I need to locate it on the page and click on it, but I'm unable to find it even though it's visible on the page. Here's my code: def capthcha(url = "https://google. ...

A method for automatically refreshing a webpage once it switches between specific resolutions

On my page www.redpeppermedia.in/tc24_beta/, it functions well at a resolution of over 980px. However, when the resolution is brought down to 768px, the CSS and media queries alter the layout. But upon refreshing the page at 768px, everything corrects itse ...

Having difficulty in successfully transmitting a dictionary via AJAX (POST) to Python (Django views) resulting in an empty dictionary every time

When I include this script in the head of the HTML : <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> and then use a button to call a function: <div> ...

Fluidity in CSS Video

I'm currently working on developing a dynamic video display component for my personal portfolio website. The main concept involves showcasing a mobile application video placed on top of a phone mockup within a designated container. My challenge lies ...

Best practice for injecting dynamic HTML using .ajax() call

Here is an example of a successful JSON Facebook Graph API request that retrieves data objects and displays their page-id pictures inside `img` tags within the `#results` div. success: function(res){ console.log(res); ...