Avoiding text from overflowing a DIV when the parent DIV's width is specified as a percentage

After extensively searching through over 20 similar posts, I have not been able to find a solution that works for my specific issue.

The layout of some content I'm working with resembles the example provided here:

Check out the Fiddle Example

In this layout, there is a container div named "Strip" that contains 3 child divs: img, title, and description. The container div has a fixed width of 944px.

  • The first div, img, has a fixed size and functions correctly.
  • The second div, title, should adjust its size automatically based on the title length, and it's working fine.
  • The third div, description, should occupy the remaining space within the Strip Div without overflowing. Unfortunately, this functionality is not working as expected.

I managed to achieve the desired effect by setting a fixed width for the description div, but this approach doesn't work well when the title length varies.

Although I believe the solution might be simple, I haven't had any luck after trying multiple approaches.

CSS:

  font-weight: bold;
}

.strip {
  width: 944px;
  max-width: 944px;
  display: inline-block;
  border: Solid;
  border-width: 2px;
  max-height: 28px;
  white-space: nowrap;   

}

.img {
  display: inline-block;
  border: solid;
  border-width: 1px;
  border-color: red;
  max-width: 50px;
  max-height: 28px;
  height: 28px;
  white-space: nowrap;
  text-wrap: hidden;


}

 .img p {   
  text-overflow: ellipsis;
  white-space: nowrap;   
  overflow: hidden;

 }


.title {
  display: inline-block;
  border: solid;
  border-width: 1px;
  border-color: green;
  max-height: 28px;


}

.title p {


  white-space: nowrap;   
  overflow: hidden;
}


.description {
  display: inline-block;
  border: solid;
  border-width: 1px;
  border-color: blue;
  max-height: 28px;


}

.description p {
  text-overflow: ellipsis;
  white-space: nowrap;   
  overflow: hidden;
}
**HTML:** <html> <div class="strip"> <div class="img"> <p> Test </p> </div> <div class="title"> <p> Rotten Tomatoes </p> </div> <div class="description"> <p> Rotten Tomatoes, home of the Tomatometer, is the most trusted measurement of quality for Movies & TV. Rotten Tomatoes, home of the Tomatometer, is the most trusted measurement of quality for Movies & TV. </p> </div> </div> </html>

Answer №1

Utilizing Flexbox for the task:

.wrap {
  width: 90vw;
  display: flex;
  margin:auto;
}

.image {
  border: 1px solid red;
  width: 50px;
}

.heading {
  border: 1px solid green;
  white-space: nowrap;
}

.summary {
  flex: 1;
  border: 1px solid blue;
  min-width: 0;
}

.summary p {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
<div class="wrap">


  <div class="image">
    IMG
  </div>

  <div class="heading">
    <p>
      Rotten Tomatoes
    </p>
  </div>

  <div class="summary">
    <p>
      Rotten Tomatoes, home of the Tomatometer, is the most trusted measurement of quality for Movies & TV. Rotten Tomatoes, home of the Tomatometer, is the most trusted measurement of quality for Movies & TV.
    </p>
  </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

A guide to loading CSS and JavaScript files asynchronously

Is it possible to use loadCSS (https://github.com/filamentgroup/loadCSS/blob/master/README.md) to allow the browser to asynchronously load CSS and JavaScript? This is what I currently have in my head tag: <link rel="preload" href="http://zoidstudios. ...

Adjust text size within a div when hovering over it

I have a div with many elements inside. When the user hovers over the div, I want to increase the font size within that specific div. Here is the HTML code structure: <div class="col-sm-5 home-grid-2x"> <div class="home-grid-2 ...

It is impossible for me to utilize inline SVG as a custom cursor in CSS

Below is the code I have written. I am attempting to change the cursor using an inline SVG, but it doesn't seem to be working as expected. However, when I use the same code as a background, it works perfectly: .container { width: 50vw; height: ...

unrestricted motion through the utilization of css3 transitions and translations

When applying a new CSS translate, it's common practice to specify the exact number of pixels you want an element to move, such as 50px, 60px. This results in a relative movement from its current position. You can see an example of this here: http://j ...

A guide to smoothly transition box-shadow with jQuery's addClass() function

UPDATED I have a div with the class .shadow-circle-lg: <div class="shadow-circle-lg"></div> To add a different border styling to the div, I am using another class called .circle-highlight: .circle-highlight{ box-shadow: 0 0 0 1px rgba(0,0, ...

Switching the theme color from drab grey to vibrant blue

How can I change the default placeholder color in md-input-container from grey to Material Blue? I have followed the instructions in the documentation and created my own theme, but none of the code snippets seems to work. What am I doing wrong? mainApp. ...

Adjust the transparency of a distant div element by using CSS checkboxes without any JavaScript

I'm faced with the challenge of manipulating the opacity or animating an array of items that are all contained within a single div. In addition to altering the opacity of each individual item, I also want to change the opacity of the entire div and it ...

Steps for resetting a div's display after adjusting the device size

I have a code that displays horizontally on desktop screens and vertically on phones. It includes an x button (closebtn) that is only displayed on phones to close the menu bar. How can I automatically display it again after resizing the page back to deskto ...

Looking to enhance my JavaScript skills - Codepen samples welcome!

I have incorporated this code pen in my website to create a menu button for mobile view: http://codepen.io/anon/pen/LNNaYp Unfortunately, the button sometimes breaks when clicked repeatedly, causing the 'X' state to appear even when the menu is ...

Stopping autoplay in Swiper as soon as you hover over it

My swiper is set to autoplay, but I want it to stop immediately when hovered over instead of waiting for the transition to finish. Is there a way to interrupt the transition and stop it at the exact point where the cursor hovers? Here is my Swiper config ...

Image not aligning to center - email

Struggling to center align an image at the top of an email due to code that hides it when the browser is larger than 520px. Is there a way to exempt this specific image and keep it centered? .mobile { display: none !important; font-size 0 !importa ...

What is the best way to increase the size of the input field to allow for more typing space?

My query is quite simple. Even when I set the height to 100px, the cursor still starts in the middle of the input box. I want the entire box to be utilized with the cursor starting at the top left corner for a more intuitive paragraph writing experience. ...

Using WebDriver Selenium to choose an element within a table following another element

The webpage features a user details table with a functionality to delete users. To remove a user, I must select the row based on the username and then click the "Delete" button. The structure of the HTML table is as follows: <table id="tblUsersGrid" ce ...

Accordion styling using CSS

My current issue lies with setting the style for the contents of an accordion. The problem arises when the styles defined in a CSS file do not take effect on the content of my accordion when using the following code along with a separate CSS file: <scr ...

The wells are surpassing the line

I'm attempting to arrange 3 Wells horizontally in one row, as shown below <div class="row" style="margin-top: 10px"> <div class="span4 well"> <h3 class="centralizado"><img src="/assets/temple.png" /> & ...

Creating a List Item with Equal Height as Its Parent Container

<nav> <ul id="navUl"> <li> <div class="settingsDiv"> hey </div> </li> </ul> </nav> I am trying to adjust the height of the div element to match the height of the nav. My g ...

Hierarchy in CSS: The battle between author and user styling

Following a hierarchy of precedence: User agent declarations User normal declarations Author normal declarations Author important declarations User important declarations The CSS specification distinguishes between author and user: Author. The author s ...

Issue encountered when submitting form: Error identified as "Unexpected string expression without template curly in string"

As a novice in React.js, I am facing an issue where setState is not functioning properly when submitting a form. Any suggestions on how to resolve this problem? > class Home extends Component{ constructor(props){ > super(props) > ...

Tips on creating a repeating background image with CSS for a sprite

I'm facing a challenge that I can't seem to solve - I need to set a sprite as the background for a container. The issue is that despite my efforts, I haven't been able to achieve this. I've searched extensively but couldn't find a ...

I utilized the "data-target" attribute to ensure the active link retains its style. Is there a way to preserve the style when navigating away from an active link?

Can someone assist me with this re-upload? I need help tweaking my code to maintain style when navigating between pages using the "data-target" attribute. Currently, the style is being lost when moving from the original link (e.g., "link/sub01.html") to a ...