Adjustable width box with shortened text

My challenge is to arrange 4 divs side by side, with the first two on the left, the fourth on the right, and the third filling the remaining space in between. The third div should have a dynamic width and contain two text lines that should support ellipsis if the page size limits visibility. Currently, when the text width exceeds the available space, the fourth div moves down. Is there a way to achieve this layout without using Javascript, while ensuring compatibility with IE9?

Here's my current setup: http://jsfiddle.net/NMrks/aySyu/1/

HTML

<div class="container">
    <div class="blockA">A</div>
    <div class="blockB">B</div>
    <div class="blockC">
        <div class="blockC_container">
            <span class="lineA">Text text text from line A</span>
            <span class="lineB">Text text text text text from line B</span>
        </div>
    </div>
    <div class="blockD">
            <span>D</span>
    </div>
    <div style="clear:both"></div>
</div>

CSS

.container {
height: 60px;
padding-top: 5px;
padding-bottom: 5px;
min-width: 340px;
}

.container .blockA {
width: 54px;
height: 100%;
float: left;
display: block;
background-color: #ff00ff;
}

.container .blockB {
width: 50px;
height: 100%;
float: left;
display: block;
background: #df8505;
}

.container .blockC {
height: 100%;
float: left;
display: block;
background: #ff7d7b;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

.container .blockC .lineA {
line-height: 2.0em;
display: block;
font-weight: bold;
}

.container .blockC .lineB {
line-height: 1.0em;
display: block;
}

.container .blockD {
width: 64px;
height: 100%;
float: right;
display: block;
background: #df8505;
}

I've experimented with various properties like flexbox, adjusting widths and margins, but haven't found a solution yet. Any help would be greatly appreciated.

Thank you

Answer №1

Consider implementing a layout like the following to address both concerns:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8>
<style>

.container {
    height: 60px;
    padding-top: 5px;
    padding-bottom: 5px;
    min-width: 340px;
}

.container .blockA {
    width: 54px;
    height: 100%;
    float: left;
    display: block;
    background-color: #ff00ff;
}

.container .blockB {
    width: 50px;
    height: 100%;
    float: left;
    display: block;
    background: #df8505;
}

.container .blockC {
    height: 100%;
    display: block;
    background: #ff7d7b;
}

.container .blockC_container p {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lineA, .lineB {margin: 0;}

.container .blockC .lineA {
    line-height: 2.0em;
    font-weight: bold;
}

.container .blockC .lineB {
    line-height: 1.0em;
}

.container .blockD {
    width: 64px;
    height: 100%;
    float: right;
    display: block;
    background: #df8505;
}

</style>
</head>
<body>

<div class="container">
    <div class="blockA">A</div>
    <div class="blockB">B</div>
    
    <div class="blockD">
            <span>D</span>
    </div>

    <div class="blockC">
        <div class="blockC_container">
            <p class="lineA">Text text text from line A</p>
            <p class="lineB">Text text text text text from line B Text text text text text from line BText text text text text from line BText text text text text from line B</p>
        </div>
    </div>

    <div style="clear:both"></div>
</div>

</body>
</html>

There are alternative methods to ensure the third column expands to fill all available space, but this approach of reordering elements in HTML and removing floats is the simplest.

Answer №2

Just a quick adjustment is needed here: blocks A, C, and D should have their width set to auto to avoid content overflow.

Here's an updated example with longer AAA, BBB, and CCC cells:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8>

...

<a href="http://jsfiddle.net/v5Dns/3/" rel="nofollow">Click here to see the revised sample</a></p>
    </div></answer2>
<exanswer2><div class="answer" i="22861499" l="3.0" c="1396596309" v="1" a="QWxleGFuZGVyIFBvcG92" ai="1539017">
<p>Minor correction
blockA, blockC, blockD should each have width:auto to prevent content overflowing.</p>

<p>updated example showing longer AAA, BBB, and  CCC  cells:</p>

<pre><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
.container {
    height: 60px;
    padding-top: 5px;
    padding-bottom: 5px;
    min-width: 340px;
}

.container .blockA {
    width: auto;
    height: 100%;
    float: left;
    display: block;
    background-color: #ff00ff;
}

.container .blockB {
    width: auto;
    height: 100%;
    float: left;
    display: block;
    background: #df8505;
}

.container .blockC {
    height: 100%;
    display: block;
    background: #ff7d7b;
}

.container .blockC_container p {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lineA, .lineB {margin: 0;}

.container .blockC .lineA {
    line-height: 2.0em;
    font-weight: bold;
}

.container .blockC .lineB {
    line-height: 1.0em;
}

.container .blockD {
    width: auto;
    height: 100%;
    float: right;
    display: block;
    background: #df8505;
}

</style>
</head>
<body>

<div class="container">
    <div class="blockA">AAAAAAAAAAAAAAAAA</div>
    <div class="blockB">BBBBBBBBBBBBBBBBBB</div>

    <div class="blockD">
            <span>DDDDDDDDDDDD</span>
    </div>

    <div class="blockC">
        <div class="blockC_container">
            <p class="lineA">Text text text from line A</p>
            <p class="lineB">Text text text text text from line B Text text text text text from line BText text text text text from line BText text text text text from line B</p>
        </div>
    </div>

    <div stye="clear:both"></div>
</div>

</body>
</html>

http://jsfiddle.net/v5Dns/3/

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

Padding issue observed at the lower part of the table cell in white color

Take a look at this JSFiddle: http://jsfiddle.net/nMbb4/1/ Here is the HTML code: <table> <tr> <td> 1 </td> </tr> <tr> <td> <div></div> ...

Selecting Specific File in Directory Using HTML File Input

Can you customize an HTML file input to choose a particular file from a directory or drive? By clicking on the file input button, the user opens the file selector and selects a folder or external drive. With jQuery, it is then possible to specify a specif ...

Tips on making a fresh form appear during the registration process

After clicking on a submit button labeled as "continue" within a form, a new form will appear for you to complete in order to continue the registration process. ...

Incorporating an external JavaScript file into an AngularJS project

index.html: <!DOCTYPE html> <html> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"> </script> <script src="./assets/namesController.js"></script> <body ng-app="myApp"> < ...

At a specific media query breakpoint, links are disabled while the rest continue to function without any

Today I encountered a puzzling issue on my website with a responsive layout that utilizes @media queries and breakpoints. At one specific breakpoint (or resolution, as I am still learning the terminology), the links in the navigation bar are inexplicably d ...

What could be the reason for ThemeProvider (Material UI) failing to function properly in this scenario?

I've encountered something puzzling with Material UI. Despite my experience with it, I can't seem to figure out why my H2 tag in the nested component is rendering in Times instead of Arial. I've double-checked the docs and my code, but the i ...

Restrict the Three.js Raycaster to a designated section within the HTML without using offsets

As I dive into using Three.js and the Raycaster for object picking, my HTML structure consists of a Navigation Bar in the head section and the rendering area in the body section. However, I encountered an issue where there was an offset in the Raycaster d ...

Enhancing the Alignment of a Bootstrap Navbar with CSS

Having trouble centering the listed items (excluding the image and title) in the middle of the navbar. Tried various solutions with no luck! Any suggestions on how to tackle this issue? <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a ...

Steps for creating a one-sided container in CSS

I've created a container class with the following CSS: .container { margin: 0 auto; width: min(90%, 70.5rem); } This setup centers the content on the page within the container, which is great for organization. However, I'm looking to creat ...

Save the selected value from the dropdown menu and automatically check the corresponding checkbox when it

I'm attempting to update the 'value' of a checkbox once an item is chosen from a dropdown list and then the checkbox itself is clicked. I have created a jQuery function that captures the value from the dropdown list (I omitted the code for t ...

The process of rendering a form eliminates the classes that were previously added by J

I am in the process of redesigning a web application and need to incorporate responsive design into the existing UI. My plan is to include col-* classes on specific html elements, such as tables: function addColstoTableCells() { $('table tr.form ...

Achieving a more optimized display on mobile and desktop using Bootstrap 5 techniques

I am working with a bootstrap 5 website template and I need to arrange divs in the following order: Desktop https://i.sstatic.net/qQEiP.png Mobile https://i.sstatic.net/JUnCY.png <div class="d-flex justify-content-between align-items-center pt- ...

Navigating through web elements with Selenium is made easy with the use of wild

Can a single xpath expression be used to cover all of the following: //center/b[contains(string(), 'New password')] //center/h3[contains(string(), 'Renaming user ID')] //h3/center[contains(string(), 'Updating Email to')] //h3 ...

Ways to flip the sequence of lines within a div without altering the formatting, word arrangement, and other elements

I need to rearrange the order of my lines while preserving the styling of words and the sequence I have created. Code Snippet: <textarea id="mytext""> Buy - 3 Potatoes $6.25 Sold - 3 Napkins $7.12 Buy - 5 Fries $11.62 Sold - 7 Pot ...

Interactive Geography Selector

When updating your personal details on , you are required to choose your country first. Once the country is selected, the system automatically adjusts the city and/or state options based on that specific country's requirements. Can someone provide exa ...

What is the best way to continuously run a series of functions in a loop to create a vertical news ticker effect?

I'm in the process of creating a vertical latest news ticker, and although I'm new to javascript, I'm eager to learn and build it myself. So far, I've come up with this, but I want the news cycle to restart once it reaches the end. ...

Creating a Unique Header Navigation Menu on Your WordPress Premium Theme

I recently faced an issue with my premium WordPress theme's navigation menu on the header. Whenever I clicked on it, it wouldn't redirect to the intended page. After some troubleshooting in the Google Chrome element editor, I managed to solve the ...

What could be causing the distance between the image and the navigation bar?

Hey there, I'm struggling with a pesky little gap that's sneaking in between an image and my navigation bar. I've exhausted all my usual tricks like setting inline-blocks on the ul and li levels, and trying to align everything left with text ...

Tips for defining a relative path in the base URL with AngularJS

Encountering an issue with AngularJS routes related to file paths. The folder structure is as follows: js -> Angular -> css -> Bootstrap -> index.html Routes work fine when hosted on a server like IIS. However, copying and pasting the direct ...

How to create a Navbar with a fixed-top position and ensure the container beneath it stays fixed to its bottom even when scrolling

https://i.sstatic.net/EgrDC.jpgWhen using the "navbar fixed-top" feature from Bootstrap, I have noticed that the container underneath it tends to slide below the navbar when scrolling down the page (see attached photo). Although this is expected behavior w ...