"Enhance Your Dining Experience with a Menu that Captiv

My goal is to create a small menu with only the initial letter of each name visible, but when focused, I want the full word to appear. Here's an example:

    css:

    .menu:focus {

     }

    php:

    <nav>
    <li class="menu"><a href="home.php>h</a></li><br>
    <li class="menu"><a href="galery.php>g</a></li>
    </nav>

and so you simply see the menu like:

h

g

and if you click on 'h' for example, you would see:

home

g

How can I achieve this?

And then if clicked again, go to the linked page.

Is it possible?

edit

    php:

    <nav>
    <li>
        <span class="m">
            H
        </span>
        <span class="f">
            <a class="menu" href="home.php">
            Home
            </a>
        </span>
    </li>
    </span>

    css:

    nav li .f {
        display: none;
    }

    nav li:hover .f {
        display: inline;
        background-color: #202020;
    }

Up to this point, everything works fine as the full word is displayed when passing by. However, changing from hover to focus breaks the functionality.

Also, making ".m" display none on hover is not working. Is there a way to make this switch possible?

    css:

    nav li:focus .f {
        display: inline;
        background-color: #202020;
    }

    nav li:hover .m {
        display: none;
    }

Thanks

Answer №1

I've put together a fiddle for you. Are you looking for something similar to this?

<nav>
<li class="menu">
    <a href="home.php">
        <span class="test">h</span><span class="test2">ome</span>
    </a>
</li>
<li class="menu">
    <a href="home.php">
        <span class="test">g</span><span class="test2">alery</span>
    </a>
</li>

nav li a .test2{display:none} 
nav li a:focus .test2, nav li a:hover .test2{display:inline}

Alternatively, if you prefer a JavaScript solution, here is the code:

HTML

<nav class="nav">
<li class="menu">
    <a href="javascript:;" data-url="home.php">
        <span class="test">h</span><span class="test2">ome</span>
    </a>
</li>
<li class="menu">
    <a href="javascript:;" data-url="gallery.php">
        <span class="test">g</span><span class="test2">allery</span>
    </a>
</li>

CSS

nav li.menu a .test2{display:none;}
nav li.menu a .test2.open{display:inline;}

JQuery

$(".nav>li>a").click(function(e) {
    var trig = false;
    var links = $(this).data("url");
    $(this).children(".test2").addClass("open");
    if(trig == false){
        $(this).click(function(e) {
            window.location.href = links;
        });

    }

});

http://jsfiddle.net/ismailfarooq/p667L2y0/

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

center the radio button with CSS3

I am experiencing difficulty focusing the pointer inside this customized radio button. <div class="radio"> <input id="left" type="radio" name="gender" value="left"> <label for="left">Left</label> <input id="right" ty ...

Differences between -webkit- and -moz-transition

My website uses CSS3 transitions and I have noticed that the -webkit- prefix works, but the -moz- prefix does not seem to be working. This is the CSS code I am using: article {z-index: 2; float: left; overflow: hidden; position: relative; -webkit-transit ...

How to show a tooltip inline by utilizing CSS styling

Working on a sticky side bar menu with a tooltip feature. While it appears correctly in Chrome and Safari, the tooltip is off-center in IE. This snippet seems to be causing the issue: /* Vertically center tooltip content for left/right tooltips */ .tool ...

"How to retrieve the height of an element within a flexslider component

I need some assistance with using JavaScript to determine the height of an element within a flexslider. There are two challenges I am facing. When I attempt to use a regular function getHeight(){ var h = document.getElementById("id-height").style.height; ...

Creating parallel lines utilizing pseudo elements

Can someone assist me in drawing double lines under my paragraph using pseudo elements only without using display block? Here is my code snippet with display block: p:after { content: ""; display: block; width: 40px; margin: 20px auto 0; bord ...

Tips for updating border color when focused with styled-components

How can I change the border color of an input on focus using styled-components and React? Here is the code snippet I am currently using: import React from "react"; import PropTypes from "prop-types"; import styled from "styled-components"; const String ...

Encountering unexpected behavior with the .data() method

I'm encountering an issue with my code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv= ...

Hover over two different divs with JQuery

I have a situation where I have two HTML table rows. When I hover over the first row, I want to display the second row. However, once the mouse leaves both rows, the second row should be hidden. Is there a way to achieve this using JQuery? <tr class=" ...

pressing the switch will adjust the size of the container

I am looking to implement a feature where clicking on an icon will resize a div to full screen in the browser. Below is the HTML code I have set up for this functionality, and I am open to suggestions on how to achieve this. <div> <a (click)= ...

What is the best way to align a jQuery Cycle 2 Slider in the middle of the

Having some trouble centering a jQuery Cycle 2 Slider on my page. You can see the slider here. I've attempted multiple methods to center it, but none have been successful. Check out the HTML code: <div class="slider"> <div id=outside> ...

Does renaming a sub-directory in the static directory of an IntelliJ Spring Boot project cause any changes?

I'm a newcomer to IntelliJ and I've been using it to develop a Spring Boot application. Right now, my project structure looks like this: https://i.sstatic.net/7A7jb.png My goal is to set up a "css" directory within the "static" directory under ...

Having trouble with Firefox not recognizing the linear gradient color in my CSS3 code

I'm working on implementing a linear gradient background using CSS, but I'm facing an issue with Firefox not displaying it correctly. body { height: 100%; /*background-color: #F0F0F0;*/ background-repeat: repeat-x; /* Safari 4-5, Chrome 1-9 */ ...

Creating visually pleasing HTML emails with uniform table data heights

Struggling with Outlook while designing an HTML template. My row has 2 td elements with different content, and setting equal heights is proving to be a challenge. The fixed height on the td causes issues when switching to mobile view in Outlook as text wra ...

Display the entire width of the element without obstructing any subsequent elements

I have a main container with an inner container. I want the inner container to span the full width of the screen. The challenge is that I can't simply set the inner container's width to 100vw because it is nested within the main container, which ...

JavaScript-enhanced HTML form validation

I encountered a small glitch while working on simple form validation with JavaScript. I tried to catch the issue but have been unable to do so. Here is the code snippet, where the problem lies in the fact that the select list does not get validated and I ...

Tips for customizing the CSS styling of the validation ng-class error

Seeking advice: Is there a way to customize the CSS style of the 'error' validation error for ng-class in Bootstrap v3? This is my current code: ng-class="(form.datos.$invalid) && ( form.datos.$touched || submitted) ? 'error&apos ...

Adjusting Table Width with Bootstrap Styling

https://i.sstatic.net/MIkw0.png Could someone please advise on how to adjust the width of the Bootstrap HTML table above? It appears to be spreading out across the entire browser screen. Thank you. # in this section, I inserted bootstrap into my html tab ...

Troubleshooting Alignment Problem of Maximize and Close Icons in RadWindow Using ASP.Net

Currently, I am utilizing telerik radwindow to showcase a PDF document. The window seems to be functioning correctly, but there is an issue with the alignment of the maximize and close icons. Ideally, they should appear in the same row, however, they are b ...

What is the best way to receive detailed error messages from the LESS compiler when using it in Symfony 2?

I have successfully implemented dynamic compilation of LESS scripts to CSS in Symfony 2 by following this guide: However, I am facing an issue where if there is an error in a LESS script, the compilation fails and no CSS is generated for the browser. Is t ...

What is causing the input boxes to exceed their container boundaries so drastically?

My plan was to organize 4 input text boxes in 4 equal columns on a single row of the form. Using Bootstrap's grid column classes, I set col--3 for medium and large screens for those four inputs. For small and extra-small sizes, I designated them as co ...