The contents within the <div> element are not appearing on the webpage

I've been attempting to design a card that performs a 3D rotation when the mouse hovers over it. While I've successfully incorporated the background and front image of the card, I'm facing an issue with adding text to it.

Here is the incorrect HTML code:

    <div class="front">
        <div class="front_card_icon">
            <img src="image/indoor_plants_icon_white.svg">
        </div>

        <p>THIS TEXT IS CAUSING THE ISSUE</p>
    </div>

Erroneous CSS code:

.front {
    width: 100%;
    height: 100%;
    overflow: hidden;
    backface-visibility: hidden;
    position: absolute;
    transition: transform .6s linear;
    background-color: #2D3436;
}

.front_card_icon {
    position: relative;
    bottom: 8%;
    transform: scale(0.70);
    z-index: 2;
}

.front p {
  positon:relative;
  text-align: center;
  color:white;
}

Despite applying position: relative to the <p> tag as suggested, the text remains invisible.

You can view the problem on jsfiddle. In the example provided, the text is visible as the image fails to load. However, when the image loads (even though it is transparent), the text disappears.

Thank you for looking into this issue!

Answer №1

<div class="front">
    <div class="front_card_icon">
        <img src="image/indoor_plants_icon_white.svg">
    </div>

    <p>Text to be centered vertically on top of image</p>
</div>

The positioning of the text within the parent container is a bit off due to the placement of the p tag below the image. This causes the text to be hidden behind the image.

To properly center the text within its parent div, here are a few steps you can take:

  1. Use position: absolute to break the p tag out of the normal flow, ensuring it is positioned correctly (though it may be hidden behind the image).

  2. Bring the p tag to the front using z-index: 2.

  3. Vertically center the p tag with the following CSS:

   position:absolute;
   top: 50%;
   transform: translateY(-50%);

For an updated example, check out this fiddle

An alternative solution could involve using the image as a background, removing it from the content flow and allowing the text to be centered without the need for absolute positioning and z-index.

Answer №2

To achieve the desired effect, adjust the positioning of your p element by setting it to be fixed with 50% for both top and left properties:

.front p {
  position: fixed;
  text-align: center;
  color: white;
  top: 50%;
  left: 50%;
  z-index: 3;
}

To see the live demonstration, visit this jsfiddle link. For additional insights, refer to this resource.

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 could be the reason for not just removing the pseudo-class, but instead deleting the entire CSS document altogether?

var style = document.styleSheets[1] style.deleteRule(`.block__header::after`) console.log(`.block__header::after`) What is preventing it from being removed from the CSS document? The pseudo-class is still found in the console, and when trying to dele ...

Corner of the Border Revealing a Clear Sky above

Looking to enhance my navigation bar (menu) by adding a cornered border when the user hovers over it. <nav> <a href="#home">Home</a> | <a href="#about">About</a> | <a href="#blog">Blog</a ...

Executing external Javascript within an HTML document

Just diving into this realm, so please have patience with me. I've got an external js file linked in my HTML. The JS code is solid and functions properly in Fiddle - https://jsfiddle.net/0hu4fs4y/ <script src="js/noti.js"></script> <sc ...

What could be causing my anchored link to redirect incorrectly?

My navigation bar correctly directs me to the 'work' section, but when I click on ABOUT in the navigation bar, it drops down about 300px above the 'about' h2. I suspect that this issue may be related to positioning and display settings. ...

Terminate the ongoing PHP script execution

Is there a way to terminate the current PHP script? For instance: page.php <?php require('./other-page.php'); ?> <h4>this text is always displayed</h4> other-page.php <?php if($_GET['v'] == 'yes&ap ...

Problems with aligning elements to both the left and right sides of the same line

Currently, I have two divs that I would like to float on the left and right sides. However, they seem to be sticking together and I can't seem to separate them.. HTML: <nav> <div id="nav_content"> <div id="home_ico ...

Angular's Conditional ng-if Error

Encountering an error link from Angular Js [1]http://errors.angularjs.org/1.2.10/$parse/lexerr?p0=Unterminated%20quote&p1=s%2013-14%20%5B'%5D&p2=recipe.ID%20!%3D%3D' I am struggling to implement the solution for this error. Any help wou ...

What is the best method for choosing all children's text except for a specific tag in Selenium's XPath selector?

Here is the HTML code I am working with: <div id="content"> <h1>Title 1</h1><br><br> <h2>Sub-Title 1</h2> <br><br> Description 1.<br><br>Description 2. <br><br ...

Modifying button text with jQuery is not feasible

I'm facing a challenge with jQuery and I need the help of experienced wizards. I have a Squarespace page here: . However, changing the innerHTML of a button using jQuery seems to be escaping my grasp. My goal is to change the text in the "Add to car ...

Modifying the CSS design of specific columns within a table created using JavaScript

A unique way to showcase JSON data in a table is by utilizing a for loop within a function. This method, however, does not assign an ID or Class to the table. To hide the final three columns of this table using CSS, the following code can be employed (whe ...

center the view on the specified element

Utilizing ReactJs, I am developing a horizontal timeline that showcases dates. For instance, there is a list of 100 elements, each containing a date and text content. The dates are displayed horizontally using flex-direction="row" and overflowX ...

Using jQuery to automatically scroll to the bottom of a div when sliding down

When a user clicks on a link to slide the div down, I want it to automatically scroll to the bottom of the div. I've attempted to use scrollTo and animate methods to achieve this effect. $('html, body').animate({ scrollTop: $("#elementID") ...

What's the solution for aligning these progress bars side by side if floating them doesn't produce the desired result?

I am looking to place two progress bars next to each other, but I have tried using float: left and inline-block without success. I am open to a solution using flex, but I believe there must be a simple fix for this issue. Here is a link to the fiddle for ...

Step-by-step guide on creating a clickable button that triggers the appearance of a block showcasing a dimmed photo upon activation

Is there a way to create a button that triggers a pop-up block featuring a darkened photo when clicked? ...

The CSS media query isn't working as expected

Having some trouble with media queries on a physician website I'm developing. I've tried multiple times but can't seem to figure out why they aren't working. If anyone could take a look and offer some guidance, that would be much apprec ...

align all items centrally and customize Excel columns based on the length of the data

Is there a way to dynamically adjust the column width based on the length of data in an Excel report using PHPexcel? Additionally, how can I center all the data in the Excel sheet? Here is the current code snippet: <?php if (!isset($_POST['send&a ...

Unleashing the power of specific dates with the angularJS datepicker directive

I am looking to develop a custom Datepicker directive using Angular JS, with the requirement of allowing only specific dates for selection by the user. For instance, I have a predefined list of numbers such as 1,3,5,7, and my goal is to make these particu ...

Enabling the acceptance of blank values within an HTML5 date input field

When using an HTML5 date input for a field that corresponds to a nullable datetime column in the database, how can one avoid setting an empty value in the input field? In my AngularJS application, the ng-model is connected to a scope variable with an init ...

Tips for modifying the height of a bootstrap-vue table and enabling scrolling with a fixed header

I have a div containing a b-table that I need help adjusting the height for. I want to make the table scrollable with a fixed header. Can anyone assist me? Here is my code: Code inside the template: <div class="tbl-barangay"> <b-table stripe ...

Issue when activating Materialize Bootstrap

I'm facing an issue with my code. I have implemented a feature where a modal should be triggered after a user successfully adds a new user. However, I am using Materialize and the modal is not being triggered. Below is a snippet of my code: <div i ...