Visible element specifically for a predefined height

As someone who is just starting to learn about HTML, CSS, and JavaScript, I have encountered a specific issue. I want to display navigation dots on my webpage for only a certain section, while keeping them hidden for the rest of the time. To achieve this, I attempted using a media query:

@media screen and (min-height:200vh) and (max-height: 600vh)
{
.invisible{
    visibility: visible;
  }
}

The targeted segment is within one div. Is there a way to make this div visible when hovering over another div?

Answer №1

Using vh and vw in your media queries is ineffective. The viewport height (100vh) represents 100% of the device's viewing area, making it impossible for a query like min-height: 200vh to apply as nothing can be two times higher than itself.

Could you elaborate on what you mean by "segment" and your specific goal? Are you looking to:

  1. Hide nav-dots when the client's viewport height is below a certain value?
  2. Hide nav-dots within a particular DOM element like <p> or <div>?
  3. Hide nav-dots once the user scrolls past a set point?

If addressing the second scenario and the query about hiding a div while hovering over another, consider the following solution outlined below. Modifications are welcome if this doesn't align with your intent.


HTML:

<div class="container" id="my_segment">
  <div class="nav-dots">
    Navigation dots content here
  </div>
</div>

Assign the unique ID my_segment to target the segment for hiding nav-dots. Note that IDs should remain distinct per page.

CSS:

.container {
  display: inline-block;
  background-color: #FFCCAA;
}

.invisible {
  visibility: hidden;
}

JavaScript:

// Access our specified element
let seg = document.getElementById('my_segment');

// Include a mouseover event listener
seg.addEventListener('mouseover', function() {
  // Locate nav-dots within the segment
  let nav_dot_elements = seg.getElementsByClassName('nav-dots');
  // Remove 'invisible' styling
  nav_dot_elements[0].classList.remove('invisible');
});

// Incorporate mouseout event logic
seg.addEventListener('mouseout', function() {
  // Find nav-dots inside section
  let nav_dot_elements = seg.getElementsByClassName('nav-dots');
  // Apply 'invisible' style
  nav_dot_elements[0].classList.add('invisible');
});

Demonstration on Codepen

This JS example is straightforward for beginners. It operates under the premise of hovering over one component to reveal another. For optimal results, ensure only one 'nav-dots' element exists within the container. Test it out and share feedback on its functionality!

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

RShiny encountering issues while trying to load external HTML file along with CSS file

I've been working on a Shiny app, where I put together the UI code using HTML, CSS, and JavaScript within the www sub-folder, while keeping the app.R file in the main folder. The code in my app is structured as follows: runApp( shinyApp( ui = sh ...

Is there a copyright concern regarding CSS?

There are countless websites that spark my creativity. If I am inspired by a particular design, CSS, or JavaScript on one of these sites, am I allowed to copy it to my local folder and use it? For instance, let's say I come across a website called xy ...

Displaying the contents of a local HTML file in a div

I am attempting to load a local HTML file into a div, however it is not displaying any content on the page despite showing an alert. Here is the HTML code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> ...

Aligning Material-UI Text Field with a Paragraph

I'm currently working on a React app that has a "mad-libs" style and I'm facing some challenges trying to align a couple of components. The image below shows the current situation along with an arrow pointing to the desired outcome. It seems like ...

Can JavaScript be used to continuously monitor a window variable object in real-time?

Is there a way to dynamically control a variable in JavaScript? I'm currently working on a code that needs to display a button when it reaches the last signature of an automatic request process. The code for activating/deactivating the button is show ...

Do HTML buttons without values get sent in a form submission?

When you have a button with the following code: <button class="button yellow" type="submit" name="button">Log in</button> and you submit it, what exactly gets sent to the server for this specific button that has a name attribute but no value ...

Combining fixed pixel width with the max-width property in CSS

My container has a nested <p/> tag serving as the message text. The container is set to have a width of 200px, with a max-width of 600px to allow for expansion if the message length exceeds the initial 200px. However, despite these settings, the div ...

Is there a way to log and process div data posted using jQuery in CSS format?

I am looking to extract and log a JavaScript-calculated result from an anonymous survey created using a WordPress plugin. The generated HTML code is: <div ref="fieldname57_1" class="cff-summary-item"> <span class="summary-field-title cff-summary ...

Combining TypeScript into HTML resulted in an error: Uncaught ReferenceError clickbutton is not defined

Attempting to create a basic CRUD frontend without the use of any frameworks. I am encountering an issue when trying to include a TypeScript file (index.ts) in my index.html, as the functions called within it are showing as undefined. I understand that bro ...

What is a more efficient method for writing HTML in JavaScript compared to document.write?

A helpful JavaScript code snippet for a jQuery mobile app can be found here. After finding it, I made some slight adjustments to suit my needs. Being a beginner in JavaScript and currently taking a course on Codecademy, I recently learned that document.wr ...

Adjusting the width of individual cells or columns within a table through my HTML code is proving to be a challenge

I am struggling to adjust different column widths in my table. Despite trying various approaches, such as changing the width of specific td/th elements and using inline styling or nth-child property, I have been unsuccessful in altering the width. The tabl ...

Angular and HTML calendar picker

Is there a way to display a date in an HTML input type="date based on a variable stored in my ts file? The variable ScreenDate is defined in my ts file. <input type="date" [(ngModel)]="ScreenDate"> I tried the above code but it did not work as exp ...

Steady Content of a Parallax Webpage

Hey there! I recently put together this awesome site and I'm facing a challenge with fixing text on the first slide, specifically the one featuring the Nike basketball. Right now, the text 'The first of its kind' is part of the background im ...

Retrieving JSON data through a JSP file using a GET request

Seeking a way to execute a get request from a JSP file and exhibit the json response. The link for the get request will appear as follows : https://api.fda.gov/drug/label.json?search="testicular cancer" Yet, I aim to substitute the search crite ...

Tips for creating a full-length sidebar below the top navigation using Bootstrap 4

Recently started using Bootstrap and decided to work with the alpha version of Bootstrap 4 to create a website for my home network. My main concern is with the sidebar, as I want it to cover the entire left side of the page, starting just below the top na ...

CSS Image Placement

If I have an image with a width of 2000px, where the snazzy design aspect is located about 600px in and spans about 900px. My goal is to use this image as the background for a website, ensuring that the snazzy design remains centered even when stretching t ...

Is it necessary for me to include body, html at the beginning of my CSS code?

For all of my pages, I have been including the following code at the top. body { color: #333333; font-family: Arial,sans-serif; font-size: 0.95em; line-height: 1.15; } However, a colleague of mine has informed me that I only need to targ ...

Storing the ID, Class, or Name in a variable for safekeeping in Python

I need assistance with extracting and saving an email from 10minutemail.net using Python. Here is my current code: from selenium import webdriver from time import sleep driver = webdriver.Chrome(r'''C:\WebDriver\chromedriver.exe& ...

Arrange four Divs next to each other with flexbox styling

I've been struggling with aligning my cards side by side. They are a series of divs nested in lists under a <ul> Changing the positioning is not resolving the issue, and I'm hesitant to alter the display as it's crucial for responsive ...

How to achieve vertical centering of an image in an li element with fixed dimensions while maintaining 100%

I need help with vertically centering an image within a fixed width and height list item. Here's the HTML I'm working with: <ul class="list"> <li class="list-item"> <div> <img src="http://lorempixel.c ...