Hover Effect for Bootstrap Gallery

I've created a hover effect for my gallery that is embedded in a Bootstrap Grid. Although the hover effect itself works fine, on some screen sizes, the overlay ends up covering the gallery images.

Does anyone have any ideas, solutions, or hints to solve this issue?

Here's an example:

demo


HTML:


    <div class="container">
        <div class="row">

            <div class="col-md-4 col-sm-4">
                <a href="http://www.google.com">
                    <div class="box">
                        <img class="img-responsive" src="http://placehold.it/300x300" />
                        <div class="overbox">
                            <div class="title overtext">Client</div>
                            <div class="tagline overtext">Tag</div>
                        </div>
                    </div>
                </a>
            </div>

            <div class="col-md-4 col-sm-4">
                <a href="http://www.google.com">
                    <div class="box">
                        <img class="img-responsive" src="http://placehold.it/300x300" />
                        <div class="overbox">
                            <div class="title overtext">Client</div>
                            <div class="tagline overtext">Tag</div>
                        </div>
                    </div>
                </a>
            </div>

            <div class="col-md-4 col-sm-4">
                <a href="http://www.google.com">
                    <div class="box">
                        <img class="img-responsive" src="http://placehold.it/300x300" />
                        <div class="overbox">
                            <div class="title overtext">Client</div>
                            <div class="tagline overtext">Tag</div>
                        </div>
                    </div>
                </a>
            </div>

        </div>
    </div>

CSS:

.box {
    position: relative;
    cursor: pointer;
    width: 100%;
    min-height: 100%;
    overflow: hidden;
    margin-bottom: 30px;
}

.box .overbox {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    z-index: 100;
    background-color: rgba(204, 36, 42, 0.75);
    color: #fff;
    opacity: 0;
    -webkit-transition: all 300ms ease-out;
    -moz-transition: all 300ms ease-out;
    -o-transition: all 300ms ease-out;
    -ms-transition: all 300ms ease-out;
    transition: all 300ms ease-out;
}

.box:hover .overbox {
    opacity: 1;
}

.box .title {
    font-size: 22px;
    line-height: 131%;
    font-weight: 400;
    text-align: center;
    padding-top: 95px;
}

@media (max-width: 991px) {
    .box .title {
        padding-top: 43px;
    }
}

.box .tagline {
    position: absolute;
    bottom: 0px;
    padding-top: 16px;
    padding-bottom: 16px;
    width: 100%;
    display: flex;
    justify-content: center;
    font-size: 16px;
    font-weight: 400;
    font-style: italic;
    border-top: 1px solid rgb(255, 255, 255);
}

.box_client {
    position: relative;
    width: 100%;
    height: 100%;
    -webkit-filter: grayscale(100%);
    -moz-filter: grayscale(100%);
    -ms-filter: grayscale(100%);
    -o-filter: grayscale(100%);
    filter: grayscale(100%);
    -webkit-transition: all 300ms ease-out;
    -moz-transition: all 300ms ease-out;
    -o-transition: all 300ms ease-out;
    -ms-transition: all 300ms ease-out;
    transition: all 300ms ease-out;
}

.box_client:hover {
    background: rgb(235, 234, 233);
    -webkit-filter: grayscale(0%);
    -moz-filter: grayscale(0%);
    -ms-filter: grayscale(0%);
    -o-filter: grayscale(0%);
    filter: grayscale(0%);
}

.img-responsive {
    margin: 0 auto;
}

Answer №1

When the overlay has a width:100%;, it ends up going over the gallery images if the image is smaller than its container's width.

You have two options to fix this issue. You can either set the image's width to 100%, or you can modify the .box class by removing width:100%; and adding display:inline-block; instead.

.box {
    position: relative;
    cursor: pointer;
    // width: 100%;          // remove this
    display:inline-block;    // add this
    min-height: 100%;
    overflow: hidden;
    margin-bottom: 30px;
}

Answer №2

When dealing with a Bootstrap column that is expanding and contracting while the image remains a fixed size, it can cause sizing issues where the .responsive-image appears smaller than its parent div. Here are a couple of approaches to tackle this problem:

1) Try replacing the image in the HTML with a background-image property in CSS:

.box {
   background: url(image-url) cover no-repeat;
}

2) Adjust the image size to be 100% width:

.response-image {
    width: 100%;
}

3) Alternatively, follow Ahmed Salama's advice by removing width: 100% and adding display: inline-block;

Answer №3

The placeholder size is smaller than the parent div element, which spans the entire width of its parent due to the img-responsive class resizing the image to "max-width: 100%". You may need to use a larger image or resize it to fit the size of your parent box, although this is not generally recommended.

In this example, I have adjusted the placeholder sizes to 767px x 767px: http://codepen.io/pure180/details/OXpNxM/ HTML:

            <div class="col-md-4 col-sm-4">
                <a href="http://www.google.com">
                    <div class="box">
                        <img class="img-responsive" src="http://placehold.it/767x767" />
                        <div class="overbox">
                            <div class="title overtext">Client</div>
                            <div class="tagline overtext">Tag</div>
                        </div>
                    </div>
                </a>
            </div>

            <div class="col-md-4 col-sm-4">
                <a href="http://www.google.com">
                    <div class="box">
                        <img class="img-responsive" src="http://placehold.it/767x767" />
                        <div class="overbox">
                            <div class="title overtext">Client</div>
                            <div class="tagline overtext">Tag</div>
                        </div>
                    </div>
                </a>
            </div>

            <div class="col-md-4 col-sm-4">
                <a href="http://www.google.com">
                    <div class="box">
                        <img class="img-responsive" src="http://placehold.it/767x767" />
                        <div class="overbox">
                            <div class="title overtext">Client</div>
                            <div class="tagline overtext">Tag>
                        </div>
                    </div>
                </a>
            </div>
            
        </div>
    </div>

Answer №4

My solution to the problem was this

.container {
position: absolute;
cursor: pointer;
max-width: 400px;
min-height: 90%;
overflow: visible;
margin-left: auto;
margin-right: auto;}

Answer №5

Check out my approach: https://jsfiddle.net/5f285ask/4/

.container {
  position: relative;
  display: inline-block;
}

.container .overlay {
  background-color: rgba(204, 36, 42, 0.75);
  height: 100%;
  left: 0;
  opacity: 0;
  position: absolute;
  top: 0;
  -webkit-transition: all 300ms ease-out;
  -moz-transition: all 300ms ease-out;
  -o-transition: all 300ms ease-out;
  -ms-transition: all 300ms ease-out;
  transition: all 300ms ease-out;
  width: 100%;
}

.container:hover .overlay {
  opacity: 1;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-md-4 col-sm-4">
  <div class="container">
    <a href="#">
      <img alt="" src="http://placehold.it/300x300" class="img-responsive">
      <div class="overlay">
        overlay content
      </div>
    </a>
  </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

Using jQuery Ajax to Retrieve Inner Text from Elements

Looking for a solution with PHP file output like this: <div id="title">Add Us On Myspace!</div><img id="image" src="http://i39.tinypic.com/67jybs.png" alt="Add Us On Myspace!" /> The code to retrieve and display this is as follows... $ ...

Having trouble with syntax highlighting on Node.js Vash view files in Visual Studio 2015 Update 3?

While working on a Node.js application using Vash as the view engine in Visual Studio 2015 Update 3, I encountered an issue with syntax highlighting. When writing HTML in the vash files, the code appears as plain text without any syntax highlighting. For e ...

The appearance of Bootstrap-Navbar is altered when viewed on a mobile device

After creating a website that was compatible with both web and mobile devices, I encountered an issue where the navbar would not collapse on my smartphone. However, when I resized the browser window to match the size of the smartphone screen, it worked per ...

Steps for creating a rubber compound with reduced elements

Sample Image Looking for a way to reduce the size of elements on a webpage without adapting them? I want the elements to shrink and align in a single column, and I will handle the adaptation myself. HTML: <!-- Trading --> <div class="main-co ...

"Discover a unique online platform showcasing videos and images with a creative

I recently updated my personal website to showcase some of the tools I've developed through short looping videos. Initially, everything was working well with just images, but when I switched to videos, I encountered some unexpected behaviors. Interest ...

If a particular <td> element is present on the page, exhibit a unique <div>

I have a webpage with various HTML elements. <div class="alert">Your message was not sent.</div> <p class="pending">Email Pending</p> I would like to display the div.alert only if the p.pending is present. Is ...

Client request: receive a daily update detailing the differences between two databases

Today, a customer requested that I provide daily reports on the changes between two tables in our database. I am currently contemplating the most efficient and intelligent way to fulfill this request. Should I create a SQL procedure? Or perhaps an HTML p ...

Having trouble getting @media queries to work effectively across various screen sizes

Currently, I am using Sass with Bootstrap and facing some challenges when implementing different media queries. Despite most discussions revolving around CSS problems only, I am uncertain of the source of my issue and how to effectively address it. The sty ...

Achieve a seamless transition for the AppBar to extend beyond the bounds of its container in Material

I am finalizing my app structure by enclosing it within an MUI Container with maxWidth set to false. The issue I'm facing is that the AppBar inside the container doesn't span the full width of the screen due to paddingX property enforced by the c ...

How to load several stylesheets for a component in Angular 2

Struggling with my angular2 application, I encountered an issue when attempting to load multiple stylesheets for the same component. Below is a snippet of the code: import { Component } from '@angular/core'; @Component({ selector: 'my-tag& ...

Restricting the number of characters allowed for text messages and keeping track of the count

I am attempting to implement a character limiter for an html textarea using JavaScript. Additionally, I want to include a total character counter. Unfortunately, the code I have written isn't functioning as expected. Can anyone identify where my mist ...

What is the best way to reduce the width of the preformatted tag?

Is there a way to adjust the width of the pre tag in order to avoid affecting the q-card when resizing the browser window? I am trying to create a q-card that can display code similar to what you see in ChatGPT. However, the q-card's size is not respo ...

Choosing different elements using identical classes in JQuery

Struggling with a coding problem that seems like it should be an easy fix, but can't quite figure it out. The HTML code I have is as follows: <section class="actualite"> <div class="actualite-text"> <h3 class="title"&g ...

How can the edit feature be implemented in AngularJS?

I am struggling with implementing an edit field in AngularJS. Can someone please help me with this? Here is the code for my CRUD operations: var app = angular.module('myApp', []) app.controller('myCtrl', ['$scope', functio ...

Can sweetalert2 be used as a tooltip?

I have a query, is it feasible to include a tooltip in the alert message? Alternatively, could there be another tooltip option available? Swal.fire({ title: '<strong>An example with HTML tags</strong>', icon: 'info', ...

What is the process for changing the output paper size to A4 in React Native (expo android)?

Using React Native to develop an Android app for billing purposes, I encountered an issue with the output paper size being 216mmX279mm instead of the standard PDF size of 210mmX297mm. Utilizing expo-print and printToFileAsync from expo, I aim to achieve a ...

Using PHP GET Variable in an HTML Form

I am attempting to populate my form values using variables passed through the URL. Despite trying various solutions, I sometimes encounter an issue where the variable does not display. Any assistance on this matter would be greatly appreciated! Thank you! ...

To prevent the background image (blue border) from shifting, I need to extract the list item element without causing the image to

Having trouble with the side borders on my navbar. I've used a background image for the border (blue line) in the list item of the navbar. Is there a way to move down two specific list items slightly, like shown in my screenshot? I need to bring down ...

Apply CSS styling to the entire element when hovering over its pseudo-element 'after'

I am working on a button/speech bubble design with a unique hover effect. Here is the current setup: https://i.stack.imgur.com/4OrpL.png Here is the code snippet for the button: <div value="GO" id="go-div" class="bubble"> <input type="submit ...

Having trouble with Vue.js implementation of Bootstrap tab navigation?

I am currently working on a vue.js application that consists of 2 routed components. I recently attempted to integrate a bootstrap tab navigation into the first component, but unfortunately, the tab contents are not being properly displayed. <templat ...