Text element within a container of unspecified dimensions

I find it challenging to explain what I have in mind without a visual reference:

https://i.sstatic.net/5MSVr.png

Some Background - There are certain aspects that can't be altered or shouldn't be changed:

On my blog's front page, I utilize a card layout where the width of each card is dynamically calculated by JavaScript based on the screen width. The height of the card is set to match its width (intending for a square shape) and the image inside maintains a 16:9 ratio. In the content section, the title doesn't wrap, the footer only contains the date, but the length of the actual text varies. Furthermore, when viewed on wider screens with larger card widths, I want more intro text to appear so that the space is effectively utilized.

Issue

When the text is too lengthy or the card's width is too small (such as on smaller screens), the text overflows from the container and pushes down the footer despite having "overflow:hidden" set.

https://i.sstatic.net/niTkk.png

How can I prevent the text div from pushing down the footer if the text exceeds the width of the card? Essentially, how can I ensure that its height equals the card's height minus the image's height, the title div's height, and the footer div's height? While achieving this using JavaScript wouldn't be difficult, is there a way to accomplish it solely with CSS? Flexbox might seem like a useful solution by allowing the text div to expand, but my attempts didn't yield the expected results. View this fiddle - It doesn't function properly without setting a fixed height for the flex container; refer to this fiddle where a specific height is assigned to the flex container. The code snippets are provided below:

<style>
.card{
  border:1px solid #000
}
.container{
  padding-top:100%;
  position:relative;

}
.item{
  top:0;bottom:0;left:0;right:0;position:absolute
}
.teaser{
  padding-top:56.25%;
  background-image:url('http://placehold.it/320x180?text=%20');
}
.content{
  display:flex;
  flex-direction:column;
  height:150px;   /* fixed height makes it work */
}
.title{overflow:hidden;white-space:nowrap;text-overflow:ellipsis}
.title, .intro, .info{padding:10px}
.intro{overflow:hidden}
</style>
<div class="card" style="width:360.25px"> 
  <div class="container">
    <div class="item">
      <div class="teaser">
     </div>
     <div class="content">
        <div class="title">
          A Blog Title A Blog Title A Blog Title A Blog Title A Blog Title A Blog Title...
        </div>
        <div class="intro">
          Some Intro text Some Intro text Some Intro text...
        </div>
        <div class="info">
            <time>2019-10-23</time>
        </div>   
     </div>
    </div>
  </div>
</div>

Is there a CSS-only solution to this dilemma?

Answer №1

// Ensure to specify both the minimum and maximum height for the intro container in order for it to function properly.

.intro {
    overflow: hidden;
    min-height: 80px;
    max-height: 75px;
}

Answer №2

It's possible that I may not have fully grasped the question, but if you were to include flex-wrap:wrap; in your .title, .intro styles,

.title{flex-wrap:wrap;}
.intro{flex-wrap:wrap;}

and delete the padding from the container, everything should function as expected...

.card{
  border:1px solid #000
}
.container{
 /* padding-top:100vh;*/
  position:relative;

}
.item{
 /*  top:0;bottom:0;left:0;right:0;position:absolute */
}
.teaser{
  padding-top:56.25%;
  background-image:url('http://placehold.it/320x180?text=%20');
}
.content{
  display:flex;
  flex-direction:column;

}
.title{flex-wrap:wrap;}
.title, .intro, .info{padding:10px}
.intro{flex-wrap:wrap;}

https://jsfiddle.net/6q0tLobr/

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 for unloading or replacing a JQuery script when the useragent is identified as IE6

I've encountered a challenge. I created a script using jQuery that causes an input field to shake if the user enters incorrect values: $('#input-name').addClass('input-bad').effect('shake',{ direction: ' ...

Creating dynamic routing functionality in Angular 8 allows for a more personalized and

I am struggling with setting up routing in Angular 8. Here is how I am trying to do it: 'company/:id/activity' 'company/:id/contacts' However, I am not receiving any params in the activatedRoute: this.activateRoute.params ...

Understanding the process of globally evaluating classes from files in node.js using the Eval function

Parent script with childscript integration const fs = require('fs'); function includeFile(f) { eval.apply(global,[fs.readFileSync(f).toString()]) } includeFile(__dirname+'/fileToRead.js'); hi(); ...

The React app hosted on Firebase displays a message saying "please activate JavaScript to run this application"

I created a web app using React that is hosted on Firebase Hosting, with a backend server utilizing Express and Cloud Functions. You can access the website here: The landing, login, and signup pages are functioning properly. However, when trying to acces ...

Looking for subsequence in dropdown choices with no assigned values

I need assistance with searching for a specific substring within text that is fetched from options generated by MySQL. How can I retrieve the selected option's text value in order to search for my desired substring? $(document).ready(function() { ...

The <p> element nested inside a <div> element with font-weight styling

I'm struggling to make a large font size and weight fit into a div tag while aligning it vertically at the bottom. Can anyone help me with this issue? div { border:1px solid black; height:100px; } table { border:1px sol ...

Multi-dimensional array: Include an extra array if the desired value is not located

I am currently working on a project that involves using Google tables to create a report based on data retrieved from my MYSQL Database. The issue I'm encountering is that there are 5 header values: ['Call Disposition', 'Answered' ...

What is the process for loading this image?

While browsing through this stunning website, I came across a feature that caught my eye. Can someone please explain how the designer displayed the "The magic is loading" effect: The image vanishes once the site has finished loading completely. ...

Ways to showcase an icon within a select options tag

Is there a way to show Font Awesome icons in select options tag? I have tried using it outside like this <i class="fas fa-chart-pie"></i> But I'm not sure how to display it within the <option> tags instead of text. <select id="s ...

Using AngularJS to extract values from deeply nested JSON structures

I'm currently navigating through a nested JSON object and I'm facing challenges in accessing the sub items within it. Below is a snippet of the JSON file I'm working with. It has successfully passed the JSONLint test, so it should be in pro ...

Angular ngClass and ngIf directives failing to update upon alterations

In my current Angular project, I am working on a functionality where I need to dynamically change a class based on a variable without having to refresh the page. I have experimented with *ngIf/else and [ngClass] directives, which do work, but unfortunatel ...

Is it possible to trigger a directive using a function and then access the generated style?

My directive is designed to randomly select a color and assign it to a new user as an avatar. The random color generation and directive functionality are working as expected, but I'm looking to expand the functionality further and need some assistance ...

Canvas is unable to duplicate image content

I am trying to duplicate a PNG captcha image in order to remove its transparency so that the captcha resolver (ocrad.js) function can work properly. However, I am facing an issue where the duplicated captcha image is being moved and resized. How can I ke ...

Angular - Highlight a section of a string variable

Is there a way to apply bold formatting to part of a string assigned to a variable? I attempted the following: boldTxt = 'bold' message = 'this text should be ' + this.boldTxt.toUpperCase().bold() ; However, the HTML output is: thi ...

Looking for Assistance with Grasping the Concepts of Ajax Function

After completing my first Ajax function using online tutorials, such as Google and w3schools, I've successfully made it work. However, I'm struggling to grasp the logic behind it and would greatly appreciate an explanation! Below is my complete ...

Error: The object referenced does not have a function called 'findById' within its methods when trying to export

I have come across a number of similar questions on this platform, but most of them seem to be related to HTML. My issue involves encountering an error while submitting a login form in Java. Here is a Very Simple Save Function: var model = require(' ...

Troubleshooting a CSS problem within mat-autocomplete component in Angular 7

While using mat-autocomplete, I noticed that when I select an option from the dropdown and then scroll through the main bar, the dropdown menu does not move along with the autocomplete input field. view image here Here is the code snippet: <td width ...

Switching Symbols with JQuery

Hello, I am brand new to utilizing javascript and I'm currently experimenting with the toggle function. My goal is to create show/hide functionality while also toggling arrow icons. Specifically, I want a right arrow next to the link "More -->" and ...

Ways to send data to a popup in svelte

Hey there, I could really use some assistance with my Svelte app. I'm trying to implement a modal and pass a parameter to the modal component in order to customize its content. However, when using the open() function of Modal, we only need to provide ...

Rotate image in Vue3 using @click

I have a dashboard with a refresh button that I want to rotate 360 degrees every time it is clicked. How can I achieve this rotation effect on the image with each click of the refresh button? Below is the code snippet I have been working on, but it only r ...