Dealing with dynamic width and text-overflow within non-overflowing <div> elements

I'm experimenting with a style that gradually expands a border up to 300px, and then uses text-overflow: ellipses when the limit is reached. If you're interested in seeing what I'm working on, feel free to click here to visit a JSFIDDLE demo.

I'd like the longest message text to be cut off at 300px and display an ellipsis. For shorter texts, I want the border to shrink to fit the size of the text. Any suggestions or assistance would be greatly appreciated.

.border{ 
    background-color: #ffffff; 
    border: 3px solid #ffffff; 
    border-radius: 5px; 
    box-shadow: 0px 0px 10px #999999; 
    margin-left: 20px; 
    margin-top: 5px; 
    padding: 2px; 
    position: relative; 
    z-index: 4;
}

.border.small { 
    /* background-image: url('%Image(G3VISIF_EXP_BKGRD_SM)'); */
    box-shadow: 1px 1px 10px #999999; 
    background-size: 100% 100%; 
    height: 22px;
    width: auto;
}


.message { 
    color: #5c5d60; 
    font-family: Arial; 
    font-size: 17px;
    font-weight: bold;
    padding-left: 5px; 
    padding-top: 2px;
    white-space: nowrap;
    text-overflow: ellipsis;
    max-width: 300px;
    display: block;
    overflow: hidden;
}
<div class="border small">
    <div class="message">
        Is [GRIDREC:EMPLID] Equals 123456789012345678901234567890
    </div>
</div>

<div class="border small">
    <div class="message">
        Is Part Time
    </div>
</div>

<div class="border small">
    <div class="message">
        Recieves Full Benefits
    </div>
</div>

Answer №1

It's quite straightforward.

Here are a couple of methods (without altering your existing html structure):

1- To have the messages appear on separate lines while maintaining your current structure:

.expression {
    /* other styles */
    float: left;
    clear: left;
}

Example http://jsfiddle.net/L66fs1y5/2/

2- If it is acceptable for the messages to be on the same line within your current structure:

.expression {
    /* other styles */
    display: inline-block;
}

Example http://jsfiddle.net/L66fs1y5/3/

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

Webkit feature: Rounded border image overlay

One issue arises when applying a rounded border to an image in webkit browsers as the border ends up hidden behind the image. CSS img { border: 10px solid #000; border-radius: 100%; } HTML <img src="http://25.media.tumblr.com/tumblr_mbje ...

Using CSS to leverage the power of both Grid and Flex simultaneously

Help Needed: CSS Challenge! I'm not a fan of CSS and can't seem to crack this code conundrum. Here's what I want the end result to look like: https://i.sstatic.net/z06qO.png Current Situation: #newOrderControl { border-style: solid ...

Adjust the color quantity based on the item that is being hovered over

I have a unique challenge at hand: <table> <tr> <td class="order-delivered"><i>order</i><br/><i>delivered</i><br/> <a class="check-mark">✔</a& ...

What's the deal with the Cordova Splash Screen?

I am currently developing an app with Cordova and I am facing some challenges with implementing the splash screen for Android. The splash screen is working perfectly fine on iOS, but I am unsure of how to proceed on Android. Do I need to install a plug-in ...

Tips for positioning a button next to a text area

I am facing an issue with aligning my text area and button vertically on the same line. Despite my attempts, the button keeps getting pushed downwards. Can someone please provide me with a solution to align them properly? Thank you. Here is the HTML code ...

Displacement occurs when the input tag is eliminated

After some trial and error, I have discovered that removing the input tag from the label causes a change in the layout height. I am puzzled as to why this is happening. Could there be a special reason for this height alignment issue when an input tag is pl ...

Float to the right, left, and top of the grid

Here is the HTML structure: <div class="row"> <div class="cell left">A</div> <div class="cell left">B</div> <div class="cell right">C</div> <div class="cell l ...

Fixing the Responsive Menu Issues

In order to achieve the desired effect of making the text from menu and logo disappear when minimizing the menu, you can use the following approach: Create a function called `smallNav()` to handle the resizing of the sidebar container: function sm ...

Blurry text and icons in Bootstrap 3

Does anyone else notice a strange display issue with Bootstrap 3 fonts and glyphicons? It seems like the bitmaps and fonts are appearing blurry on desktops when using Firefox and Chrome, but everything looks fine on mobile devices. I've attached an ex ...

Handling a change event for a mat-datepicker in Angular 7 can be tricky, especially when its value is tied to an optional input parameter. Let's dive into how to

I've recently started working with angular development and encountered a challenge with a mat-datepicker. The value of the datepicker is connected to filterDate using [(ngModel)] as an @Input() parameter. I have implemented a handleChange event that e ...

Enhance Website Functionality with Dynamic Tables and Spreadsheet Features

Currently, I need to incorporate spreadsheet-like functions into a table on my website. Initially, I explored KendoUI but realized it might not be within my budget constraints. Is there a more affordable alternative available? Key features I require inclu ...

How do I use jQuery to animate a height increase where the added height is applied to the top of the element?

I am facing a simple issue that I need help resolving. The problem involves hidden content that, once expanded, needs to have a height of 99px. When collapsed, the container holding this content section#newsletter is set to be 65px in height. If you want ...

What is the best way to make a JavaScript cookie remember the state of a DIV?

Seeking assistance with a test site here that is currently in development. I am attempting to make the notification at the top remain hidden once the close button is clicked. Below is my current script: <style type="text/css"> <!-- .hide { displ ...

Establishing a secondary setTimeout function does not trigger the execution of JQUERY and AJAX

// Custom Cart Code for Database Quantity Update $('.input-text').on('keydown ' , function(){ var tr_parent = $(this).closest("tr"); setTimeout(function () { $(tr_parent).css('opacity', '0.3'); }, 4000); var i ...

Centered Navigation Bar Aligned with Header

I'm having trouble aligning my header vertically with the text in my nav-bar using Bootstrap 4.6. The nav-bar items are right-aligned, so the text isn't centered in the middle of the page like shown in picture 3. .jumbotron { background: #3 ...

Loop through each input element in the form to retrieve the Name and Value using Javascript

I have been honing my JavaScript skills lately, after relying heavily on JQuery in the past. Though I am quite experienced with jQuery, my knowledge of raw JavaScript is limited. I decided to take on the challenge of learning pure JavaScript just like I ...

Personalize scrollbar appearance in Mozilla Firefox and Internet Explorer

When it comes to customizing the scrollbar in chrome, CSS makes it easy: ::-webkit-scrollbar { width: 7px; } Unfortunately, this method does not have the same result in Firefox (version 38) and IE (version 11). I attempted the following code as an alter ...

Including Vuetify in my project has triggered a SecurityError, specifically relating to the CSSStyleSheet.cssRules getter being restricted from accessing cross-origin stylesheets

Looking to create a Vue application that opens a CKEditor component in a separate window, I managed to do so following the method outlined in this helpful post. I have even set up a Codesandbox demonstration to showcase the functioning example. However, u ...

Achieving perfect alignment of two elements using flexbox: centering one and aligning the other to the right

Can you help me with aligning two elements to the center and right edge using flex? I am trying to achieve a layout similar to the image. XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX https://i.sstatic.net/cvmHX.png CSS Styles .flex{ display: flex; justify- ...

Unable to add padding to <b> tag

Can anyone explain why the padding-top property is not taking effect for the <b> tag? Check out this link <b>hello world</b>​ b { padding-top: 100px; } ​ ...