


How to Prevent Unintended Content Hiding in CSS: A Solution for the \':focus\' Problem
Hide/Show Content-List with CSS: Resolving Unintended Behavior
In pursuit of a solution to hide and show content using only CSS, a developer encountered an issue: the content could be hidden by clicking anywhere on the page, rather than just by clicking the designated "hide" link.
The developer's initial code used the following CSS:
<code class="css">#cont {display: none; } .show:focus + .hide {display: inline; } .show:focus + .hide + #cont {display: block;}</code>
This code successfully hides the content when the "hide" link is clicked. However, it also enables hiding by clicking any part of the page, because the CSS rule targets the ":focus" pseudo-class.
To resolve this issue, we can use the following updated CSS:
<code class="css">body { display: block; } .span3:focus ~ .alert { display: none; } .span2:focus ~ .alert { display: block; } .alert{display:none;}</code>
In this updated code, we use the "~" combinator to target elements that are siblings of the focused element. This means that the "hide" element (~ .alert) is only hidden when the "show" element is in focus.
The HTML remains the same:
<code class="html"><span class="span3">Hide Me</span> <span class="span2">Show Me</span> <p class="alert">Some alarming information here</p></code>
With this revised approach, the content is now only hidden when the "Hide Me" element is clicked, as the developer intended.
The above is the detailed content of How to Prevent Unintended Content Hiding in CSS: A Solution for the \':focus\' Problem. For more information, please follow other related articles on the PHP Chinese website!

Here's a container with some child elements:

Flyout menus! The second you need to implement a menu that uses a hover event to display more menu items, you're in tricky territory. For one, they should

"The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect."- Tim Berners-Lee

In this week's roundup: datepickers are giving keyboard users headaches, a new web component compiler that helps fight FOUC, we finally get our hands on styling list item markers, and four steps to getting webmentions on your site.

The short answer: flex-shrink and flex-basis are probably what you’re lookin’ for.

In this week's look around the world of web platform news, Google Search Console makes it easier to view crawled markup, we learn that custom properties

The IndieWeb is a thing! They've got a conference coming up and everything. The New Yorker is even writing about it:


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version
Useful JavaScript development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.