Tips for shortening button text within a flex child element

I'm struggling to achieve a specific layout using flexbox. I require one child element that does not shrink, and two child elements that can shrink/grow and be truncated based on their content while considering the sizes of their content.

My current solution (using Tailwind CSS classes, although it's not crucial):

  <div class="flex items-stretch">
    <div class="flex-none">Lorem</div>
    <div class="flex-initial min-w-0">
      <div class="truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>
    </div>
    <div class="flex-initial min-w-0">
      <div class="truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut ut mollis tortor, ut volutpat lacus.</div>
    </div>
  </div>

This setup would result in:

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

This is precisely what I aim to accomplish. However, replacing the child div elements with button elements causes the text not to truncate anymore and the parent element overflows.

  <div class="flex items-stretch">
    <div class="flex-none">Lorem</div>
    <div class="flex-initial min-w-0">
      <button class="truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</button>
    </div>
    <div class="flex-initial min-w-0">
      <button class="truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut ut mollis tortor, ut volutpat lacus.</button>
    </div>
  </div>

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

What am I missing to enable text truncation for buttons in this scenario?

Here's the code snippet:

https://play.tailwindcss.com/mHCJZeG0IX

Answer №1

Set the maximum width of your button to 100%

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 guide to showcasing JSON data on a webpage using JavaScript

I am currently working on a SOAP WSDL invocation application in MobileFirst. The response I receive from the SOAP WSDL is in JSON format and is stored in the result variable. When trying to access the length of the response using result.length, I encounter ...

The z-index of the fixed header in FullPageJS is causing the section's content to be hidden

For my current project, I am incorporating FullPageJS and using a fixed top menu that adjusts its height based on the viewport size. On smaller screens, the menu items will be stacked on top of each other, while on wider screens, the menu items will be po ...

Pair of buttons triggering the submission of a form

I'm encountering an issue where I have 2 buttons in my form, one for submitting and one for going to the previous page, but both seem to be performing the same action. How is this happening? <div style="position:fixed; left: 50px; ...

How to open a new window in a separate desktop on macOS using Javascript

I am currently browsing my website on a Mac computer. I am interested in opening a new tab on the second desktop using Mission Control. Is this achievable? If so, could you please guide me on how to do it? After searching extensively online, I have been u ...

struggling to preserve form data using PHP and MySQL

I am facing an issue with a page that needs to display a form with checkboxes, save the results in the database, and then load the page with the checkboxes checked based on the stored data. Although I realize that my solution of floating "checked" is not ...

What is causing the chat-widget to display a null value for the style read property?

Could someone assist me with hiding the Widget-chat? I keep getting an error that the property of style is null. Any help would be greatly appreciated. Thank you in advance. document.getElementById("chat-widget").style.display='none'; ...

Animation will cease once the page is refreshed via Ajax

I'm facing a challenge with a problem that I can't seem to resolve. The issue lies in my use of this plugin for displaying random images. The only step left is to refresh the content within the div. However, every time I attempt to do so, the an ...

Steps for incorporating Bootstrap 5 pagination without using jQuery

Currently, I am working on incorporating pagination for cards using Bootstrap 5. My reference point is the following link: https://getbootstrap.com/docs/5.0/components/pagination/ While I can find the UI elements, I am struggling to come across a concrete ...

Displaying database records in custom fragments using Spring Boot and Thymeleaf

I'm struggling with displaying database records on a webpage in a specific format. To achieve this, I've created a thymeleaf fragment to act as a template for each record in my database. However, I can't figure out how to make these fragment ...

Proportional fluid image grid with responsive design

After implementing various media queries, I've managed to create an image grid using Bootstrap 4+ that looks great on specific devices and layouts. Here's the reference code: .cmd-three-img-container { position: relative; margi ...

Step-by-step guide on replacing image and text simultaneously with a single click

I'm currently attempting to update both my text and image upon clicking (specifically on mobile), but unfortunately, I'm encountering an issue. While I've successfully managed to change the image using the function I created, the text remain ...

Creating a navbar dropdown that is clickable on mobile devices and opens on hover on desktop is a simple way to improve

Utilizing Bootstrap 5 for my website creation, I am facing an issue with the navbar dropdown functionality. On mobile devices, the dropdown opens upon clicking but fails to close when clicked again. Meanwhile, on desktops, hovering over the dropdown works ...

Arrange a pair of div containers side by side on the webpage without the need to alter the existing

Is there a way to align these two div side by side? <div class="main_one"> <div class="number_one">Title A</div> </div> <div class="main_two"> <div class="number_two">Title B</div> </div> <div class=" ...

Sorry, but we are experiencing difficulties processing your request at the moment. HTTP ERROR 500: We are unable to locate the

My code seems to be functioning correctly when connecting to the database, but I'm encountering an error. Here is the code snippet: <?php include 'header.php'; ?> <!DOCTYPE html> <html> <head> <t ...

Locating the nearest image within a specific div using jQuery's find method

Here is the HTML I used on my page: <div class="edge-img-sec"> <img src="img1" alt="edge-icon" class="edge-icon1"> <img src="img2" alt="right-icon" class="edge-icon1-right"> </div> <div class="edge-img-sec"> < ...

Tips for making your inner content as wide as possible

I'm currently working on developing collapsible tables, where an outer and inner table are displayed for every row that is clicked. This is the code I have implemented: HTML: <table class="table outerTbl mb-0"> <thead> <t ...

What is the best way to create floating text that appears when clicked, similar to the mechanics

https://i.stack.imgur.com/nRKG1.jpg Upon clicking the "big cookie" in my game, a popup appears displaying the number of cookies earned (like +276.341 septillion in this image). The popup slowly moves upward and then fades out. I successfully incorporated ...

Generate dynamic maps that are exportable to HTML format

I've utilized Leaflet to produce engaging interactive maps in R. However, I'm encountering an issue when trying to export the maps - the background map appears grey after exporting. library(leaflet) library(htmlwidgets) m <- leaflet(data.fra ...

Using relative URLs in HTML to navigate a specific group of requests via nodejs middleware

Alright, so let me dive into the details of my current dilemma. Essentially, I have a project implemented in node that serves a specific purpose. It's a website utilizing express, jade, and stylus. I have configured the routing for static content in ...

What is the best way to say hello using jQuery?

I need some assistance with a task that involves entering my name into an input field, clicking a button, and having an h1 tag display below the input saying Hello (my name)! Unfortunately, I am struggling to figure out how to achieve this. Below is the H ...