Stop elements from expanding by setting an automatic width with no wrapping of white space

Within my HTML page, there are nested divs as follows:

div#given                -- display: block
    div#one              -- display: table
        div#two          -- display: table-row
            div#three    -- display: block
                div#four -- display: block

The #given div is provided by a third party and has a defined width, which may be altered through JavaScript.

On the other hand, #one, #two, #three, and #four have implied widths.

The #three div's stylesheet includes:

#three
{
    overflow-y: hidden;
}
#three:hover
{
    overflow-y: visible;
}

#four contains a large amount of text that exceeds the boundaries of #three, but remains hidden until #three is hovered over.
I aim to apply text-overflow: ellipsis; to #four, but this only works when white-space: nowrap; is set. Unfortunately, setting this property stretches both #three and

#four</code beyond the desired layout.<br>
As of now, the only solution I have found involves explicitly defining a width for <code>#four
, which is impractical due to the variable width of #given.

Is there a non-JavaScript method to achieve this?

To view the issue in action, refer to this fiddle: https://jsfiddle.net/zquL7sem/3/

I aspire to have the content within the red border end at the blue line with three dots indicating truncated text, without setting explicit widths for #three or #four.

Any assistance on this matter would be greatly appreciated.

Answer №1

When utilizing the display:table property, the element will expand based on the content similar to how a real table behaves. To address this issue, you can use: table-layout:fixed along with width. For more details and examples, check out this link: https://jsfiddle.net/zquL7sem/4/

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

ReactJS does not update the conditional CSS class when hovering with mouseOnEnter or mouseOnOver

I am currently attempting to showcase data in a table where each row features an info icon that is only visible upon hovering. Additionally, I want a pop-up to appear when the info icon is clicked (there is an onclick function assigned to this button). He ...

Issues with CSS properties not functioning correctly within the class.col function

When attempting to apply specific CSS properties to a particular area (e.g., "Dashboard") by assigning the class name "main" to the div.col function in the HTML, I encountered an issue where the CSS property applied affected the entire page. The following ...

Tips for transferring a data table (an object) from a JavaScript file to Node.js

On my HTML page, there is a table displaying student names and information, along with controls to manage the table. I created a save button to save this table as an object named SIT in my JavaScript code. I was able to manually save this table in MongoDB ...

Toggle the visibility of 2 Form Fields by checking the Checkbox

Hi, I am trying to display two form fields when a checkbox is selected. These fields are required, so they should only be displayed when the checkbox is checked and should be mandatory. However, I am facing issues with hiding the fields when the checkbox i ...

Why aren't the divs appearing on the page?

I have developed a JavaScript and PHP page where the script in the PHP page sends data to my SQL database. However, the result is not displayed on my home page. Here is the code snippet: function getVote(question_ID) { var option_ID = document.queryS ...

What is the process for adjusting the width of an element using JavaScript?

I have a unique bar with one half red and the other green. I am trying to subtract 1vw from the width of the red section. Unfortunately, using style.width is not yielding the desired result. See below for the code snippet I am currently using: //FIGHT do ...

Display my additional HTML content on the current page

Is it possible for my addon to open a predefined html page in the current window when it is started? And if so, how can this be achieved? Currently, I am able to open my addon page in a new window using the following command: bridge.boot = function() { ...

What is the best way to target a class within a span using CSS?

I need help with hiding an icon from the mobile menu. I am unsure about how to target this specific class within the menu structure. <a class="funiter-menu-item-title" title="Nieuw">Nieuw<span class="icon fa fa-chevron-down"></span>< ...

Navigating Divs Using jQuery

I am working with a class that has multiple divs, each with a unique id attached to it. I am using jQuery to dynamically cycle through these divs. This is a snippet of my HTML code: <div id ="result">RESULT GOES HERE</div> ...

Load External HTML content into webpage along with executing JavaScript code and triggering JS functions upon loading

I'm in search of a super lightweight solution that can effectively load an external HTML file into a page using only vanilla JavaScript. The external file contains HTML, CSS, and JS. Essentially, I want to create a concise JS snippet that loads a butt ...

Hide in certain zones, contextual menu

I recently discovered how to create my own context menu with links based on the div clicked (check out here for more details). However, I am facing an issue now. I am struggling to prevent the context menu from appearing above the specific div boxes where ...

Empty the localStorage when terminating the IE process using the Task Manager

Utilizing HTML5 localStorage to keep track of my application session has been a useful feature. Here is a snippet of the code I am currently using: if(typeof(Storage)!=="undefined") { if(sessionStorage.lastname=="Smith") { alert("Your ses ...

Achieve a scrolling effect for just a specific section of an HTML page

Hey there! I'm currently working on adding scrolling text along the side of a webpage for a specific section. My goal is to have three different sections, each with text that stops scrolling when you reach it and then transitions to the next section o ...

Implement JQuery UI Accordion to enhance navigation on mobile devices

I am implementing the JQuery UI Accordion to expand content on a website. Below is the basic markup structure: <div class="accordion"> <h2>Heading</h2> <div>Content</div> <h2>Heading</h2> <div& ...

Guide to displaying a confirmation prompt in c# programming

I need to create a confirmation window similar to confirm() in JavaScript that will pop up when a button is clicked. If the user selects "YES", I want to execute some C# code. How can I achieve this? EDIT: here is the code snippet that I have: SCRIPT: & ...

When I press the button, a model popup will display the complete information

How can I display full information on a model popup when clicking a button? <button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#myModal" > <i class="glyphicon glyphicon-zoom-in"></i> </button>< ...

What steps can I take to troubleshoot and fix the height of a div/span element?

Here is my HTML code: <div> <span style="display: inline-block;height:20px">20</span> <span style="display: inline-block;"><img src="img/ex.png"/></span> </div> The image I have in the second span is sized at ...

Guide to incorporating the content of a div into an image source using PHP

In extracting a value from an HTML table, I encountered this syntax: $('table#showalluporders tbody tr').click(function() { var tableData = $(this).closest("tr").children("td").map(function() { return $(this).text(); }).get(); $(' ...

The react-transition-group fails to function properly until the page is reloaded

My task scheduler using React Router 5 and React Redux is working fine. Now I am trying to animate transitions between different routes using react-transition-group. When I click the URL changes, but the screen does not re-render until I manually reload ...

Obtain saved browsing history in HTML5 with the use of JavaScript

I'm currently utilizing the History.js library found at https://github.com/browserstate/History.js/ to create an AJAX-based application that leverages the HTML5 History API for dynamically changing the URL and title of the browser. Does anyone have s ...