CSS is causing trouble with text not showing up when hovering over it

I have been trying to make the p element visible upon hovering over the image, but so far, nothing seems to be happening. The text is initially visible on the page, leading me to believe that the transform property may not be functioning as expected. I've included all the code for this page, including the header code which I'm not sure is necessary but I included it just in case.

Despite looking up similar questions and even asking one myself, I still can't find a solution. I've tried different browsers without any success.

* {
  margin: 0;
  padding: 0;
  text-decoration: none;
  list-style: none;
}

.header {
  width: 100%;
  height: 80px;
  display: block;
  background-color: #101010;
}

.inner-header {
  width: 1000px;
  height: 100%;
  display: block;
  margin: 0 auto;
}

.logo-container {
  height: 100%;
  display: table;
  float: left;
}

.logo-container h1 {
  color: white;
  height: 100%;
  display: table-cell;
  vertical-align: middle;
  font-size: 32px;
  font-weight: 200;
}

.logo-container h1 span {
  font-weight: 800;
}

.navigation {
  float: right;
  height: 100%;
}

.navigation a {
  height: 100%;
  display: table;
  float: left;
  padding: 0px 20px;
}

.navigation a li {
  display: table-cell;
  vertical-align: middle;
  height: 100%;
  color: white;
  font-size: 16px;
}

.navigation a:last-child {
  padding-right: 0;
}

.mission {
  width: 80%;
  height: 350px;
  margin: 5px auto;
  position: relative;
}

.mission p {
  position: absolute;
  font-size: 30px;
  bottom: 50%;
  left: 25%;
  transform: scale(0);
  transition: .25s ease-in-out
}

.mission img:hover+.mission p {
  transform: scale(3);
  transform-origin: center;
}

.mission img {
  width: 100%;
  height: 100%;
  position: relative;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <link rel="stylesheet" href="./Grid2.css">
          <title>Awesome Website</title>
</head>

<body>
  <div class="header">
    <div class="inner-header">
      <div class="logo-container">
        <h1>MY<span>SITE</span></h1>
      </div>
      <ul class="navigation">
        <a>
          <li>Home</li>
        </a>
        <a>
          <li>About</li>
        </a>
        <a>
          <li>Portgolio</li>
        </a>
        <a>
          <li>Contact</li>
        </a>
      </ul>
    </div>
  </div>
  <div class="mission">
    <img src="./330px-GABRIEL_VELLA_vs_ROMINHO_51.jpg">
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ducimus nesciunt ratione animi facilis. Quo, et?</p>
  </div>

</body>

</html>

My expectation is for the text to appear upon hovering, but currently it remains stagnant.

Answer №1

If you're looking to place the p tag on top of an image, one way to achieve this is by using the hover function and applying a transformation. You can see an example of this in action on Codepen: https://codepen.io/lewisnewson/pen/BaBdEzB. Just add the following code snippet after your current hover CSS:

.mission:hover p {
  display: block;
  transform: scale(1);
}

Answer №2

Oops! Your selector for the p element is incorrect. Instead of:

.mission img:hover+.mission p

The correct selector should be:

.mission img:hover+p

Additionally, to prevent the p element from disappearing after hover, you need to add pointer-events: none to it.

Code Snippet

* {
  margin: 0;
  padding: 0;
  text-decoration: none;
  list-style: none;
}

.header {
  width: 100%;
  height: 80px;
  display: block;
  background-color: #101010;
}

.inner-header {
  width: 1000px;
  height: 100%;
  display: block;
  margin: 0 auto;
}

.logo-container {
  height: 100%;
  display: table;
  float: left;
}

.logo-container h1 {
  color: white;
  height: 100%;
  display: table-cell;
  vertical-align: middle;
  font-size: 32px;
  font-weight: 200;
}

.logo-container h1 span {
  font-weight: 800;
}

.navigation {
  float: right;
  height: 100%;
}

.navigation a {
  height: 100%;
  display: table;
  float: left;
  padding: 0px 20px;
}

.navigation a li {
  display: table-cell;
  vertical-align: middle;
  height: 100%;
  color: white;
  font-size: 16px;
}

.navigation a:last-child {
  padding-right: 0;
}

.mission {
  width: 80%;
  height: 350px;
  margin: 5px auto;
  position: relative;
}

.mission p {
  position: absolute;
  font-size: 30px;
  bottom: 50%;
  left: 25%;
  transform: scale(0);
  transition: .25s ease-in-out;
  pointer-events: none;
}

.mission img:hover+p {
  transform: scale(3);
  transform-origin: center;
}

.mission img {
  width: 100%;
  height: 100%;
  position: relative;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="./Grid2.css">
  <title>Awesome Website</title>
</head>

<body>
  <div class="header">
    <div class="inner-header">
      <div class="logo-container">
        <h1>MY<span>SITE</span></h1>
      </div>
      <ul class="navigation">
        <a>
          <li>Home</li>
        </a>
        <a>
          <li>About</li>
        </a>
        <a>
          <li>Portgolio</li>
        </a>
        <a>
          <li>Contact</li>
        </a>
      </ul>
    </div>
  </div>
  <div class="mission">
    <img src="./330px-GABRIEL_VELLA_vs_ROMINHO_51.jpg">
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ducimus nesciunt ratione animi facilis. Quo, et?</p>
  </div>

</body>

</html>

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

The focus state persists even after the DOM element has been modified

I am currently utilizing Vue along with Bulma. My challenge lies in updating the DOM upon a button click event. Even after the update, the button still retains its focus state. I aim to have the updated button without the focus state. What would be the m ...

Instructions for creating a Google Maps overlay that hovers above the zoom bar

Let me share my workaround for creating an overlay and dealing with z-index issues when using Google Maps API. The problem arises when dragging the map and the overlay ends up behind control elements like the zoom bar. No matter how much I adjust the z-ind ...

Encountered a runtime error while trying to insert a list item <li> into a paragraph <p> element

Take a look at this code snippet: <%@ Page Title="Home Page" Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication18._Default" %> <!DOCTYPE html> <html> <body> <p id="someId"></p& ...

Using MutationObserver in an iFrame with JavaScript

I currently have an iframe that is loaded with the source www.abc/main.html <iframe id="my-iframe" src="http://www.abc/main.html"></iframe> The main.html file from abc imports and runs some JavaScript files. My goal is to utilize a MutationO ...

Rotating an HTML caret using CSS does not pivot from the center point

Is there a way to adjust my simple caret rotation to make it rotate from the center? What changes should I make? const Wrap = styled.div` width: 100px; background: grey; span { display: block; transform: ${(props) => (props.isOpen ? " ...

Pass a jQuery value to a PHP variable

I am looking to send a value when I click a button. For example, when I click on <a id="link1"> Page Home </a>, it should send the value to a custom variable php. Here is an example: <?php $linkredirect = ''; // This will be sent ...

What is the best way to display the element from a list with a distinct identifier using Thymeleaf within a Spring Boot application?

In my entity class, I have an array list that stores a list of enrolled students. Clicking the student button will display the list of enrolled students. Check out the enroll student page in the screenshot below. However, when clicking on another button to ...

Incorporating jQuery to Load Content into a DIV while preserving the original JavaScript

I am attempting to implement the following <script> $(document).ready( function() { var data = 'testing' $("#about").on("click", function() { $("#main-content").load("/about.html"); ...

Is there a way to embed an AJAX submit form into a notification without the need for page refresh?

I have integrated the jQuery plugin toastr js () for notifications on my website. I am facing an issue where I want to include a contact form within the notification popup and submit it using AJAX. Despite having the form working fine outside of the toastr ...

An error has occurred in the Shadow Dom due to the inability to access the property 'style' of an

While working on a component using shadow DOM, I encountered the following error in the console: "Cannot read property 'style' of undefined". This issue seems to be related to my HTML code in PHP. The main challenge I am facing is figuring out ho ...

How can I modify the language of a session in asp.NET?

As a newcomer, I am eager to create some basic hyperlinks that can alter the session language parameter. Afterwards, I plan to experiment with this parameter in order to dynamically display different elements on the page. I have searched high and low for ...

Summernote carries out encoded HTML scripts

Retrieving information from a MySQL database, the stored data appears as follows: <p>&lt;script&gt;alert('123');&lt;/script&gt;<br /></p> Upon fetching the data in its raw form, it displays like this: <script ...

Transforming JQuery Output into an HTML Table Layout

Hello there! I am currently working on parsing an XML file within my web page using jQuery. Here is a snippet of the code: function loadCards(lang) { $.ajax({ type: "GET", url: 'data.xml', dataType: "xml", suc ...

Upon logging in to the first HTML page, the user will be automatically redirected to the second HTML page while passing values

Is there a way to automatically redirect users to Login2.html when selecting "TEAM" in the dropdown on Login1.html, using the values entered in Login1.html? Similarly, can we redirect them to the Premium page when they select "Premium"? I need a solution u ...

Ways to display the title of the image being viewed

I had an issue while working with the input type="file" in HTML. Every time I tried to browse a new image, the name of the image did not show up beside the button. Can anyone provide some guidance on how to fix this problem? Here is my fiddle with the cod ...

What are some ways I can efficiently load large background images on my website, either through lazy loading or pre

Just dipping my toes into the world of javascript. I'm currently tackling the challenge of lazy loading some large background images on my website. My goal is to have a "loading" gif displayed while the image is being loaded, similar to how it works ...

THREE.js: dual scenes sharing identical camera positions

I'm currently working on a project where I have two overlapping scenes. The top scene can be faded in and out using a slider, and users can rotate objects within the scene for a better view. My challenge is to keep the camera position consistent betw ...

Center alignment is not possible for the Div element

Problem Every time I attempt to implement the following code (outlined below), the div only appears centered when using width: 100px;. <div style="border: solid 1px black; width: 100px; height: 100px; background-color: blue; margin-left: auto; mar ...

Confirmation for deletion in HTML form

Is there a way I can include a confirmation message for deleting an item on my form button? Any suggestions on which JavaScript code to use? <script type="text/javascript"> function confirmDelete() { return confirm("Are you sure you want to delete ...

Ensure that the tooltip remains visible within the confines of the page

In my Angular application, I have successfully implemented a versatile tooltip feature that goes beyond just displaying text. The tooltip is a div element that has the ability to contain various contents: .tooltip-master { position: relative; .tooltip ...