Play button icon is missing in Firefox when using absolute positioning

I'm currently experiencing an issue with my video gallery section. I have both normal and hover versions of a play button positioned above a preview image of a video. However, the play buttons are not visible at all in Firefox. You can view the page here, and here is the code snippet:

<div class="videoPreview">
    <div class="videoPreviewImg">
        <img src="img/promo/groupFitness.jpg">
        <i class="playButtonHover"></i>
        <i class="playButton"></i>
    </div>
</div>

div.videoPreview {
  float: left;
  display: inline-block;
  width: 21%;
  margin: 2%;
  margin-bottom: 0;
}

div.videoPreview:last-child {
  margin-bottom: 2%;
}

div.videoPreviewImg { 
  position: relative;

}

div.videoPreviewImg img {
  max-width: 100%;
  z-index: 1;
}

div.videoPreviewImg i {
  position: absolute;
  z-index: 5;
  top: 50%;
  left: 50%;
  margin-top: -24px;
  margin-left: -24px;
  -webkit-transition: opacity .7s ease-in-out;
  -moz-transition: opacity .7s ease-in-out;
  -o-transition: opacity .7s ease-in-out;
  transition: opacity .7s ease-in-out;
}

div.videoPreviewImg:hover i.playButton {
  opacity: 0;
}

I would really appreciate any assistance with this problem!

Answer №1

div.videoPreviewImg { 
  position: relative;
}

The 'wrapping' div that contains the playbuttons is set to a relative position, while the playbuttons themselves are set to an absolute position.

Absolutely positioned elements are taken out of the normal flow of the document. They position themselves in relation to their closest positioned ancestor. When a wrapping div is set to relative positioning, absolutely positioned children will align themselves within that parent. However, because the absolutely positioned element is no longer part of the flow, the parent div might collapse as it appears empty to its content area.

If there is no explicitly positioned containing div, then the absolutely positioned element will reference the next level up parent for its positioning.

You have two options: you can change the position of the playbuttons to absolute:

div.videoPreviewImg { 
    position: absolute;
}

Or you can try setting the position of the playbuttons to relative and adjusting their appearance using margins.

Be aware that different browsers might interpret these positioning rules differently, so don't solely rely on one browser for testing.

UPDATE

After checking your website in Firefox version 3.6.28, I noticed something interesting:

The first preview button displays correctly, but upon further inspection of your code, I found an issue with how the playbuttons are declared for the other videos:

<i class="playButtonHover"></i>
<i class="playButton"></i>

These should actually be like this:

<img class="playButtonHover" src="../img/playButtonHover.png">
<img class="playButton" src="../img/playButton.png">

So, even though the buttons do appear, they lack an image source for display.

I also noticed that Chrome seems to fix some syntax errors automatically, which might explain why it works in that browser despite the incorrect syntax.

To resolve this issue, make sure to use the correct syntax for the playbuttons by replacing the i tags with either divs or img tags.

Good luck!

Answer №2

Apologies for my focus on the main slideshow/video player yesterday...

To correct the other play buttons, modify:

.playButton {
  content: url(../img/playButton.png);
}
.playButtonHover {
  content: url(../img/playButtonHover.png);
}

to

.playButton {
  background: url(../img/playButton.png);
}
.playButtonHover {
  background: url(../img/playButtonHover.png);
}

and specify a specific size, for example:

div.videoPreviewImg i {
  position: absolute;
  z-index: 5;
  top: 50%;
  left: 50%;
  margin-top: -24px;
  margin-left: -24px;
  -webkit-transition: opacity .7s ease-in-out;
  -moz-transition: opacity .7s ease-in-out;
  -o-transition: opacity .7s ease-in-out;
  transition: opacity .7s ease-in-out;
  width:48px;
  height:48px;
}

Lastly, assign a fixed width to the video preview instead of a max-width:

div.videoPreviewImg img {
  width: 100%;
  z-index: 1;
}

The content CSS property is utilized with the ::before and ::after pseudo-elements to generate content within an element. Objects inserted using the content property are anonymous replaced elements. - MDN

Content CSS | MDN
You were inadvertently misusing the content property, resulting in inconsistent outcomes. Visit the link provided above for further clarification.

Answer №3

After some investigation, I believe I have identified the problem and found a solution. Huge thanks to everyone for their contributions and suggestions. It turns out that when I used buttons as images instead of icons, they displayed properly in Firefox. Although this goes against my preference since buttons are not technically considered content, it seems to be the only effective workaround so far. Once again, thank you all for your help!

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

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 ...

The touch event doesn't seem to be functioning properly on the div element, but it works perfectly on the window element

I have a dilemma that's been puzzling me lately. I'm trying to append a touchevent to a div, but my current method doesn't seem to be working. Here's what I've tried: $("#superContainer").bind('touchstart', function(even ...

How to eliminate the vertical scroll indicators in Material UI's TextField

I'm currently working on customizing the styling of a Material UI textfield and I need to remove the top-down arrows. Below is the code snippet I have so far: const theme = createMuiTheme({ MuiInput: { root: { "&::-webkit-outer-spin-bu ...

Ways to display a series of images side by side to fill the entire width consistently

I need a solution to display multiple images in a box, all set to the same height and width of 154px x 125px. While this can be achieved, the issue arises when there isn't enough space for the final image, leaving blank areas. Is there a way to make t ...

Change the background color of cells according to the value they contain

I have a scenario where I am populating a table with random numbers, and I want the background color of each cell to change based on the value of the number in that cell. Since these numbers refresh periodically, I need the colors to update accordingly as ...

Spacing applied to content within a fresh Vue application

Having been assigned the task of developing a Vue page for my team, I am facing an issue with a persistent white border surrounding the entire page. <script setup lang="ts"> </script> <template> <body> <div>&l ...

Excessive form inputs extend beyond the modal when utilizing Bootstrap 3

Having an issue loading a modal with Angular and populating it with a template. The main problem I'm facing is that the inputs are extending beyond the boundaries of the modal - attached below is a screenshot illustrating the problem: Below is the c ...

What to do when encountering a problem with HTML, CSS, and JS while loading a webpage from an SD card to a WebView

I am facing an issue while loading an HTML file from the SD card to a webview. The problem is that the CSS, images, and videos are not loading properly in the webview. Compatible with Android 4.4 KitKat and Chrome version Not compatible with versions belo ...

Ways to add gaps between flexbox items within a single row?

I have a coding dilemma where I am trying to display two items in the same row with a 12px gap between them, but my current method is not working as desired. I want there to be space between the A's and B's without resorting to traditional techni ...

I find myself struggling to manage my javascript dependencies

Currently, I am utilizing NPM along with various angular packages. As per the tutorial on Basic Grid Part 1 at this link, I am encountering challenges. This is my file directory structure: D:/nodeStuff/uiGrid includes: node_modules uigrid.css uigrid.h ...

Guide for creating a scroll-triggered rotation animation using only JavaScript

Looking to achieve a cool scroll effect with an image that rotates on the X-axis by a specific degree, such as 70deg. The goal is to have the image's rotateX value change to 0deg when it enters the viewport upon scrolling and revert back to 70deg whe ...

Create a moving background gradient with styled-components

Currently, I am working on setting the background of the <Paper /> component using Material-UI version 1.0.0-beta.25 to display a gradient of colors. The colors are dynamically added by clicking the Add button and selecting one from the color picker. ...

A centered Bootstrap navigation bar on a WordPress site

My Bootstrap navbar is floating in the center on WordPress and I'm not sure why. Can anyone help me with this issue? Could it be related to WordPress or my stylesheet problems? (Will update my code here if you need) STYLES.CSS .navbar-default { ...

How can I display a clicked-on div while hiding all other divs using jQuery?

I want to create a website where a button can show and hide a specific div, but my challenge is; How can I ensure that clicking on one button hides all other divs? Here is the JavaScript code: function showHide(divId){ var theDiv = document.getEleme ...

Having trouble with CSS :before pseudo-element and sibling selector?

Looking for a CSS solution to change the appearance of a triangle when the .hide class is activated within my markup. I attempted using a pseudo-element like so: summary:before { content: '\25BC'; } summary:before + .hide { con ...

Truncate a string in Kendo Grid without any white spaces

While using a Kendo-Grid for filtering, I've come across an issue where my cell does not display the full string if there is no white space. The problem can be seen in the image below: For example, the string "https://www.linkedi/Testing" is only dis ...

Rotating SVG graphics with a growth effect

Check out my CSS below: /* -------------------------- Base --------------------------- */ body { padding-top: 60px; background: #0f4e7a; } svg { margin: auto; display: block; width: 28%; } .star{ fill: #FFF; } /* ------------------ ...

Conceal the div on larger screens and display it on mobile devices

I have a fixed navigation bar at the top of my website. By default, it is always visible on all pages, but I want to hide it on desktop screens and display it only on mobile devices. Here is what I have implemented: @media (min-width: 992px) { #sp-he ...

Adaptable images - Adjusting image size for various screen dimensions

Currently, my website is built using the framework . I am looking for a solution to make images resize based on different screen sizes, such as iPhones. Can anyone suggest the simplest way to achieve this? I have done some research online but there are t ...

Place an image on top of adsense

Is there a way to overlay an image on top of Google AdSense ads in order to track user clicks? I am trying to implement an onclick method for when someone clicks on the ads. .ad-alert { width: 728px; height: 400px; background: #cccccc; mar ...