Hiding a span element with CSS and revealing it on hover is possible, but this technique does not apply to p elements

My goal is to create a selection using radio buttons with explanations that appear when hovering over the label. I have tried putting the explanation text in a span-element instead of a p-element, but I'm struggling to understand why there is a difference:

    <fieldset>
        <h2>Choose your character</h2>
        <div clas="radios">
            <legend>Select character class:</legend>
            <p class="row">
                <input type="radio" id="character-ninja" name="character" value="ninja">
                <label for="character-ninja" class="show">Ninja</label>
                <p class="hidden">The ninja class....</p> 
            </p>
        </div>
    </fieldset>

In order to style this, I have used the following CSS:

.hidden{
    display: none;
}

.show:hover + .hidden{
    display: block;
}

The text in the p-element is hidden by using "display:none", but it doesn't show up upon hovering over the label element. However, changing the p-element into a span-element results in the text being hidden by "display:none", yet it does appear when hovering over the label element.

I suspect the issue may be due to nesting a p-element within another p-element, but even so, I am puzzled as to why it only seems to work partially.

Answer №1

For organizing your content in rows, it's best to utilize the div element:

<div class="row">

The reason nested p tags may not function properly is due to invalid HTML syntax, which can be automatically corrected by the browser. This results in alterations to the structure of elements like label.

.hidden{
    display: none;
}

.show:hover + .hidden{
    display: block;
}
  <fieldset>
      <h2>Select player</h2>
      <div clas="radios">
          <legend>Select character class:</legend>
          <div class="row">
              <input type="radio" id="character-ninja" name="character" value="ninja">
              <label for="character-ninja" class="show">Ninja</label>
              <p class="hidden">The ninja class....</p> 
          </div>
      </div>
  </fieldset>

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

Are you able to identify the contrast between my coding and the tutorial?

Can someone explain the differences between the code in my top navigation here and the one in this tutorial? Aside from changing the menu id name, I've used the same HTML and CSS. Oddly, the menu on my site is not visible; it seems to be hidden someh ...

How can the communication be improved between a JSP page and a Java object?

In the midst of a project involving a java back-end and web page UI, my goal is to integrate the two seamlessly. The java system functions on the server, storing rules created within the web page's interface. To achieve this, I am seeking a way for te ...

Initiating external libraries at the right time in Angular 4

I am currently experimenting with a UI kit (you can check it out here) that comes with multiple JavaScript files, jQuery, Bootstrap, and its own components. I have included them in my index.html file and everything works perfectly as long as the checkbox ...

Applying CSS Style to Element Created in a Vue Component

<template> <div id="body"> <button type="button" @click="create">Create</button> </div> </template> <script> export default { methods: { create () { let e = document.createElement(' ...

Maintaining input focus in AngularJS when a button is clicked

How can I ensure that the focus remains on the textarea when clicking a button inside a dynamically generated directive template? <input type="text" ng-model="myText" id = "area1" ></input> The buttons are created dynamically using a dire ...

Adjust the transformation origin in relation to the container. Text that has been rotated

Seeking assistance to understand the functionality of transform-origin, my research efforts have been unsuccessful in finding a solution tailored to my specific situation. Here's the challenge I'm facing: I have a fixed footer with predetermined ...

Wrapping content in Vue/Vuetify into columns according to screen size

I am working on a parent component that uses a v-for to render instances of the product-box component based on the number of products. Currently, when there are 200 products, they simply stack on top of each other extending the page length like this: [box ...

Tips for causing text to wrap to a new line when reaching the end of a div element

I am struggling with keeping a text inside a div from overflowing when it reaches the border of the div. I have tried various CSS properties like "word-break" and overflow, but haven't been able to find a solution. <div class="col-lg ...

Dynamic classroom experience featuring a bootstrap sidebar

I am having an issue with changing the active class of the sidebar after a click event. I have tried using Bootstrap and implemented some JavaScript code, but it doesn't seem to be working properly. $(function(){ $('.sidebar1 a').filt ...

What is the process for submitting a record to a table following the activation of a JavaScript link or button

I am working on creating a like-unlike button below each post for registered users to interact with. I have successfully created the button itself, but now I need to figure out how to store records when a user clicks the button. My idea is to utilize a tab ...

Creating efficient browser caching for static elements like CSS, JavaScript, and images

Just to clarify, I am utilizing Django with an Apache server. During testing of a website on Pingdom Tools, I encountered the following error messages: The cacheable resources mentioned below have a short freshness lifetime. It is recommended to specify ...

The functionality of Vue.js Stylus and scoped CSS appears to be malfunctioning

I am currently utilizing stylus and scoped CSS styles with Vuetify. Despite trying to use deep nested selectors such as ::v-deep or >>&, I have not been successful in getting them to work (even after rebuilding the project due to issues with hot relo ...

Javascript - Conceal a Dynamic Div Depending on its Text

I have a unique table that generates dynamic Divs with ID's that count as they are created in the following format: <div id="dgpCheckDiv10_0"> <input Delete </div> <div id="dgpCheckDiv10_1"> text2 </div> Some of t ...

Retrieving xml data using ajax

Hey there, I'm working with an HTML file that looks like this: <!DOCTYPE html> <html> <style> table, th, td { border: 1px solid black; border-collapse: collapse; } th, td { padding: 5px; } </style> & ...

The dropdown menu's subcategories are not functioning properly within the navigation system

I am experiencing an issue with my navigation menu. The 'News' link works correctly, but when I try to access the dropdown menus for "Bulgaria" and "International", they do not appear as expected. Despite having the same code structure, there see ...

I am experiencing difficulty closing my Bootstrap 5 nav bar once it has been clicked in mobile view

Having an issue with my Bootstrap 5 navbar in mobile view - it can be clicked to open, but won't close when clicked again. Currently using Bootstrap v5.0. If anyone has insight into why this might be happening, please let me know! <link href ...

Is it possible to access the serial port using HTML5?

Can a HTML5 page access the serial port of a device solely on the client-side? I am aware that this is possible with Java applet, but I am curious to know if it can be achieved using HTML5. ...

What methods can I use to streamline integration with minimal lines of code?

Seeking help with JavaScript: Recently dived into JavaScript and managed to create the desired functionality for my navigation menu. However, I suspect that my code is not optimized as I find myself repeating lines unnecessarily. Here's a snippet of ...

Enhancing Image Quality in JavaFx's Scene Builder

Hey everyone! I've been using JavaFx scene builder to create a user interface with some png images. Up to now, I've been using labels and enlarging them to display the pictures, but this solution isn't ideal because I need to create multipl ...

What is the best way to create space between two flex elements that doesn't follow a

Dealing with a challenge in Flexbox. I am trying to establish a specific distance between two flexible elements. I understand that I should use justify-content, but unfortunately cannot set an exact distance using it. Avoiding the use of margins or othe ...