Height constraint disregarded by anchor

I am facing an issue with a large textual menu where the active link space is overlapping onto the other menu items. This is causing difficulty in accurately clicking on a link.

For reference, you can check out this example: http://jsfiddle.net/dhyz48j3/1/

Below is the source code:

<div id="menu">
    <span>
        <a href="#" id="still-life">Still&nbsp;Life</a><span class="divider">/</span><br/>
        <a href="#" id="interiors">Interiors</a><span class="divider">/</span><br/>
        <a href="#" id="books">Books</a><span class="divider">/</span><br/>
        <a href="#" id="personal">Personal</a>
    </span>
</div>

The CSS related to this issue is as follows:

#menu span, #menu span a {
        font-family: sans-serif;
        font-size: 6.1vw;
        line-height: 4.7vw;
        letter-spacing: -0.0425em;
        text-decoration: none;
        color: #ccc;
        display: inline-block;
        }

#menu span a:hover {
        color: #aaa;
        }

The links on the fiddle are not working accurately due to their larger size. I need assistance in resolving this problem. How can I fix this?

Answer №1

Although the suggestions provided by atmd are excellent for your code, they may not completely solve your issue:

font-size: 6.1vw;
line-height: 4.7vw;

It seems that the problem lies in the spacing of your text. While you've attempted to align the lines closely together and reduce the spacing, the font you're using still has extra space above and below the letters. This results in the elements occupying more space vertically than expected, causing them to overlap.

To address this issue, you can adjust the padding of the text element by setting a specific height and using overflow:hidden on a parent element. Then, position the anchor text in the center of the parent element. A functional example can be found here: http://jsfiddle.net/dhyz48j3/3/

Answer №2

To organize a list like this, it is recommended to use the ul tag as they stack vertically by default.

<ul>
    <li><a href="#" id="still-life">Still&nbsp;Life</a></li>
    <li><a href="#" id="interiors">Interiors</a></li>
    <li><a href="#" id="books">Books</a></li>
    <li><a href="#" id="personal">Personal</a></li>
</ul>

This approach eliminates unnecessary markup and allows you to create dividers using CSS.

#menu span, #menu span a {
        font-family: sans-serif;
        font-size: 6.1vw;
        line-height: 4.7vw;
        letter-spacing: -0.0425em;
        text-decoration: none;
        color: #ccc;
        }

#menu span a:hover {
        color: #aaa;
        }

#menu span a:after {
        content: "/";
        }

#menu span a:last-child:after {
        content: "";
        }

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

Having issues with downloading the app from the website

Currently I am diving into the world of android development and I have encountered an issue while following a tutorial. The tutorial demonstrates how to download a web page and print it into logs using the AsyncTask class. However, the problem I am facing ...

Spinning with animation in jQuery

Greetings! I am in the process of creating a popup box that will appear upon clicking the Login button. My aim is to produce a popup box with a rotating effect, however, my attempts have not been successful so far. You can view the code snippet on JsFidd ...

The image component is missing the necessary "src" attribute even though a valid src value has been provided as a prop

I'm encountering an issue in Next.JS where a component is not recognizing the image source passed through a prop. I am providing the path of an image named "logo.jpg" from the project's public folder. The image successfully displays when used as ...

Is there a way to prevent tags from wrapping and showcase them all in a single line when utilizing the jQuery select2 plugin?

I have a requirement to prevent tags from wrapping and instead display them in a single line using the jQuery TagIt plugin. Check out my preview: https://i.stack.imgur.com/lYhsi.png My goal is to have all the tags displayed on a single line without wra ...

Creating extensive pianoroll visualization using HTML and JavaScript

Currently, I am focusing on developing an HTML5 audio application utilizing the latest Web Audio API, and I require a "pianoroll" feature. This is essentially a keyboard grid where users can draw notes, similar to what is seen in many music production soft ...

Styling the tab view in PrimeFaces

I am currently working with the tab view feature in primefaces and I have encountered a couple of issues. 1) When using Internet Explorer, the tabs are displayed vertically instead of horizontally. However, it works fine in Firefox. FireFox : Internet E ...

What are some possible applications for leveraging the HTML5 <link rel> attribute duo of stylesheet and next?

The specification for HTML5 emphasizes the handling of each link created within a link element as separate entities. This means that multiple link elements with `rel="stylesheet"` are treated independently, considering them as distinct external resources a ...

Creating a customized design for a q-popup-edit

As I navigate through using Quasar in Vue, I stumbled upon a q-popup-edit that allows me to gather input from the user. Despite my attempts at researching via Google and reading documentation, I have hit a roadblock when it comes to customizing the style o ...

Can I create personalized animations using Compass?

I am curious about how to convert this code into Compass mixins @-webkit-keyframes shake { 0% { -webkit-transform: translate(2px, 0px) rotate(0deg); } 10% { -webkit-transform: translate(-1px, 0px) rotate(-1deg); } 20% { -webkit-transform: tran ...

Injecting SVG styling into HTML using the content tag and CSS

I am working with 3 different files: index.html <!DOCTYPE html> <html> <head> <link type="text/css" rel="stylesheet" href="style.css" /> </head> <body> <i class="logo myRed" aria-hidden="true"></i> ...

unable to display dropdown menu from Django model in HTML view

I'm in the process of creating a Django application and I want to implement a feature where users can choose a [team_number] from a dropdown menu. Once they submit their selection, they should be redirected to a page that displays the relevant informa ...

The candy stripes on a loading bar zebra assist in creating a unique and

I'm in the process of creating my portfolio and I'd like to incorporate unique animated loading bars, such as vertical or horizontal candy stripes, to showcase my coding skills. Can anyone suggest a specific programming language or tool that woul ...

Retrieve the AJAX response data to be utilized in future operations

It appears that there is a bug in using INNERHTML where my SELECT OPTION tag becomes blank, based on the research I have done. I am trying to figure out how to create a variable containing my OPTION tags for later use, based on the JSON data below, but I a ...

Comprehending the positioning of elements enclosed within a parent <div> tag

I'm struggling to understand why: vertical-align - isn't behaving as expected in this scenario, even though the elements are aligned along a baseline and are inline elements. I've experimented without using float but that didn't sol ...

The Chrome extension takes control of the new tab feature by redirecting it to a custom newtab.html

I have a website https://example.com where users can adjust their site preferences, including enabling night mode. To enhance the user experience, I developed a Chrome extension for https://example.com that transforms Chrome's new tab with a custom ne ...

Execute AJAX function when loading a form populated from a MySQL/PHP database

I am currently working on a drop-down menu that is being populated from a MySQL table using PHP. The goal is to have a second drop-down menu triggered based on the selection made in the first form. This functionality works perfectly when a selection is mad ...

php redirect back to the page upon form submission

I've designed an html form that allows users to input data, which will then be saved into a database using PHP: <form action="http://localhost/php/insert.php" method="post"> Barcode: <input type="text" name="barcode" /><br><b ...

The html select option tag is automatically closed because of the presence of the "/" character within the dynamic value in JSP and JSTL

<select id="ordersSelect" class="drop-down" onchange="somemethod()"> <c:forEach items="${orders}" var="order" varStatus="orderStatus"> <option value="${order.id}"> ${order.publicId} </option> </c:forEach> </select> ...

Leveraging image values for selecting an image from a collection and showcasing it (Javascript)

I have a collection of images that I want to enlarge upon clicking. Here is what I currently have: <div class="gallery"> <div> <img src="content/imggallery/img1.jpg" class="oldimg" value="0"> </div> ...

Divide the text into uniform segments immediately following "/>"

I am currently faced with the challenge of breaking down an HTML file into chunks of a maximum size of 5000 bytes in order to accommodate AWS translate. Based on the assumption that a character can be at most 78 bytes in size, I have developed a simple fu ...