A trio of versatile sections within a box, one designed to accommodate text overflow

Trying to create a CSS layout where three texts are placed side by side without wrapping, but once the first text is too long, it needs to be truncated. Check out the image below for more details.

Methods I have attempted so far:

  • Floated positioning of texts in a row
  • Flexbox for positioning texts in a row
  • Using display: table-cell to position texts in a row

Unfortunately, when the first text exceeds the container's width, issues arise. Either the container or the child text becomes larger than intended, or the other two texts end up being cut off or hidden.

Any ideas on achieving a flexible layout as shown below? Both Case 1 (or any alternative) and Case 2 should work without knowing the width of the text.

Answer №1

Here is the code snippet:

 <div class="container">
     <div class="box1">
         Short
     </div>
     <div class="box2">
         LongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLong
     </div>
     <div class="box3">
         Short
     </div>
 </div>

 <style>
 .container{
     margin:10px;
     width: 400px;
     background-color:grey;
 }

 .container div {
     overflow:hidden;
 }

 .box1 {
     text-overflow: ellipsis;
     background-color:green;
     min-width: 20%;
     float:left;
     max-width: 60%;
     display: inline-block;
 }

 .box2 {
     background-color:red;
     width: 20%;
     display: inline-block;
 }

 .box3 {
     float:right;
     background-color:yellow;
     width: 20%;
     display: inline-block;
 }
 </style>

You can view the result here: http://jsfiddle.net/ramsesoriginal/utSgC/

The use of percentage-based widths allows for easy adjustments by setting the parent's width.

The third box in the example demonstrates how the layout adapts to longer content in the second and third boxes.

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

Angular error message: Trying to access the property 'name' of an undefined object leads to a TypeError

I'm having trouble phrasing this question differently, but I am seeking assistance in comprehending how to address this issue. The error message I am encountering is as follows: TypeError: _co.create is not a function TypeError: Cannot read property ...

Result of utilizing Bootstrap Radio buttons

Looking at the HTML snippet below, I am trying to display two lines of radio buttons. However, when I click on a radio button in the first line and then proceed to click any radio button in the second line, the result of the radio button in the first line ...

Is there a way to design a form that appears as though it's levitating above a div element?

I am new to web development and currently practicing by converting PSD designs into HTML pages. I am facing an issue where I need to create a form that appears to be floating on top of a div, with the form being taller than the div itself. Here is an illu ...

Is it possible to send information via the URL while using jQuery Mobile?

My mobile application utilizes an in-app browser to send information, such as deviceID, to my server via a URL. For instance, the browser opens a web-page (jquery Mobile): www.myserver.com/doWork.html#deviceID Within the doWork.html file on the server si ...

What are the steps to modify data within the root component?

I am currently working on a Vue project with vue-cli and routes. In my App.vue file, the template structure is as follows: <template> <div id="app"> {{Main}} <router-view></router-view> </div> </template&g ...

Create a scrollable Bootstrap table without impacting the layout grid system

Is there a way to create a scrollable table without impacting the grid system layout? How do I make a table scrollable while keeping the col-xs tag intact? <table class="col-xs-12"> <thead> <th class="c ...

Every time I attempt to create a detail page for a table, I am consistently greeted with an error message

Error: Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /var/www/2909kher/entabell/detaljer.php on line 23 <!doctype ...

Adjusting the size of content with CSS

I've been attempting to get an image to cover the entire screen on a device using CSS, but so far I haven't had any success. The image is within an :after pseudo element and content tag. Since it needs to be laid over the HTML, I can't use t ...

Add extra space to the dimensions of the div by incorporating padding

Showing my issue with an accompanying image: I am looking for a solution to include padding in the width: 50%; calculation. Currently, the first div's width is actually 50% + 2em because the padding was not factored in initially. Is there a way to i ...

Modifying a Flash Video through JavaScript

Similar Question: How can I change the source of a flash object using jQuery? UPDATE I have resolved the initial loading issue, so I removed that part from the code. I've created a flash player like this: <div id="video_content"><div i ...

Python code to extract text data from a table using XPath

Recently, I've been using requests and lxml to develop a simple API that can fetch a timetable from a specific website. However, being new to this, I'm struggling to extract any information beyond the hours. Despite experimenting with xpath code ...

Creating a responsive design with dual backgrounds using Tailwind CSS

I have a design in Figma that I want to convert to React using Tailwind CSS while maintaining 100% pixel-perfect accuracy. The design is created for a Macbook Pro 16 inch, which has a width of 1728px. However, I want to center the content within a customiz ...

Angular - Acquire reference to the <audio> element

Is there a way to access the methods of an audio tag within my component in order to implement play and pause functions based on click events? The current method I tried does not allow me to access the play() function. How can I correctly approach this? ...

Is it possible to modify the underline color while using the transition property in CSS?

One of the challenges on my website is customizing the navigation bar to resemble the BBC navigation bar. I want to change the border bottom/underline color using transition elements. Can anyone provide guidance on modifying the code to achieve this look? ...

Styling the tab view in PrimeFaces

I am currently working with the tab view feature in primefaces and I have encountered a couple of issues. 1) When using Internet Explorer, the tabs are displayed vertically instead of horizontally. However, it works fine in Firefox. FireFox : Internet E ...

Using Spring Boot RestController to Serve HTML Pages

I'm having trouble accessing the HTML page I created. Here is an overview of my project: This is the "IndexController" class: @RestController @AllArgsConstructor @RequestMapping(path = "/webpage") public class IndexController { @GetMapping(p ...

Understanding the significance of 'href = '<? = variable ?>' on an HTML/PHP webpage

I must admit, I have a slight inkling that I'll feel a tad foolish once it's clarified, but could someone kindly explain what the following statement accomplishes? href='<?= $authUrl ?>' This line is extracted from the Google AP ...

Securing Your Data with PHP and MySQL Password Protection

Currently, I am in the process of developing a web application that features a login and registration system. The application caters to two main types of users: clients and one admin. So far, I have successfully implemented a registration page for clients ...

What strategies can I implement to improve the efficiency of calling the PHP exec() function for pinging over 100 different hosts?

I have been experimenting with collages in an attempt to find a solution to the slow rendering issue I am facing with the results from my PHP function. The problem arises when I call the function multiple times for different hosts, causing significant dela ...

When setting the height to auto in Dreamweaver for a background image, no content will be displayed

I have been searching through several questions on this platform today in the hopes of finding an answer to my query, but unfortunately, I haven't had any luck so far. That's why I'm turning to you all for help. My current goal is to transi ...