What is the reason why the `text-overflow: ellipsis` is not functioning properly?

I can't get this overflow ellipsis to work properly. The documentation examples all seem correct, so what am I missing?

Check out the fiddle

p {
  width: 100px;
  height: 100px;
  word-break: break-all;
  border: 1px solid blue;
  overflow: hidden;
  text-overflow: ellipsis;
}
<p>
  (long string of text)
</p>

Answer №1

Make sure to include the white-space: nowrap; property and note that word-break: break-all may not be necessary in this context.

p{
  width: 100px;
  height: 100px;
  border: 1px solid blue;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
<p>
Some long text will be truncated with an ellipsis 
</p>


If a long word without spaces is present, you might not need white-space: nowrap;

p{
  width: 100px;
  height: 100px;
  border: 1px solid blue;
  overflow: hidden;
  text-overflow: ellipsis;
}
<p>
ssssssssssssssssssssssssssssssssssssssssssssssssss
</p>

Answer №2

To achieve the dotted effect when text overflows the width, we are using the CSS properties text-overflow: ellipsis; and white-space: nowrap;. It is important to include white-space: nowrap; for the dotted effect to work correctly.

p{
          width: 100px;
          height: 50px;
          border: 1px solid red;
          overflow: hidden;
          text-overflow: ellipsis; 
          white-space:nowrap;
        }
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</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

The button's size shrinks significantly when there is no content inside

When text is absent, the button shrinks in size. I am utilizing an angular model to bind the button text: <button type="button" class="btn btn-primary" ng-bind="vm.buttonText" tooltip="{{vm.tooltipText}}" ></button> I prefer not to apply any ...

Make sure that the HTML5 application is fixed inlandscape mode

I'm in the process of developing a basic HTML5/CSS3/Javascript application that needs to be compatible with all major mobile platforms - android, ios, and windows-phone. My goal is to have the app only function in landscape mode, even if the user hold ...

What is the method for inserting an image into a designated container in HTML?

I created a slideshow in the top row and have added two containers below it. However, every time I try to include an image instead of text in the container, the image ends up overflowing the container and takes over the entire page. How can I ensure that t ...

Using htaccess to eliminate PHP and HTML files from your website

I've been scouring the Internet for quite some time now, trying to find a working htaccess file for my website. I'm using CuteNews, a news CMS that offers URL rewrite functionality. However, when I enable URL rewriting, it causes my news pages to ...

The email submission function in my PHP form seems to be malfunctioning. I must be overlooking something

Having an issue with my PHP form, it's only sending field names instead of data to the email address. Here is a simplified version of the code: <?php $ToEmail = 'example@example.com'; $EmailSubject = 'Site contact form'; $ma ...

Passing a variable to the render method in a PDF document

I'm currently working on a project with Django where I need to convert an HTML monthly report into a PDF. The data for the report is retrieved from a database based on the selected month. I am facing an issue in sending the selected month from the HTM ...

Tips for changing between two texts within a button when clicked

Seeking a solution for toggling between two different texts inside a button when making an ajax call, with only one text displayed at a time. I'm facing difficulty in targeting the spans within the button specifically. Using 'this' as conte ...

JS script for clicking various icons on a webpage that trigger the opening of new tabs

I am working on a webpage where I have 9 icons with the same class. I am trying to write JavaScript code that will automatically open all 9 icons when the webpage loads. I tried using the code below, but it only clicks on the first icon and stops. let ...

New feature in Bootstrap 5: Fixed navigation with smooth scroll effect

Recently, I made the switch from Bootstrap 4 to Bootstrap 5 for my template. Surprisingly, I didn't encounter this issue with Bootstrap 4. Initially, I suspected that adding a flex container inside the navbar might be causing the problem, but that doe ...

Reliably analyzing text to generate unprocessed HTML content

My input text in a textarea is structured like this: This is some sample text./r/n /r/n This is some more sample text. I want to format it for display as follows: <p>Here's some text.</p> <p>Here's some more text.</p> ...

Difficulties encountered when trying to interact with buttons using JS and Bootstrap

I'm working with a Bootstrap 5 button in my project and I want to access it using JavaScript to disable it through the attribute. Here is the code I've been testing: Script in Header: ` <script> console.log(document.getElementsByName(& ...

Enhance card design by adjusting appearance based on container size in Bootstrap

I need to display different views of cards depending on the size of the device. The card style should adjust according to the width of the container. For larger devices, I have the following card style: <div class="col-lg-3 col-md-4 col-sm-6 portfolio ...

Illuminate the current page

I have been working on a website with around 20 pages that all have a side navigation bar. To make it easier to manage, I decided to centralize the links in a JavaScript (JS) file and include it on each HTML page. This way, any changes can be made quickly ...

Tips for shifting an image upwards and extending it beyond one section while keeping the other section unaffected

Struggling all day while designing a CSS site, trying to hide one part of an image when it overflows and keep another part visible, in addition to moving the image up and down. Here's the HTML code snippet: <section class="next-gen"&g ...

Struggling with applying mixins

Is it possible to select only the top border using this mixin? Currently, I only need a top border but would like to have the option to use others in the future. Using separate mixins for each side of the border seems inefficient. .bordered(@top-width: 1 ...

"Enhance user experience: Utilizing multiple dropdowns with the power

I found a helpful tutorial that I am currently following - Upon examining the demo - , I noticed that the second dropdown only appears once the first selection is made, and the same applies to the appearance of the third dropdown based on the second choic ...

Border becomes dashed when dragging and dropping

I am working on enabling drag and drop functionality for users. When an item is lifted from its original position, a gray dashed box should appear in its place. As the item is moved closer to another spot, the containers adjust to create a target area (gra ...

Vue.JS behaves differently on Firefox and Safari compared to Chrome and Edge by not hiding the scrollbar

Currently I am dipping my toes into frontend development using Vue.JS and Vuetify. One of my objectives was to hide the scrollbar (even though I know I can't completely delete it). I found a code snippet that should achieve this goal, which is include ...

Tips for Customizing the Width of Your Material UI Alert Bar

At the moment, I have refrained from using any additional styling or .css files on my webpage. The width of the Alert element currently spans across the entire page. Despite my attempts to specify the width in the code snippet below, no noticeable change ...

When working with basic shapes such as "rect" or "circle," the inline SVG may not be displayed

This is the code we are using to style our checkboxes: .checkbox-default { display: inline-block; *display: inline; vertical-align: middle; margin: 0; padding: 0; width: 22px; height: 22px; background: url('data:image/ ...