The hover effect in CSS animations is turned up too high

Check out my Reddit news feed design:

https://codepen.io/Teeke/pen/YxXXaE

When hovering over articles, the headlines get displayed. But if the article text is too long, part of the headline may go off-screen.

Instead of changing the line-height, I'm looking for alternative solutions to this issue.

I have two ideas:

1) Have the article text extend beyond the image with a grey overlay.

2) Limit the popup height: The top part will be visible while the lower part remains hidden below.

What are the recommended ways to address this problem?

I've experimented with overflow: hidden; and position: fixed; but they didn't produce satisfactory results.

CSS:

.overlay{
      display: block;
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      z-index: 3;
        // text-shadow: 2px 2px 2px #f22;
    }

    .bar, .overlay{
      transition: transform 250ms;
      transform: translateY(80px);
      color: transparent;
    }

    &:hover{
      .bar, .overlay{
        transform: translateY(0);
        color: inherit;
        text-shadow: 2px 2px 2px #222;
         background: linear-gradient(to top, #001, rgba(0,0,0,0.4) 5px);
        padding: 8px;
      }
    }

    &.stickied .overlay{
      background: linear-gradient(to top, #0f0, transparent 80px);
    }

    @media (max-width: 520px){
      width: 100% !important;
    }
  }
}

Answer №1

One suggestion I have is to decrease the font size of the text within the .post class to around 14px. After conducting some tests, it was determined that the text remained completely legible.

Additionally, you may want to consider shortening the text if it appears too lengthy by using the following CSS:

.post {
   overflow: hidden;
   text-overflow: ellipsis;
}

Answer №2

My recommendation would be to go with the second option and consider making the following adjustments:

  • Decrease the font size
  • Lower the line height
  • Eliminate any letter spacing
  • Align the text to the left
  • Add a faded effect when text exceeds its container

View codepen demo for reference

.grid .item .bar {
  position: absolute;
  left: 0;
  bottom: 0;
  top: 0;
  width: 100%;
  height: 200px;
  padding: 0 4px;
  z-index: 4;
  color: white;
  display: flex;
}


.grid .item .bar a {
  color: inherit;
  text-decoration: none;
  font-size: 16px;
  /* decreased font size */
  line-height: 1.2;
  font-family: 'Open Sans', sans-serif;
  font-weight: 400;
  text-align: left;
  overflow: hidden;
}

.grid .item .bar a.zoom {
  align-self: flex-end;
  overflow: inherit;
  z-index: 3;
}

.grid .item .bar a:not(.zoom):before {
  content: '';
  width: 100%;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
  background: linear-gradient(transparent 175px, #888);
}

Answer №3

If you want the overlay to extend beyond the confines of its container, simply include overflow: visible; in the styling of the .item class.

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

HTML Brickwork Picture Arrangement

I recently integrated this code into a WordPress theme and encountered an issue where the new images are displaying vertically instead of horizontally. I am seeking assistance in aligning the new images to appear on the green line instead of the red line a ...

The JavaScript code appears to be missing or failing to execute on the website

Encountering a console error while trying to integrate jQuery into my website. The JavaScript file is throwing an error in the console that says: Uncaught ReferenceError: $ is not defined catergory.js:1 Even after following the suggested steps in this an ...

Image placed as background for registration form

In my Vue project, I am trying to create a login form with an image as the background. However, I am facing an issue where the image is not displaying on the page. Can someone guide me on how to add a picture behind the form? HTML: Below is the HTML code ...

Increased space between the sidebar and the top bar

Currently, my code is a bit messy as I am still in the learning stages of bootstrap. I need some assistance on how to resolve the empty space that exists between the top and side bar elements. <!DOCTYPE html> <html lang="en"> <sty ...

Every div must have at least one checkbox checked

Coding in HTML <div class="response"> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> <input type="checkbox" /> </div> <div class="response"> <input type="check ...

prettyPhoto popup exceeds maximum width and height limitations

I am currently using the most up-to-date version from No Margin for Errors and I have set allow_resize to true. However, the size of the display is still too large. Is there a way to set a maximum width/height? I have already configured the viewport as fo ...

Selecting the label "for" will activate both the anchor tag and input tag simultaneously

It seems like I'm having trouble making this work, and it appears to not be possible. That's why I'm reaching out for help... Here is the CSS that is being used: label.btn { cursor:pointer; display:inline-block; } label.btn>inpu ...

Transform your image using a stunning zoom-in effect

Currently, I am experimenting with a feature for my website where I want images to switch upon hover. While I have successfully achieved the image switch on hover, I am looking to create smooth transitions between the switches, with the second image being ...

Minimize the number of HTTP requests by including CSS and JS files in PHP

I've been considering a method to reduce the number of HTTP requests made when loading a page by minimizing the amount of downloaded files, while still keeping separate files on the server. The thought process is as follows: <!DOCTYPE html> &l ...

Mixing together an array of colors, experimenting with adding a touch of transparency

Here is my first question, diving right in. I recently created a canvas in HTML and followed a tutorial to generate random floating circles that interact with the mouse position......if you want to check it out, click here. The issue I'm facing now ...

Javascript code fails to execute properly on IE8

I have a scenario where I am working with two drop-down menus. When the user selects an option from one menu, it should dynamically change the options in the other menu. However, I'm facing an issue with Internet Explorer where the second drop-down me ...

What is the best way to eliminate the gap above a block element using CSS?

Currently in the process of designing a website, I am faced with a challenging issue that seems to have me stumped. The structure of my page consists entirely of HTML DIVs, with certain elements nested within their parent DIVs. My main dilemma lies in tryi ...

Tips for placing an icon within an input field

I'm struggling to place an icon inside an input tag, but it always appears at the bottom of the input. I initially tried using Bootstrap, but I ended up resorting to custom styles for this specific issue. Here's the HTML code: <d ...

Create dynamic animations using AngularJS to transition between different states within an ng-repeat loop

Here's a simplified explanation of my current dilemma: I have an array containing a list of items that are being displayed in an Angular view using ng-repeat, like... <li ng-repeat="item in items"> <div class="bar" ng-style="{'width ...

What could be causing the disappearance of my <Div> when applying a Class to the contained <span>?

My goal is to showcase a variable on my HTML page using CSS for a Graphical display in OBS streaming software. Whenever I apply the class .wrappers to the span id p1Name (and p2Name), the text disappears from the HTML output in OBS. I'm puzzled as to ...

Tips for minimizing excess white space in Shiny applications

Encountering an issue with plot output in Shiny. When using standard ggplots, the output is correct without any extra white margins. However, when utilizing the "ggmap" package (which also produces ggplot-type outputs), white margins suddenly appear. (Ple ...

Tips for positioning an image in the TOP Right corner below the navbar using CSS

I am currently in the process of learning HTML and CSS, and I would like to practice and conduct research whenever I encounter difficulties. Recently, I have been attempting to style my landing page based on a screenshot that I took. However, I have been u ...

What is the best way to line up three divs horizontally and center the contents inside each one?

I'm brand new to CSS and need some help simplifying things. I am trying to create 3 divs that are all the same size, placed next to each other, with centered content in each one. Currently, I have a central div with a rotating image, and on the left a ...

Personalizing the structure of a joomla template

Having some trouble customizing my Helix Framework template. I'm trying to adjust the width of the page to be 1140 px. When I make changes in the framework menu, it only adjusts the text field width and not the graphics. How can I achieve the layout s ...

Is utilizing fixed-top/fixed-bottom with inner div elements set to a fixed height the most effective strategy?

I am working on developing an app similar to stackoverflow, with fixed menu and footer panels and an inner div that creates browser scroll as needed. I'm wondering if the code below is correct for achieving this setup. The classes fixed-top/fixed-bot ...