Text that is inside a grid item will not be cut off using an ellipsis

For some reason, the ellipsis isn't showing up as expected. Instead of truncating with an ellipsis, the text just goes to the next line.

text {
   display: inline;
   overflow: hidden;
   text-align: center;
   text-overflow: ellipsis;
}

grid {
   width: 200px;
   height: 3em;
   border: 1px solid #000000ff;
   display: grid;
   grid-template-columns: 1fr;
}
<grid><text>This text should display an ellipsis instead of wrapping!</text></grid>

Answer №1

apply the CSS property white-space: nowrap; to prevent wrapping of text

text {
   display: inline;
   overflow: hidden;
   text-align: center;
   text-overflow: ellipsis;
   white-space: nowrap;
}

grid {
   width: 200px;
   height: 3em;
   border: 1px solid #000000ff;
   display: grid;
   grid-template-columns: 1fr;
}
<grid><text>This text should display an ellipsis instead of wrapping!</text></grid>

Answer №2

To prevent text wrapping, add the nowrap CSS property to the text:

text {
       display: inline;
       overflow: hidden;
       text-align: center;
       white-space: nowrap;
       text-overflow: ellipsis;
    }
    
    grid {
       width: 200px;
       height: 3em;
       border: 1px solid #000000ff;
       display: grid;
       grid-template-columns: 1fr;
    }
<grid><text>This text should display an ellipsis instead of wrapping!</text></grid>

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

What is a way to include a ":hover" effect in Elm without relying on signals?

I'm looking to apply a :hover style to an element using Elm's HTML library. I've considered using Signals and Sets to manage selected nodes, but it feels like overkill for such a simple task. Another option is adding an external stylesheet, ...

What is the best way to stop div animations when clicking with jQuery?

Upon loading the page, a div animates automatically. There is also a button present. When the button is clicked, I would like to create a new div and animate it the same way as the first one. However, when this happens, the position of the first div also ...

Issue with wrapper not aligning correctly at the top of the screen

I keep noticing a gap between my wrapper and the top of the page. Despite trying multiple solutions, none seem to work for me. The background image covers the entire background and is aligned at the top perfectly, but the wrapper with its own background a ...

Sorting through mongoose information on the front end using EJS depending on a dropdown pick

Beginner embarking on my inaugural project here. I have developed 2 Mongoose schematics and models for managing categories and products. The products are nested within the corresponding categories model. Using Node and Express, I successfully sent all ca ...

Is it possible to validate only the fields that are currently visible using HTML form validation

I need a solution for excluding hidden fields from HTML form validation. My situation involves having two groups of form fields, each with some required attributes. Depending on user selection, one group may be hidden, and those fields should not contribut ...

Ways to adjust the text size in jqGrid?

The current theme is ui-lightness. How can I adjust the font size within the grid? Your suggestions are appreciated. Many thanks. ...

Using CSS backdrop-filter to create a unique blurred border effect for your web elements

In my quest for achieving unique visual effects, I have been experimenting with the backdrop-filter and element borders. While it is easy to create an element that blurs its background, I am facing challenges in making the filter affect only the border are ...

Customizing the colors of the Input field in the Material UI Text Field component with CSS styling can elevate the overall

import { TextField } from "@mui/material"; import { FunctionComponent } from "react"; interface IProps { type: string; label: string; color: | "error" | "primary" | "secondary" | &quo ...

The function .click does not function properly when used with an anchor element within a figure tag

In my JavaScript-loaded figure, there is an image description and two buttons. Sometimes the description contains a link with a fig attribute, like this: <a fig="allow" href="#tt5">[1]</a> If the anchor is not in a figure and has a fig attrib ...

CSS for a Div with a Subtle Curve at the Bottom

Is there a way to achieve this specific shape using CSS? I attempted to use the following resources, but they didn't provide me with the desired outcome. Curved border with stroke in pure CSS? http://jsfiddle.net/ECHWb/ .banner-img{ height: 661p ...

Sidebar misalignment

Apologies in advance for what may seem like a trivial question, but I have been grappling with this all day and can't seem to find the solution. I've tried adding and removing divs without success. To make things easier, I've created two liv ...

In PHP, the use of ul, li, class, and

I have searched high and low, but unfortunately the answers provided by others did not alleviate my problem. Instead, they caused even more confusion. I am currently working on a small project for my website and attempting to convert it to PHP in order to ...

Issues with the functionality of jQuery append and AngularJS ng-if not functioning

In my application using checkboxes, I control the visibility of charts with the ng-if directive and implement drag-and-drop functionality with angular-Dragula. The use of ng-if is essential for me as it allows me to manipulate visible div IDs and organize ...

Using Sweet Alert to enhance the user confirmation experience on your website

I need to replace the standard confirm dialog with a customized one using Sweet Alert. The JavaScript function I want to use is located in the MasterPage. function checkDelete() { swal({ title: "Are you sure?", text: "You will not be able to r ...

Issue with ng-bind-html not properly rendering content within audio tag

Currently, I am working with a variable called result.questionText. It currently holds the question: "<i>How many times are the hands of a clock </i>at right angle in a day?<audio controls ng-src="media/abc.mp3"></audio>". Instead o ...

Saving the name and corresponding value of a selected option element into separate fields using Angular framework

I have implemented the following code to generate a select field. The ngModel is successfully updating the value, but I am also looking to capture the name of the selected option and store it in a different field. Is there a solution to achieve this? ( & ...

Tips for creating a vertical Angular Material slider with CSS

Attempting to modify the angular material directive to render vertically has been a challenge. I experimented with using transform:rotate in the CSS, however, it resulted in the slider behaving and rendering differently. md-slider { position: absolute ...

Interconnected HTML div values impacting one another

Forgive me for the not-so-great title, as I am unsure of what this particular HTML coding method is called. That's why I am asking this question in the first place. I've written some code and I need to know what type of coding practice this is. ...

Hierarchy-based dynamic breadcrumbs incorporating different sections of the webpage

Currently in the process of developing a dynamic breadcrumb plugin with either jQuery or Javascript, however I am struggling to implement functionality that allows it to change dynamically as the page is scrolled. The goal is to have a fixed header elemen ...

Solve the problem with SCSS at the component level in NextJS

I've decided to transition my regular React app to Next.js. In the past, I would simply import SCSS files using: import from '.componentName.scss' However, now I need to import them using: import style from 'componentName.module.scss ...