Make the child element's height 100% when the parent's width is not set

Having trouble implementing the height:100; property on hover in my portfolio section. I've tried several solutions from similar questions without success. Although it works with media queries, I believe there's a better way to achieve this but I can't seem to figure it out!

Here is a snippet of my HTML:

<!-- Begin Portfolio -->
<section id="section2">

    <div class="container portfolio">

        <!-- Page Title -->
        <div class="row page-title-2">
            <div class="col-lg-12">
                <h3>Portfolio</h3>
                <hr>
                <p>We also create some other stuff.</p>
            </div>
        </div>

        <!-- Portfolio Filter -->
        <div class="container text-center">
          <ul class="nav nav-pills">
            <li class="filter" data-filter="all">all</li>
            <li class="filter" data-filter="print">print</li>
            <li class="filter" data-filter="web">web</li>
            <li class="filter" data-filter="branding">branding</li>
            <li class="filter" data-filter="branding">illustration</li>
          </ul>
        </div>

        <!-- Portfolio Items -->
        <div class="container port-holder">
          <ul id="myPortfolio" class="no-padding">
            <li class="item branding col-xs-4 no-padding">
                <a data-toggle="modal" href="projects/project-1.html" data-target="#myModal">
                    <img src="img/projects/thumbs/branding1.jpg" alt="..." />
                    <span class="portfolio-hover">
                      <span>
                        <h4>Beach Sand</h4>
                        <em>Branding</em>
                      </span>
                    </span>
                </a>
            </li>
            <li class="item web col-xs-4 no-padding">
                <a data-toggle="modal" href="projects/project-2.html" data-target="#myModal">
                    <img src="img/projects/thumbs/web1.jpg" alt="..." />
                    <span class="portfolio-hover">
                      <span>
                        <h4>B&W Scene</h4>
                        <em>Web Design</em>
                      </span>
                    </span>
                </a>
            </li>
            
            [Other portfolio items omitted for brevity]
  
          </ul>
        </div>

    </div>

</section>
<!-- End Portfolio -->

The CSS code related to the hover effect:

.portfolio ul li:hover span.portfolio-hover {
    opacity: 1;
}

.portfolio img {
    max-width: 100%;
    width: 100%;
    height: 100% !important;
}

span.portfolio-hover {
    background: rgba(39,39,39,0.95);
    color: #8e8e8e;
    width: 100%;
    height: 100%;
    display: table;
    left: 0;
    position: absolute;
    top: 0;
    bottom: 0;
    opacity: 0;
    -webkit-transition: opacity 500ms;
    -moz-transition: opacity 500ms;
    -o-transition: opacity 500ms;
    transition: opacity 500ms;
}

span.portfolio-hover span {
    display: table-cell;
    text-align: center;
    vertical-align: middle;
}

Any assistance would be highly appreciated!

For a live demonstration, you can visit this link and navigate to the portfolio section to hover over an image.

Answer №1

Update the style of span.portfolio-hover to have display:block instead of display:table

Answer №2

Consider utilizing the height in pixels based on the original image or whatever the height of your image is.

height:388px

Appreciated

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

Ways to achieve text transparency with CSS without converting it to an image

Is there a way to have my navigation bar indicate the selected page by changing the text color and adding a black background, while making only the text inside the current page nav transparent? For example, you can see the effect here: sammarchant.co.uk/n ...

When attempting to use the ResponsiveSlides plugin, the functionality of 'Image links' seems to be disabled in the Chrome browser

While everything is functioning perfectly in Firefox and IE, I've encountered an issue with Chrome. It only works after right-clicking and inspecting the element; once I close the Inspector, it stops working - displaying just an arrow cursor as if the ...

What could be causing my CSS transitions to fail when using jQuery to add classes?

I'm currently working on a website and I'm facing an issue with the transition not functioning as expected. The problem persists even when the 7.css stylesheet is removed and interestingly, the transition works fine when using window:hover. My a ...

Can you explain the concept of "cascading" within CSS?

Can someone kindly explain the specific definition of "Cascading" in Cascading Style Sheets (CSS)? I have heard conflicting perspectives on this topic, so I am seeking clarification here. Any examples to illustrate would be greatly appreciated. ...

Adjusting the image height to match the container height while preserving its original aspect ratio

Is there a method, using CSS alone, to adjust an image's height to fit its container while preserving aspect ratio and allowing the overflow of width to be concealed? It may seem like a complex set of requirements, but is it achievable? Essentially, I ...

Arranging divs within a wrapper, ensuring that one of them displays a vertical scrollbar when the content exceeds the space available

I'm currently facing a challenge with defining the height of the description box in order to achieve the layout shown. I am trying to find a solution without relying on javascript. https://i.stack.imgur.com/3j278.png At present, the wrapper and titl ...

"Creating multiple circles on an HTML5 canvas using an iPad: A step-by-step guide

My current code is only drawing one circle at a time on an iPad view, but I want to be able to draw multiple circles simultaneously. How can I achieve this? // Setting up touch events for drawing circles var canvas = document.getElementById('pain ...

Bootstrap 4: Concealed and Revealed Columns?

Is anyone else experiencing an issue where xs is hidden in xs views? I have a hunch it might be due to changes in Bootstrap v4, but I'm curious if there's a way to still make it work without delving into the CSS. My current setup uses the default ...

Icon displayed within the input field

Is there a simple method to add an input text element with a clear icon on the right side, similar to the layout of the Google search box? I've searched, but I could only find instructions for placing an icon as the background of the input element. I ...

Interactive div with dynamically generated click event

I need to add an onclick event to a button that is being generated dynamically via ajax. How can I achieve this? This is the code responsible for generating the content. When we click on an item, I want a popup window to appear. function retrieveTableDat ...

Tips for deciding on the appropriate CSS for an Angular 6 navbar component

I am currently working on an angular 6 application where users are assigned different roles that require distinct styling. Role 1 uses Stylesheet 1, while Role 2 uses Stylesheet 2. The Navbar component is a crucial part of the overall layout structure of ...

Stylish Wave Animation Effects in CSS for iPad Native Application

The ripple effect on the iPad Native app is malfunctioning. The effect is mistakenly applied to all buttons in the navigation instead of just the li elements. Please identify the error and provide a solution. (function (window, $) { $(function() ...

Vibrant Reverberation of Color

When creating a table connected to a MySQL database, I encountered an issue with changing the text color inside the rows. How can I display the text in white within the table? I attempted to use <style = color #34242, but it didn't produce the des ...

I'm looking for a way to implement an interactive auto slideshow in JavaScript that allows users to manually

Having spent a lot of time studying auto slideshows, I'm facing an issue where clicking on the bullet to show the next image results in the image disappearing suddenly. Initially, I thought the problem was with using addEventListener events, so I swi ...

Newcomers to Visual Studio Code facing a problem with images not displaying

As a beginner in all aspects, I am currently facing an issue with displaying an image on Visual Studio Code. The problem arose when I tried to create a separate folder for the image, which resulted in a cascade of subfolders that only made things worse eac ...

Is there a way to use Selenium to perform testing on a web UI that generates XML content instead of HTML?

Utilizing Selenium for testing my Perl cgi script has been successful overall, but I've encountered a unique issue in one particular test case. In this scenario, the cgi script returns XML content to the web browser instead of the expected HTML conten ...

"Encountering an issue with the live preview feature in Br

Currently, I am working on a project offline and trying to make Brackets' live preview feature work smoothly. It has proven to be quite convenient for my tasks. While opening my project files using the "open file" option in Brackets, I encountered an ...

Transfer information to a different html page and store it

Seeking guidance on transferring the entire content of input.html to approve.html for validation and database storage. Any tips or advice would be greatly appreciated as I am new to this and have been struggling with this issue for a week. <form action= ...

Unusual Blank Space in HTML CSS Design

While working on my website, I noticed a peculiar white space appearing at the bottom of the page, but only when using Internet Explorer. Safari looks fine. I am currently using IE8. I would like the white background to end after the black navigation link ...

HTML: Choose from a list of options by selecting multiple items from

I want to implement a select field with the multiple attribute as a standard dropdown field with size=1: <select name="test[]" size="1" multiple> <option>123 <option>456 <option>789 </select> Any reason why the a ...