Show the Table and Conceal the Overflow

Currently, I am experimenting with creating an Img hover for entertainment purposes. However, I have added some text to my div. In order to center the text beautifully within my div, I utilized the following CSS code:

display: table-cell;
vertical-align: middle;

In addition, I have implemented the following CSS code as well:

.vertical-smallborder{
    position: relative;
    width: 217px;
    height: 350px;
    border: 5px solid white;
    outline: 1px solid #c8c8c8;
    float:left;
    display: table;

    -webkit-transition: all .3s;
    -moz-transition: all .3s;
    -ms-transition: all .3s;
    -o-transition: all .3s;
    transition: all .3s;

    overflow: hidden;
}

I specifically included the display: table in this section to facilitate text alignment. Removing it would disrupt the centered positioning of the text.

However, I encountered a complication with the use of overflow: hidden. This property no longer functions properly in FireFox and IE when combined with display: table.

On the contrary, both Google Chrome and Safari enable seamless compatibility between display: table and overflow: hidden.

Please note that I prefer a pure CSS solution and cannot incorporate any JavaScript for this task.

Thank you!

Answer №1

Firefox Demo - Demonstrating Possibilities

In order to showcase the capabilities for Firefox, I have put together a demonstration below:

<div class="image-clipper">
    <img src="http://placekitten.com/400/500" style="margin: -150px 0 0 -100px;" />
    <div class="text-panel">
        <div class="text-cell">
        <h1>Shirt<br/>$24.95</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
        </div>
    </div>
</div>

The CSS used in this demo is outlined below:

.image-clipper {
    width: 250px;
    height: 300px;
    border: 5px solid red;
    overflow: hidden;
    position: relative;
}
.image-clipper .text-panel {
    position: absolute;
    top: 0;
    left: 0;
    display: table;
    height: 100%;
}
.image-clipper .text-cell {
    display: table-cell;
    vertical-align: middle;
    padding: 20px; /* works okay */
    background-color: rgba(255,255,255,0.5); /* applied to entire cell */
}

By implementing this setup, I was able to clip the image within its parent element and position the text appropriately as needed.

For a live demonstration, please visit: http://jsfiddle.net/audetwebdesign/JpMXP/

To Conclude

While I did not have extensive time to investigate every detail of how table/table-cell interacts with overflow: hidden, the approach outlined above appears to be effective and straightforward to comprehend.

Answer №2

My suggestion is to remove the following line from your CSS:

display: table;

and add top and left properties to:

.vertical-smallborder .text

By doing this, all texts will be aligned even if one of them is longer, as they will have the same starting point at the top. This adjustment will enhance the overall appearance.

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

Adjust the width of an item on CSS Grid upon hovering

I recently created a basic CSS grid layout with the following structure... .container { display:grid; grid-template-columns:1fr 1fr 1fr 1fr; } .col1 { padding:20px; background:red; color:white; text-align:center; } .col2 { padding:20px; ...

Using jQuery and Ajax to fade in content after all images and other assets have finished loading

I've encountered an issue with loading pages via ajax for users with custom URLs. For example, a profile is usually found at http://example.com/users/Dan, but if a user has a custom URL like http://example.com/DansCustomURL, I need to fetch their desi ...

Creating a column in CSS that maximizes width without utilizing 100% or causing text wrap

Trying to keep a three-column div from spilling over the page can be tricky. The first two columns must not exceed 200px, while the third column should be at least 280px wide. The issue arises when there is a table in the third column with long sentences i ...

How can I safeguard my HTML and CSS content from being altered using tools similar to Firebug?

Is there a method to deter the alteration of HTML and CSS components on a webpage using tools similar to Firebug? I have noticed that certain users are changing values in hidden fields and modifying content embedded within div or span tags for their perso ...

Alter the color scheme of a paragraph using PHP

I have been working on creating a management panel for a website. My first step was to include an input field to collect a color value: <form> <input type="text" name="test"> <input type="submit" value="Send"> <?php $color = $_REQ ...

Can you tell me which BBC channel is airing this animation?

Is anyone familiar with the animation on the login screen of BBC when entering the day, month, and year? Check it out here: ...

Aligning content vertically in Bootstrap 4 so it is centered

I've been struggling to center my Container in the middle of the page using Bootstrap 4. I haven't had much luck so far. Any suggestions would be greatly appreciated. You can check out what I have so far on Codepen.io and experiment with it to s ...

Samsung Galaxy S7 can interpret alphabetical parameters as numbers in a link sent via SMS

When trying to open a text message with a new message on my website using a link, I encountered an issue specifically with the Galaxy S7. The following code works on most Android phones: sms:5555555555?body=JOIN However, on the Galaxy S7, the "?body=JOIN ...

Creating a CSS3 Grid Layout with a Fixed Header

I'm having some trouble creating a layout using CSS Grid. My goal is to make the header element 'sticky', so that it remains fixed at the top of the viewport while other content scrolls up and underneath it. Additionally, I want to add a bac ...

Tips for adjusting an image to fit your carousel

I am dealing with a carousel that has fixed dimensions (e.g., width=800px, height=450px), but the images I want to display in it have varying aspect ratios (16 : 9, 16:10, 1:1, etc.) and are larger than the carousel itself. I am attempting to resize all th ...

Adjust padding of radio button labels in Qualtrics for a cleaner, more streamlined appearance

As I delve into the world of CSS, my goal is to customize the existing survey theme known as "Minimal 2014". Specifically, my focus is on minimizing the spacing in various areas to create a more compact design. So far, I've successfully reduced the g ...

Is it possible to nest a <dl> list within a <li> item?

Would it be considered semantically accurate to include a dl (along with some dt / dd elements) inside a li tag? While it's common to add block or inline elements within an li element, the feasibility of including dl, dt, and dd elements is uncertain ...

"Guide to triggering the display of a particular div based on its class when clicked

I have multiple div elements with the class name dis HTML: <div class="dis">Content</div> <div class="dis">Content</div> <div class="dis">Content</div> and so on ... Additionally, there are various images: <img sr ...

What is the best way to combine a string with a variable in sass?

Is there a way to merge a string and a variable in Sass to form a variable name that is already present? $size: "sm"; $button-sm: 1rem; $buttom-md: 1.5rem; body { font-size: $button-#{$size}; } The desired output is: body { font-size: 1r ...

Using Jquery to target all elements except for their child elements

I have the following code: <div id="mn"> <span></span> <span> <span></span></span> <span></span> <span> <span></span></span> <span></span> </div& ...

VueJS is utilized to duplicate the innerHTML output value

Currently diving into the world of Vue, I encountered an issue while rendering an HTML text. My component template is a WYSIWYG editor. <template> <div id='editor_container'> <slot name="header" /> <div id='editor ...

Position the text in the exact center of an HTML element using absolute positioning

Hey there! I am currently working on a website and I'm trying to create a simple delete button that can be used throughout the site. However, I'm having trouble getting it positioned correctly... Here's what I have so far: <button id="c ...

Two collapsible menus featured in the navigation bar

My navbar is displaying two collapse menus, but when one is active and I open the second one, the collapsed content from the second menu gets added to the end of the first one's content. How can I close the other menu when opening the second one? h ...

Encountering additional backslashes ("") in each slash within the JSON response received from Laravel AJAX

I have been working on my Laravel app and attempting to make an ajax call. However, I am encountering an issue where there is one extra slash being added, whether it's a backslash or a forward slash. Can someone please explain why this is happening an ...

Is there a way to display shortened text only when hovering without altering the height of the list box?

Here is my script for a vue component : <template> ... <b-card-group deck v-for="row in formattedClubs"> <b-card v-for="club in row" img-src="http://placehold.it/130?text=No-image" img-alt="Img ...