CSS styling failing to meet desired expectations

Two different elements from different panels are using the same CSS styles, but one displays the desired text while the other does not. The CSS file in question is named grid.css.

To see the issue firsthand on my live website, please visit:

I am uncertain whether the problem lies with the JavaScript linked to the element or if video files inherently cover text, so I have shared the full website for easier debugging purposes. Here is the corresponding GitHub repository: https://github.com/kaweepatinn1/kaweepatinn1.github.io

Despite attempting various modifications to the CSS settings and inspecting the element in Developer Tools, I cannot identify the source of the issue since one element behaves flawlessly with seemingly identical CSS code.

The problematic HTML excerpt is as follows:

      <a href="TO SET">
<div class="applead grid-item" onmouseover="regifApple()" onmouseleave="revertApple()">
<img class="img" id="appleimage" width="100%" height="auto" src="./static/assets/applead.webp" alt="Applead Image">
  <div class="img-caption">
    <div class="vid-title">
      Mock Apple Ad
    </div>
    <div class="vid-director">
      Animation and Motion Graphics
    </div>
  </div>
</img>
</div>
</a>
<a href="TO SET">
  <div class="OYYGC grid-item" onmouseover="regifOYYGC()">
  <video class="img" id="OYYGCimage" width="100%" height="auto" src="./static/assets/OYYGC.mp4" loop muted="muted" alt="OYYGC">
    <div class="img-caption">
      <div class="vid-title">
        Oh Yeah You Gonna Cry?
      </div>
      <div class="vid-director">
        Animated x Live Music Video
      </div>
    </div>
  </video>
  </div>
  </a>

The relevant CSS classes are defined as:

.grid-container {
    display: grid;
    grid-template-columns: auto auto auto;
    justify-content: space-evenly;
  }

.grid-item{
    height: 17w;
    margin: 1vw;
}

/* Remaining CSS class definitions can be found above */

If necessary, the associated JavaScript functions are included below:

var mouseOverApple = false;
var mouseWasGoneApple = true;

// Remaining JavaScript functions omitted for brevity

Answer №1

When working with HTML, it's important to note that you cannot directly nest a <div> element inside a <video> tag. The purpose of the <video> element is specifically for displaying video content and does not support block-level elements like <div>.

If you need to overlay content on top of a video or position content around a video element, there are alternative ways to structure your HTML code.

To address this issue, simply move the div tag with class="img-caption" outside of the <video> tag as shown below:

<a href="TO SET">
    <div class="OYYGC grid-item" onmouseover="regifOYYGC()" bis_skin_checked="1">
        <video class="img" id="OYYGCimage" width="100%" height="auto" src="./static/assets/OYYGC.mp4" loop="" muted="muted" alt="OYYGC"></video>
        <div class="img-caption" bis_skin_checked="1" style="pointer-events: none;">
            <div class="vid-title" bis_skin_checked="1">Oh Yeah You Gonna Cry?</div>
            <div class="vid-director" bis_skin_checked="1">Animated x Live Music Video</div>
        </div>
    </div>
</a>

Include the CSS code snippet below to ensure proper functionality:

.OYYGC .img-caption {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.OYYGC .img-caption .vid-director {
  bottom: 15px;
}

Answer №2

The issue arises from placing the img-caption within the video element, causing it to display only if the user's browser does not support the video tag.

According to the source code in your repository, you should use the following structure instead:

<div class="OYYGC grid-item" onmouseover="regifOYYGC()">
  <video class="img" id="OYYGCimage" width="100%" height="auto" src="./static/assets/OYYGC.mp4" loop muted="muted" alt="OYYGC"></video>
  <div class="img-caption">
    <div class="vid-title">
      Oh Yeah You Gonna Cry?
    </div>
    <div class="vid-director">
      Animated x Live Music Video
    </div>
  </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

What is the best way to emphasize a div depending on a query outcome?

A new application is in the works for a gaming project. This app is designed to display the location of a specific monster, utilizing a database containing information about monsters and their corresponding maps. Currently, the application functions almos ...

Maximizing cell background color in HTML table with limited width fails to function properly

Having difficulty turning the header cells (th) with background-color applied? It seems like the color bar may be too small, the cell width too large, or the background isn't being affected properly. Is there a way to create a narrow cell with long t ...

Enhancing Canvas with a JPEG layer using the Caman library

I'm currently working with the Caman library to manipulate an image. My goal is to overlay a jpeg onto the manipulated image, but I'm facing a challenge. Although I can briefly see the jpeg beneath the manipulated image, it quickly gets overlai ...

Utilizing erb within a coffeescript file for modifying the background styling

Is there a way to change the background image of a div based on user selection from a dropdown menu? For instance, if the user picks "white" the background image becomes white, and for "red" it changes to red. I'm struggling with this in coffeescript ...

What is the best way to capitalize the first letter of a string in JavaScript?

Is there a way to capitalize only the first letter of a string if it's a letter, without changing the case of any other letters? For example: "this is a test" → "This is a test" "the Eiffel Tower" → "The Eiffel ...

How can I execute a synchronous MongoDB query in Node.js properly?

When utilizing the Node.JS driver for MongoDB, I am interested in executing a synchronous query. Here is an example of what I am aiming to achieve: function retrieveSomething() { var database = new mongo.Db("mydatabase", server, {}); database.ope ...

The issue of variable stagnation in Firefox content script while utilizing self.port.on

I'm having trouble updating the version var as intended. When I try to update it with the following code: self.port.on("get-version", ver => { version = ver; alert(version); }); An alert pops up displaying the correct version number, but the HTML ...

Tips for stopping execution in Discord.js if the user no longer exists?

I'm currently working on a discord bot and encountered a minor issue. I am using "messageReactionRemove" and "messageReactionAdd" to manage certain roles by removing or adding them, but the problem arises when a user leaves the server. When this happe ...

Sorry, we encountered a snipcart issue: The public API key was not found. To fix this, please ensure that the attribute data-api-key is

I'm experiencing issues with loading Snipcart correctly. It's able to detect the API key on localhost and display the number of items in the cart, but when deployed to Netlify, it briefly shows the item count before displaying the error message: ...

Ensure equal width for an HTML element by matching it with the dimensions

Hello, I am facing an issue with a dropdown button. Whenever I hover over it, the links to different pages drop down. However, I want the width of these links to be the same as that of the button. The size of the button varies as it is set to 100% width o ...

Express JS encountering Firebase Google Sign-In glitch

Whenever a user clicks a button on the HTML page, this function is triggered. The function resides in auth.js and it is called from the server.js page. auth.js const firebase = require("firebase"); static googleSignIn(req,res){ firebase.aut ...

Tips for Setting Up Next.js 13 Route Handlers to Incorporate a Streaming API Endpoint via LangChain

I am currently working on establishing an API endpoint using the latest Route Handler feature in Nextjs 13. This particular API utilizes LangChain and streams the response directly to the frontend. When interacting with the OpenAI wrapper class, I make sur ...

Exploring outside iframe data

My webpage includes an iframe A with a src attribute that links to a URL containing another embedded iframe B. I'm trying to figure out if it's possible to access the src of this nested iframe B. However, it appears that browser security measures ...

Is employing absolute paths in our confidential Node dependencies a good idea?

I have recently organized our codebase's React components into a separate dependency to make them reusable across different projects. To improve readability, all components now utilize Webpack aliases: import TestComponent from 'components/TestCo ...

Issues with the Diagonal HTML Map functionality

I'm seeking assistance to implement a unique Google Maps Map on my webpage. I have a particular vision in mind - a diagonal map (as pictured below). My initial approach was to create a div, skew it with CSS, place the map inside, and then skew the ma ...

Attempting to streamline this particular JavaScript function

I have been struggling with a function that I believe could be written more effectively. My goal is to simplify it while still maintaining its functionality. function changeLetters(text) { text = text.toLowerCase(); for (var i = 0; i < text.length; ...

Utilizing Ajax to serialize or transfer JSON objects

I have received a Json object and I am looking to extract the data using JavaScript. Specifically, I need help with looping through fields and extracting the data. def For_Sale_Listing(request,id): try: listing = Listing.objects.filter(pk=id) ...

Guide to adding content and icons to the top navbar on the right side using vue.js

In the process of developing a fixed top navbar, I encountered an issue while trying to add right side icons and additional content. The goal is to include two icons, as shown in this example: example link, along with profile and cart information on the ri ...

Each time the Jquery callback function is executed, it will return just once

Whenever a user clicks on the "customize" link, I trigger a function to open a dialog box. This function includes a callback that returns an object when the user clicks "save". The problem is, each time the user clicks "customize", the object gets returned ...

What could be causing my selenium tests to fail on travis-ci even though there have been no code changes, when they are passing successfully

I'm facing a tough challenge trying to troubleshoot a selenium test that passes when run locally but not on travis. Reviewing the travis build logs, I noticed that the test was passing in build #311 but started failing at build #312. It seems like th ...