The percentage-based max-width feature is experiencing difficulties in functioning properly

Having an issue with the "max-width" property in CSS on my website. There is a title that is limited to one line and uses the following property for overflow:

text-overflow: ellipsis;

Everything works fine and the overflow behaves as expected, but when I apply a percentage to the max-width property, the title's div does not shrink.

CSS:

.card-content-title {

  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;

  max-width: 80%;

  text-align: left;
  font-family: $roboto-condensed-regular;
  font-size: 18px;
  color: $inactive-text-color;

  margin-top: 13px;
  margin-bottom: 0;
  padding: 0;
}

HTML:

<div class="row">
    <div class="card-menu">
        <div class=" card-menu-item"></div>
        <div class=" card-menu-item"></div>
        <div class=" card-menu-item"></div>
        <div class=" card-menu-item"></div>
    </div>

    <div class="card-content">
        <div class="row">
           <div class="card-content-title">(title here)</div>
    </div>
</div>

Result:

Changing the max-width to pixels instead of percentages:

max-width: 200px

Result:

Is there a way to prevent overflow when using percentages?

EDIT: Here is the CSS for .row:

.row {
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-box;
    display: -moz-flex;
    display: -ms-flexbox;
    display: flex;
    padding: 5px;
    width: 100%;
}

Answer №1

Here is a snippet with two sections: one with a max-width of 50% and the other with a max-width of 200px.

Please make sure to include the closing div tag in your code.

.row {
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-box;
    display: -moz-flex;
    display: -ms-flexbox;
    display: flex;
    padding: 5px;
    width: 400px;
}

.card-content-title {
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;

  text-align: left;
  font-family: $roboto-condensed-regular;
  font-size: 18px;
  color: $inactive-text-color;

  margin-top: 13px;
  margin-bottom: 0;
  padding: 0;
}

.card-content-title-1 {
  max-width: 50%;
}
.card-content-title-2 {
  max-width: 200px;
}
<div class="row">
  <div class="card-menu">
    <div class=" card-menu-item"></div>
    <div class=" card-menu-item"></div>
    <div class=" card-menu-item"></div>
    <div class=" card-menu-item"></div>
  </div>

  <div class="card-content">
    <div class="row">
      <div class="card-content-title card-content-title-1">
        (here is the title here is the title here is the title here is the title)
      </div>
    </div>
  </div>
</div>

<div class="row">
  <div class="card-menu">
    <div class=" card-menu-item"></div>
    <div class=" card-menu-item"></div>
    <div class=" card-menu-item"></div>
    <div class=" card-menu-item"></div>
  </div>

  <div class="card-content">
    <div class="row">
      <div class="card-content-title card-content-title-2">
        (here is the title here is the title here is the title here is the title)
      </div>
    </div>
  </div>
</div>

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

Steps to showcase a HTML modal based on the outcome of a JavaScript/AJAX database query

Currently in the process of developing a Facebook game utilizing html and Javascript. With two modals on an html page (referred to as ModalA and ModalB), the goal is to link both modals to a single button, triggering the display of only one modal based on ...

What is the process of calling a function in my WordPress theme's functions.php file from an ajax handler?

I have a function in my theme's functions.php file that I'd like to execute using an ajax handler. An ajax handler is helpful for preventing the need to load the entire WordPress stack (including plugins) for each ajax request. functions.php f ...

Rows intersecting and stacking above one another

I designed a layout with some text and icons displayed in rows. While it appears properly on iOS, the rows overlap on Android. const criteriaList = [ { id: 0, title: 'Noor', checked: false }, { id: 1, title: 'Friends & Grades', ...

What is the best way to configure an EmailId validator in Angular 6 to be case insensitive?

My register and login page include a form validator pattern matching for the registration form. this.registerForm = this.formBuilder.group({ firstName: ['', Validators.required], emailId: ['', [Validators.required, Validators.patt ...

What is the best way to zoom in on an image and make it move off the screen as I scroll through my webpage?

I am working on a website design where I would like to implement an image zoom effect as the user scrolls down. Additionally, I want the image to move to either the left or right side of the screen as it goes out of view when scrolling to the bottom. While ...

Can menus in Vue.js be customized differently for various "pages"?

I am new to Vue and facing a challenge with a common component - menu - that needs to be styled differently on the "TOP page" compared to all other "pages". <template> <div> <menu></menu> <transition name="fade" mode="o ...

Choose an option from the dropdown list using ellipses

I am looking to truncate the dropdown list options with ellipsis, and when clicked on the ellipsis, users should be able to view the full option values. For instance, the dropdown list currently looks like this: <select id ="id"> <option ...

What is the best method for transforming a stream into a file with AngularJS?

Currently, I have a server returning a file stream (StreamingOutput). My goal is to convert this file stream into an actual file using AngularJS, javascript, JQuery, or any other relevant libraries. I am looking to display the file in a <div> or ano ...

Adjusting the empty image source in Vue.js that was generated dynamically

Currently experimenting with Vue.js and integrating a 3rd party API. Successfully fetched the JSON data and displayed it on my html, but encountering issues with missing images. As some images are absent from the JSON file, I've saved them locally on ...

Strategies for updating text within a DIV element without an ID, solely relying on a class attribute, by utilizing JavaScript injected into a WKWebView

I've encountered an issue while attempting to update the text within a DIV tag using JavaScript. The tag only has a class attribute, not an ID. I've attempted the following code: document.getElementByClassName('theClassName').innerHTML ...

Looking for a solution to align the header properly in your React app?

Struggling with aligning a header? The CSS property of the header is inherited from the app's CSS file. For example, in the image below, "Our Mission" is the header that needs to be left-aligned. Looking for some assistance here. You can find the app. ...

Incorporating CSS sprites within an <img> element

I have a sprite that contains various logos. I am trying to extract a specific logo using the following css .prog_logo { background-image:url('../../image/sprite_logo.png'); } .prog_logo_prime { background-position:0px -81px; width:52px; height: ...

Creating a dynamic number animation and generating content with Vue.js and SCSS

While exploring different methods for creating a number scrolling animation, I stumbled upon the following code snippet (written in SCSS and Vue): new Vue({ el: ".app", data: { number: 0 }, methods: { setNumber(e) { this.n ...

What is the best way to add multiple values to a single column but on separate rows?

Attempting to save the question and answer separately in different tables. Successfully stored the question text value, but encountering an error when inserting the answer value. Fatal error: Uncaught exception 'PDOException' with message ...

Ways to transmit variable values through a URL?

I have an issue where I need to construct a URL using variable data. { this.state.countries.map((country, key) => { return <a key={country.iso2}> <img src="https://www.countryflags.io/{country.iso2}/shiny/24.png" /> </a& ...

Stretchable navigation cell

I am working on a navigation bar called "nav" that consists of a "ul" and "li". I have specified the display property for the "ul" as table and for the "li" as table-cell. Setting the "ul" to take up the full width of the wrapper ensures proper alignment. ...

Stop unwanted clicking on inactive buttons in Angular

I want to make sure that disabled buttons cannot be clicked by users who might try to remove the disabled attribute and trigger an action. Currently, I have this code to handle the situation: <button [disabled]="someCondition" (click)="executeAction()" ...

The dynamic ID stops functioning once a row is deleted from the table

I have a table with feeSetting id containing dynamic data. I am able to add and remove rows from the table. The issue arises when a row is removed and a new row is added, as it overrides the unique ID of the last row. I need the table to generate unique ...

Leveraging semantic markup alongside a CSS framework

Are there any CSS/styling frameworks out there that can work with semantic markup while keeping file sizes relatively small? It seems like a classic case of the "three options, pick two" dilemma. Let me break it down. I want: A visual styling framewor ...

Using absolute positioning for child elements within a table cell division in CSS

Similar Question: Is it possible to position items relatively or absolutely within a display: table-cell? I am working with a display: table layout example. You can view the demo here. In the second panel, there is a #pos div that has a position: abs ...