CSS Only flyout navigation - reveal/hide with a tap or click

I want to make adjustments to a CSS-only menu that has a horizontal flyout effect triggered by hovering. I am looking to achieve the same effect on touch or tap - meaning, one tap to open the menu and another tap to close it.

Is it possible to accomplish this using solely CSS?

Below is the code snippet, but for optimal viewing, please refer to the Codepen link provided. Currently, my challenge lies in having to keep the tap pressed for the menu to display - how can I create a toggle without relying on JavaScript?

The Codepen Link: http://codepen.io/pliablepixels/pen/WwPgwg

/*
Forked from http://codepen.io/IanLunn/pen/NPapxy */
/*
 sass flyout.scss >flyout.css (sudo gem install sass)
 or sass flyout.scss --style compressed >flyout.min.css
 "IL" logo Copyright (c) Ian Lunn Design Limited 2015

 Modified by pliable pixels
*/
.drawer {
  position: absolute;
  z-index: 10;
  top: 0;
  left: 0;
  /*height: 100%;*/
  padding: .4em 0;
  background: #7D294E;
  color: white;
  text-align: center;
  /* Remove 4px gap between <li> */
  font-size: 0;
}
.drawer li {
  pointer-events: none;
  position: relative;
  display: inline-block;
  vertical-align: middle;
  list-style: none;
  transform: translateZ(0);
}
.drawer a {
  pointer-events: auto;
  position: relative;
  display: block;
  min-width: 5em;
  margin-bottom: .4em;
  padding: .4em;
  line-height: 100%;
  /* Reset font-size */
  font-size: 16px;
  text-decoration: none;
  color: white;
  transition: background 0.2s;
}
.drawer a:active, .drawer a:focus {
  background: #B44659;
}
.drawer i {
  display: block;
  margin-bottom: .2em;
  font-size: 2em;
}
.drawer span {
  font-size: .625em;
  font-family: sans-serif;
  text-transform: uppercase;
}
.drawer li:active ul {
  /* Open the fly-out menu */
  transform: translateX(0);
  background: #B44659;
  /* Enable this if you wish to replicate hoverIntent */
}
.drawer > li {
  display: block;
  /* Fly out menus */
}
.drawer > li > a {
  background: #7D294E;
}
.drawer > li:active, .drawer > li:focus {
  z-index: 100;
}
.drawer > li:active, .drawer > li:focus a {
  background: #B44659;
}
.drawer > li a:active {
  background: #F56356;
}
.drawer > li ul {
  position: absolute;
  /* Stack below the top level */
  z-index: -1;
  top: 0;
  left: 100%;
  /* height: 100%;*/
  width: auto;
  white-space: nowrap;
  /* Close the menus */
  transform: translateX(-100%);
  background: #B44659;
  transition: 0.2s transform;
}
<ul class="drawer">
        <li>
            <a href="">
               
                <span>Info</span>
            </a>
            <ul>
                <li>
                    <a href="http://www.google.com">
                        
                        <span>Item 1</span>
                    </a>
                </li>
                <li>
                    <a href="http://www.google.com" >
                        
                        <span>Item 2</span>
                    </a>
                </li>
                <li>
                    <a href="http://www.google.com">
                        
                        <span>Item 3</span>
                    </a>
                </li>
            </ul>
        </li>
    </ul>

Answer №1

Take a look at this code snippet which should solve your problem.

<a href="#popup">Click here</a>
<div id="popup">Hello there!</div>

CSS:

#popup {
  display: none;
}

#popup:target {
  display: block;
}

Here is the CodePen link for you to see it in action: http://codepen.io/anon/pen/ABCDE123

Answer №2

This piece of code has proven to be effective for me

<!DOCTYPE html>
<html>
   <body>
       <a href="#something" id='target'>Show</a>
       <div id="something">Bingo!<a href="#target">hide</a></div>
       <style>
           #something {display: none;}
           #something:target {display: block;}
           #target:target #something{display: none;}
    </style>
</div>
</body>

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

Creating responsive modal windows in Vue and Laravel to dynamically adjust to the screen size

I am currently working with a modal window code snippet. <transition name="modal" @close="showModal = false"> <div class="modal-mask" style=" width: 90% !important;"> <div class="modal-wrapper"> < ...

Having trouble with the JSFiddle dropdown button that is unresponsive to

I am currently in the process of developing a test drop-down menu. The open menu button functions correctly, however, the close button is unresponsive to clicking or hovering actions. Upon clicking the open menu button, it should make the other button visi ...

Guide on altering the background color of dynamically generated textboxes in R Shiny

textInput(paste0("inp1-", wid),label = NULL,value = record$Current_week) This code was used to dynamically generate text input boxes, where the id for each box is determined by a number called wid. I attempted to change the background color using the fol ...

Unable to align the row in the center

I'm having trouble centering a row with 4 columns. It seems off when I look at the picture below, specifically at the vertical border under the "most read" blue square. html file: <div class="block-section"> <div class="sm-section-wrapper" ...

The updated Bootstrap 4 carousel is only working halfway as expected when attempting to double it up, causing the scroll loop to stop functioning

Discovering a fantastic carousel modification was an exciting find, which can be accessed Here. However, when attempting to place two carousels on one page, issues arose with the scrolling functionality. While I managed to make them operate on the correct ...

Unexplainable space or padding issue detected in OwlCarousel grid gallery

There seems to be an unusual gap or margin at the bottom of each row section in this portfolio grid gallery that's running in OwlCarousel. You can view an example here. https://i.stack.imgur.com/NHOBd.png I've spent a lot of time trying to solv ...

Error in Angular 2 component when loading background images using relative URLs from an external CSS skin

In my angular2 component, I am utilizing a third-party JavaScript library. The skin CSS of the component attempts to load images using relative URL paths. Since I am following a component-based architecture, I prefer to have all component dependencies enca ...

Fluid Centered UL with Bullet Points

We have received a unique request from one of our clients. They are asking for the content within a specific <ul> to be centered along with the icons. Centering and adding icons are doable, but the challenge lies in centering the <li> elements ...

What is the best way to define coordinates or set margins for the autoTable component in jsPdf when using React js?

While working with the jsPdf library to create a PDF in React, I am encountering an issue where I am unable to set margins for the autoTable when there are multiple tables on a single page. Below is the code snippet: import React from "react"; ...

The animation isn't loading

I discovered a handy script that displays a waiting message when my form is submitted. I implemented jquery-ui to showcase this message in a dialog box, and it was successful. However, upon customizing the text and adding an animated gif background using C ...

Guide to dynamically updating the href of an SVG Image in Angular HTML

I am currently iterating through a list of employee objects, each containing an image URL that I need to incorporate into an SVG - Image element. <div *ngFor ="emp of employees"> <defs> <pattern id = "attachedImage" height ...

Ways to adjust the ngx-pagination color scheme?

I am looking to customize the background color of ngx-pagination Here is my current code: <pagination-controls class="custom-pagination" id="indicadorPaginationResults" (pageChange)="p=$event" maxSize="9" directionLinks="true" autoHide="true" previ ...

Header with a dropdown select option

In the process of developing a monitoring system, I am in need of a feature that allows users to select varying numbers of days. Here is the desired style: Previous [Dropdown Selection] Days https://i.sstatic.net/ysk6X.png Ideally, I do not want any bor ...

What might be causing the background color to remain the same when focusing on a div element

I am trying to change the background color of a parent div when an input field within it is in focus using CSS only. However, my current code does not seem to be working as expected. This is what I have tried: .a:focus{ background-color:red; border:2 ...

Choose the grandparent of an element's parent

Is there a way to select the grandparent element of a child in Javascript without having to chain the .parentElement method twice? Specifically, I am looking for a method that can substitute .parentElement.parentElement when selecting the desired element, ...

Tips for wrapping a div around its floated children

I'm currently developing a website for an online shopping cart and working on making the search results responsive. I am aiming to display as many items as possible across the screen (usually 3) when viewed on any device with a resolution lower than t ...

Unexpected problem with redrawing HTML application in Android WebView

I created a basic nixie clock app using HTML and wrapped it in a WebView for use on Android. It consists of one HTML file, a JS file, a CSS file, and ten digit images. After a few hours, I noticed stripes appearing in the center of the screen where the an ...

Position a div element on top of Google Maps to create a floating

Currently working on a website and attempting to add shadows over Google Maps by using a <div> element for a shadow effect: Unfortunately, the desired effect is not being achieved. This is the current CSS code in use: html { height: 100% } body ...

Modifying app aesthetics on-the-fly in Angular

I am currently working on implementing various color schemes to customize our app, and I want Angular to dynamically apply one based on user preferences. In our scenario, the UI will be accessed by multiple clients, each with their own preferred color sch ...

A confined space that is scrollable, yet keeps any overflow hidden without displaying a scroll bar

Is there a method for creating a overflowing div that conceals the overflow, does not display a scroll bar, but remains scrollable (via mouse wheel or touch input)? For example: <!DOCTYPE html> <div id="longtext" style="width:100px; height ...