Create a span in the middle with an ellipsis that seamlessly integrates with an icon on the left

I am looking to incorporate ellipsis into li.text, while still maintaining the presence of the right span (which contains numbers) and the spacing (padding) between the number span and the text span.

Is there a way to achieve this?

.right {
  float: right;
  padding: 0 8px;
}

.menu {
  width: 155px;
  border-right: 1px solid #ccc;
  list-style-type: none;
}

body {
  font-family: "Segoe UI", "Open Sans", Helvetica, Arial, sans-serif;
}
a {
  text-decoration: none
}
    .p {
     width: 155px;

      white-space: nowrap; 
      overflow: hidden;
      text-overflow: ellipsis;
      display: inline-flex;
    }
      .text {
        white-space: nowrap; 
        overflow: hidden;
        text-overflow: ellipsis;
        width: 45%;
        padding-right: 16px;
      }
      .right {
        width: 10%;
      }
<link href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet"/>
<ul class="menu">
<li class="" data-action="switchFolder" data-sign-in="false" id="inbox">
<a href="javascript:void(0);">
            <div class="p">
   <i class="icon ion-ios-filing-outline"></i>
   <span class="text">This is a very long element that wil exceed limit</span>
   <span class="right">429</span>
            </div>
</a>
</li>
</ul>

Expected outcome:

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

Please note the spacing between 429 and text. I have made several attempts but it seems that they end up too close to the 429. Also, no matter what I try, it keeps breaking to the next line because of the icon.

Answer №1

To ensure you achieve the desired outcome, make sure to utilize inline-flex when setting a width of 100%:

.text {
  width: 100%;
  padding-left: 5px;
}

.right {
  width: 10%; /* omit this line */
}

.right {
  float: right;
  padding: 0 8px;
}

.menu {
  width: 155px;
  border-right: 1px solid #ccc;
  list-style-type: none;
}

body {
  font-family: "Segoe UI", "Open Sans", Helvetica, Arial, sans-serif;
}
a {
  text-decoration: none
}
    .p {
     width: 155px;

      white-space: nowrap; 
      overflow: hidden;
      text-overflow: ellipsis;
      display: inline-flex;
    }
      .text {
        white-space: nowrap; 
        overflow: hidden;
        text-overflow: ellipsis;
        width: 100%;
        padding-left: 5px;
        padding-right: 16px;
      }
      .right {
        /*width: 10%;*/
      }
<link href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet"/>
<ul class="menu">
<li class="" data-action="switchFolder" data-sign-in="false" id="inbox">
<a href="javascript:void(0);">
            <div class="p">
   <i class="icon ion-ios-filing-outline"></i>
   <span class="text">This is a very long element that wil exceed limit</span>
   <span class="right">429</span>
            </div>
</a>
</li>
</ul>

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

Select only the top-level items in a dropdown menu using jQuery

Wondering how to create a fade effect that only triggers when hovering over the parent LI's without affecting the items in the dropdown menu? Any suggestions or solutions? Tried numerous examples with no success, struggling to make it work and gettin ...

CSS with three columns: the middle column has a fixed size, while the right and left columns

I am attempting to create a 3 column layout with specific requirements: The middle column is fixed at a width of 660px The left and right columns should each take up half of the remaining space, but have a minimum width of 120px The middle div need ...

Reduce the value in the database when a button is clicked using PHP

I am currently working on a carpooling website and I could really use some assistance. I have implemented a button that, once clicked, should decrease the number of available free spaces in the car by one (meaning the person who clicks it will reserve a ...

Performing a validation on data fetched using a .load() function

I've been struggling with a persistent issue that I just can't seem to solve. So, here's the situation: I have a blog post on a CMS that I'm developing. The content is saved within a div with its own unique ID. When the user clicks an ...

I'm having trouble getting my modal to open, it just displays the information on my page instead

I am encountering some difficulties with my model window. I would like it to open a modal that shows a larger version of the photo and description when the thumbnail is clicked. However, I have not been able to get it to work properly. The only time it pop ...

Guide to making a split background color design using only CSS

Looking for some help in designing a footer for a website with a split color design featuring two overlapping triangles. Any creative ideas are welcome! Thank you! https://i.sstatic.net/stoqy.png I tried to achieve this effect using the following code: ...

Ways to update a component's state by clicking a button located on a different component

Seeking help with changing a parent state value when clicking a button. Although there are numerous similar queries out there, I'm really struggling to grasp the concept. I've attempted lifting the state up but haven't quite nailed it yet. ...

Can you recall the name given to characteristics that do not have any value assigned to them (e.g. "checked" and "selected")?

There is a specific group of attributes in HTML that do not accept a value. For example, the checked attribute for the <input> tag and the selected attribute for the <option> tag fall into this category. Do you know what term is used to refer ...

A New Approach to Initializing Web Pages in ASP.NET (with a Surprising Twist)

Well, I've encountered quite the puzzling issue with a project I'm working on (it could even make it to the Daily WTF), and I'm hoping for some help in finding a solution. (Apologies in advance for the lengthy explanation...) About a month ...

Adjust the scrollTop of the tab-content when navigating between different tabs

When I scroll through the content of menu1 and then click on the menu2 tab, the content for the menu2 tab is displayed. However, I am facing an issue with changing the scroll position of the tab content so that it is visible from the top. I attempted to u ...

Having trouble implementing render props for a toggle button that reveals/hides child components

My goal is to display or hide a couple of child components based on a toggle click using the original HTML structure provided. However, I am encountering an issue where the EditToggle link needs to be displayed next to the h2 element inside the "subtitle-c ...

When a td element is clicked, the Textbox will also be clicked

Similar Question: Dealing with jQuery on() when clicking a div but not its child $(oTrPlanning).prev().children('td').each(function () { this.onclick = setCountClick; }); When a TD element is clicked, the function setCountClick() i ...

Creating a WordPress Infographic: How to Design a "Wide" Graphic

I have a question for those who are experienced with infographics. I'm in the process of getting an infographic designed for my blog and I've noticed that some websites have a feature that allows the infographic to expand to full width when you c ...

The background-size property in CSS does not seem to properly display on iPhones

Hello there! I'm facing an issue with my CSS code when it comes to displaying the image on Safari browser. It works perfectly fine on other browsers, but for some reason on Safari, the image doesn't show up correctly. I tried using a media query ...

The submit button is not reading the JavaScript file for validation and instead goes directly to my PHP file

**Hello, I'm new to Stack Overflow. My submit button is not reading the JavaScript file I created; instead, it goes straight to the PHP file without validating the input fields first in the JavaScript file. I've been stuck here for hours and can& ...

Ways to ensure that floating blocks remain in the same row using CSS

Check out my demo here: http://jsfiddle.net/3c40tafe/1/ Is there a way to align the icon, file name, and description in a single row? The icon and title should have fixed widths, while the description paragraph should take up the remaining width. Here&ap ...

The server attempted to transfer the resource as an image, but it was interpreted with the MIME type text/html

Since updating to the new version of go appengine, I've been having trouble loading images into a page. It used to be straightforward before, but now when I compile the code and launch the app in the browser, I get this message: Resource interprete ...

Avoiding HTML Encoded Characters when sending button or form submissions

When a user clicks a button that uses the GET method, I need to send multiple values at once. To achieve this, I am using an argument in the following way: $argument='var2=value2&var3=value3'; echo "<button value='value1&$argument ...

What could be causing certain items in my Bootstrap navbar to be hidden on mobile screens?

When I view my website on mobile devices, only the logo appears in the navbar, not the other elements. Can you help me troubleshoot this issue? NavBar HTML Code: .navbar-logo { width: 93.75px; height: 23.5px; margin-left: 10rem; } .navba ...

What is the best way to utilize a JavaScript variable as a background within an inline style sheet?

I have a fun project for this evening - I am trying to make my website load a different background image every time the page is refreshed. Earlier on in this project, I managed to make the background interact with window size and screen resolution similar ...