Text overflow doesn't seem to be functioning properly when using a horizontal box-orient in a box

I am having trouble making the text in my box display properly render an ellipsis. It is currently overflowing beyond the containing element.

HTML:

<div class="outer hbox">
  <div class="hbox left-container">
    <div class="label no-wrap box-centered">Col1</div>
  </div>
  <h1 class="label no-wrap">really long title really long title really long title really long title really long title really long title really long title really long title really long title</h1>
</div>

CSS:

.outer {
  width: 400px;
  border: 1px solid black;
}
.hbox {
  -moz-box-orient: horizontal;
  -webkit-box-orient: horizontal;
  box-orient: horizontal;
  display: -moz-box;
  display: -webkit-box;
  display: box;
}
.left-container {
  border: 1px solid red;
}
.no-wrap {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
h1 {
  border: 1px solid green;
}

An example can be viewed here: http://jsfiddle.net/bmclachlin/Sq7Xa/

I have attempted different solutions such as wrapping the h1 in a div or changing it to a different element, but nothing seems to solve the issue. I feel like I might be overlooking something obvious, any suggestions?

Please note that this code is produced by a JavaScript library called qooxdoo, limiting my ability to make extensive structural changes. However, I do have the option to switch the h1 to a different element or wrap it in a div if necessary.

Answer №1

the h1 element is being treated as a single long line of text due to the no-wrap property, causing it to take up more space and not allowing overflow. To address this issue, you can use the following CSS:

.no-wrap {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}

Check out this example on JSFiddle for reference.

This will force the h1 element to take the full width of its parent container and allow overflow.

An alternative solution would be to specify the widths of both elements explicitly, like in this modified code on JSFiddle, although there may still be some minor inconsistencies due to borders.

If maintaining the border is crucial, consider using either the box-sizing: border-box; property on the h1 element (check compatibility at Can I Use) or adding an additional div within the h1 element as shown in this code snippet on JSFiddle.

In conclusion, simplifying the code by revising the usage of properties like display: box; might provide a more straightforward solution to the problem at hand.

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

Extension for Chrome - view source of current webpage

I'm attempting to develop my chrome extension to extract the current page source and identify the current URL, as seen in this example. If I were to visit https://www.google.com and the page source contains google I want my extension to display a ...

Safeguard your contact information on the screen

On my classified website, I have concerns about the contact numbers being displayed as plain text in the product details page. This makes them visible to search engines. Is there a way to protect or display phone numbers as images to keep them hidden fro ...

Directly target images within a jQuery slideshow

There's a script I really admire for its functionality: One thing that I'm curious about is whether it's possible to directly target each image in the slideshow. For example, can I have a hyperlink that says 'Image 3' and when cl ...

Is there a way to make a sass file universally accessible without having to import it into every file and causing an increase in bundle size?

Question How can I efficiently import variables.scss globally without the need to duplicate them in every file and reference them in my build instead of importing? Setup I am using Vue2 with laravel-mix, where I have imported index.scss in my main.js ...

Changing HTML dynamically does not trigger the ng-click event within ng-bind-html

I have developed a custom directive that can display messages along with rendering HTML content that may contain Angular attributes like buttons, anchor tags with ng-click attribute, and more. index.html: <ir-error-panel status="status"></ir-err ...

How to Customize Auto Complete Background Color of Selected Items in Bootstrap 4 Input Controls?

I'm currently struggling to figure out how to override the default white background color of a form control's autocomplete in Bootstrap. The white background doesn't align well with my dark theme. Whenever I enter something into an input fi ...

What is the best way to assign a jQuery variable to a PHP variable?

After spending some time searching and working on it, I still can't figure out the answer to this straightforward question. Here is the code I have been struggling with. <script> function calculate() { var total = (parseInt($('#stude ...

A guide to eliminating missing tags from HTML code using Asp.net

There have been instances where the HTML code we receive from certain websites does not have proper tag endings, causing issues with our UI. For example: <br /><p>hello the para start here </p> <p>some text and no ending tag As yo ...

I am facing difficulties with collision detection

As a newcomer to HTML, I'm facing an issue with my game piece. While it stops at the ground as intended, it passes through the sides and top of the canvas. Can anyone suggest a way to fix this problem? Here is the code snippet I am currently using: ...

Simple steps to modify the width of underline using CSS

One of the cells in my table has the following content: <td><b>Grand Total</b></td> I want to add a line under the text "Grand Total". I tried using text-decoration: underline;, and it worked fine. However, I now need to customize ...

The W3C validator verifies the cached iteration of the website

Click here The most recent error is on Line 420, Column 42: Found a stray start tag script. <script src="/skin/sayan_health/js/nc.js"></script> However, I managed to fix this error by placing the script tag inside the body tag. When I inspec ...

Adjust the color of static hyperlinks based on the background color

Is there a way to dynamically change the color of my fixed side links based on the background color when scrolling? I attempted to use CSS mixed-blend-mode: difference, but it does not provide the level of control I need. Therefore, I am looking to achieve ...

Navigating pages in tinymce editor

Currently, I have implemented TinyMCE as the editor for my PHP-based website. However, I am facing a challenge in integrating pagination within the editor. My goal is to allow users to input long content that will be displayed across multiple pages inste ...

Troubleshooting Firefox 4's Margin Issue

Recently, I updated to Firefox 4 and noticed that it's causing some display issues with my sidebar. Specifically, I have a contact form in the sidebar where I've applied a 1px margin to the textarea element. This aligns perfectly in all browsers ...

What could be causing the text alignment issue in the flexbox next to this image?

I am having trouble centering a logo and the words 'style guide' next to each other in the header. I am using flexbox for this layout, but the text positioning seems off. I suspect it may be due to scaling the logo to half size, but I can't ...

What is the best way to show hidden content within a masked div, similar to a tooltip?

In an icon-based menu, a grid consists of several <div> elements. Each element is empty with general CSS styling and inline CSS to set the mask effect. The purpose of using images as masks is to allow the icons to be colored in different ways by cha ...

Utilizing XHTML text input with CSS text-transform and JavaScript features

Similar Question: How to Convert a String into Pascal Case (UpperCamelCase) in JavaScript I am working on some basic tasks here, so please be patient. My current task involves using an XHTML text input to collect a user's name. I then display an ...

Ordering columns inside columns with responsive design in Bootstrap 5

Could the layout be rearranged for md+ devices to this configuration on xs, sm devices? <head> <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="294b46465d5a5d5d5b4859691c07 ...

Combine several elements in a single jQuery scrollreveal function

I am currently working on a webpage that utilizes the jQuery library plugin scrollreveal to gradually reveal different html elements when the page loads. The functionality of the code is working correctly at the moment, but I have noticed that there is a d ...

Efficiently incorporating styles and CSS, as well as Bootstrap CDN, into window.print() while utilizing Vue.js

I am trying to print from my Vuejs component and apply CSS and Bootstrap styles to the printed page. Currently, I am using window.print() inside the mounted lifecycle hook as shown below: export default { mounted() { ...