Display the Span in the sidebar when hovering over it

I am currently working on making the menu items in my sidebar hidden by default and only visible when I hover over the sidebar element.

.app{
  height: 100vh;
  width: 100vw;
}
.sidebar {
  width: 100px;
  height: 100%;
  background-color: #060606;
  transition: all 1s;
  color: #9ca3af;
  display:block;
}

.sidebar span{
display:none;
}

/* Here we use the hover effect to reveal the hidden menu items */
.sidebar:hover span{
visibility:visible;
}
<div class="app">
<dive class="sidebar"><span>123</span></div>
</div>

Answer №1

Your desire is to have the visibility property set to visible when the user hovers over the .sidebar element(s). However, you mistakenly used the display property with a value of none and forgot to update it, preventing it from being shown.

To fix this issue, ensure that you use the same CSS property in both places and set the property value for default and :hover states accordingly.

If you prefer using visibility:

*,
 ::before,
 ::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.app {
  height: 100vh;
  width: 100vw;
}

.sidebar {
  width: 100px;
  height: 100%;
  background-color: #060606;
  transition: all 1s;
  color: #9ca3af;
  display: block;
}

.sidebar span {
  visibility: hidden;
}

.sidebar:hover span {
  visibility: visible;
}
<div class="app">
  <div class="sidebar"><span>123</span></div>
</div>

Alternatively, you can opt for using display:

*,
 ::before,
 ::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.app {
  height: 100vh;
  width: 100vw;
}

.sidebar {
  width: 100px;
  height: 100%;
  background-color: #060606;
  transition: all 1s;
  color: #9ca3af;
  display: block;
}

.sidebar span {
  display: none;
}

.sidebar:hover span {
  display: initial;
}
<div class="app">
  <div class="sidebar"><span>123</span></div>
</div>

You also have other options like using opacity for a smooth transition between hidden and visible states:

*,
 ::before,
 ::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.app {
  height: 100vh;
  width: 100vw;
}

.sidebar {
  width: 100px;
  height: 100%;
  background-color: #060606;
  transition: all 1s;
  color: #9ca3af;
  display: block;
}

.sidebar span {
  opacity: 0;
  transition: opacity 0.5s ease-in;
}

.sidebar:hover span {
  opacity: 1;
}
<div class="app">
  <div class="sidebar"><span>123</span></div>
</div>

Moreover, additional properties such as transform can enhance the appearance further. For instance:

*,
 ::before,
 ::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.app {
  height: 100vh;
  width: 100vw;
}

.sidebar {
  width: 100px;
  height: 100%;
  background-color: #060606;
  transition: all 1s;
  color: #9ca3af;
  display: block;
}

.sidebar span {
  display: inline-block;
  opacity: 0;
  transform: scale(0.4) rotateZ(-75deg);
  transition-property: opacity, transform;
  transition-duration: 0.4s;
  transition-timing-function: ease-in;
}

.sidebar:hover span {
  opacity: 1;
  transform: scale(1) rotateZ(0deg);
}
<div class="app">
  <div class="sidebar"><span>123</span></div>
</div>

Further resources:

Answer №2

To hide the .sidebar span element, update the CSS to use `display: none; visibility: hidden;`. When hovering over it, set `visibility: visible;` and `display: block;`.

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

Ways to increase the font size of the text within the button for forum actions

<form action="https://www.kroger.com/account/communityrewards/" > <input type="submit" value="Go to Krogers" style="height: 50px; width: 150px;" /> </form> I'm interested in learning how to increase the font size of the form action ...

Switch out a section of the web address with the information from the button to

Before we begin: Check out this Fiddle My current goal is to create a functionality where clicking a button will replace the # in a given link with the text entered in a text box, and then redirect the user to that modified link. http://www.twitch.tv/#/ ...

Tips for ensuring icons stay in the top right of a Bootstrap 4 navbar when viewing on mobile devices

After trying various approaches, I am still struggling to keep the icons in the top right corner when transitioning to mobile view without duplicating them. The desired order is as follows: on desktop: brand (far left) - nav links (middle) - account & ...

Dynamic content loading using AJAX to selectively update a designated section

I am having trouble displaying the error message in my form. Currently, it is causing my form page to load four times. Can someone help me identify what I did wrong? I only want to display that span: controllers: <?php /* * File Name: user.php */ ...

Locate tags utilizing CSS selectors excluding their children elements

Is there a way to only find tags that meet certain conditions on the first level, without including their children or grandchildren? I am currently using Selenium with Python. <div id="example1"> <div id="example2"> </div> </ ...

Aligning an Image Vertically

I'm working with a document structure that includes an unordered list containing div elements with images inside. The images have a set height of 150px, but sometimes the images are smaller than that. Is there a way to vertically position the images w ...

Is there a way to retrieve the complete date and time from a Beautifulsoup ResultSet?

My current challenge involves utilizing selenium and beautifulsoup to retrieve the date and time of an Instagram post. I am encountering difficulty in extracting the datetime element from the HTML. from bs4 import BeautifulSoup from selenium import webdriv ...

What is the best way to automatically update the contents of a div that contains PHP variables

Recently, I created a new page called queries.php <?php require("connection.inc.php"); $query = "SELECT SUM(john), SUM(robert), COUNT(school) FROM election"; $result = mysql_db_query($db, $query, $connection) or die("query error!"); $data = mysql_fetc ...

What is the best way to crop a page?

Running a React application, I am integrating a page from an external ASP.NET app. To achieve my goal of extracting only a section of the page rather than the entire content, I am unsure if it is feasible. Specifically, I aim to extract just the body of th ...

Steps for positioning a RadioButtonList at the center of a table cell

How can I easily center a RadioButtonList? It used to be straightforward, but for some reason the below HTML is not working. Can you spot what's missing? <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></ ...

When a textarea contains a new line, it will automatically add an additional row and expand the size of the textarea

Developed a form with the functionality to move placeholders in a textarea upwards when clicked. The goal is to increment the height of the textarea by 1 row for every line break. However, I am uncertain about what to include in the if statement of my Ja ...

How should form elements be named and handled for avoiding duplication?

Suppose my form contains 2 inputs <input name="person_name" value="John" type="text" /> <input name="person_name" value="Jean" type="text" /> After submitting the form, which "person_name" will be received? John or Jean? Also, what if I have ...

The widths of inputs vary between FireFox and Chrome

I've been investigating why the widths in FireFox and Chrome show a significant difference. This variation is causing a problem with my Modal in the views. Chrome: https://i.sstatic.net/D0lgu.png FireFox: https://i.sstatic.net/do4YU.png Upon comp ...

Is there a way to trigger a Bootstrap modal to open upon clicking on an input?

Currently using Bootstrap, I have a search form and a modal in my project. My goal is to have the modal open when clicking on the search form, rather than having it triggered by a button as most online resources suggest. Is there a way to achieve this func ...

Having trouble getting the hover effect to change the colors of CSS borders

I am experiencing difficulty in changing the background color of the 'About' button to yellow and the border color to blue when it is hovered over. Currently, only a small rectangle around the text changes to yellow on hover and I cannot figure o ...

What is the default margin for Autocomplete in Material UI?

Having just started with material-ui, I'm having trouble figuring out the margins of the Autocomplete. My form includes both Autocomplete and TextInput elements, but their positioning seems off to me. Is there some predefined margin box around Autocom ...

Tips on implementing a circular progress bar with locomotive scroll functionality

Can anyone help me integrate progress functionality with Locomotive Scroll using JavaScript? Link to CodePen for reference Check out this code snippet from Locomotive Scroll that calculates the percentage of pages scrolled: const scroller = new Locomotiv ...

Access the value of a variable passed from the view to the controller

Is there a way to retrieve a dynamically generated value from the view to the controller in AngularJS? <ng-option ng-repeat="w in details track by $index"> <div class="program-grid-row table-row" > <div> <a class= ...

Tips on boosting CSS specificity in Material-UI's makeStyle for styled components in order to successfully override the root style

As a newcomer in the world of React, I am attempting to utilize MUI makeStyles to customize the existing styles. However, I have encountered an issue where setting fontWeight to 'bold' does not seem to work, even when using !important. Any sugges ...