What is the best way to position text below an image icon in a menu?

I am having trouble creating a menu that has the same style as shown in this image: .

Unfortunately, my menu ends up looking like this instead: .

Can someone please help me fix this issue?

Here is the HTML code I am working with:

<header>
            <div id="logo">
                <h1>TecQ</h1>
            </div>
            <nav class="prime-menu">
                <ul>
                    <li><a class="on" href="index.html"><img src="img/icons/home.png">Home</a></li>
                    <li><a class="on" href="index.html"><img src="img/icons/home.png"></a></li>
                    <li><a class="on" href="index.html"><img src="img/icons/home.png"></a></li>
                    <li><a class="on" href="index.html"><img src="img/icons/home.png"></a></li>
                </ul>
            </nav>
        </header>

And here is the CSS code associated with the menu:

.prime-menu ul {
    list-style: none;
    }

.prime-menu ul li {
    margin-top: 2px;
    display: inline-block;
    }

.prime-menu ul li a{
    width: 140px;
    height: 140px;
    display: inline-block;
    font-size: 20px;
    color: #FFF;
    text-align: center;
    text-decoration: none;
    background: #15161c;
    font-size: 12px;
    line-height: 140px; 
    }

.prime-menu ul li a img{
    }

.prime-menu ul li a:hover {
    background: #1c1d25;
    font-weight: 400;
    }

Answer №1

Enclose your text within <p> or <span> tags, such as <p>Home</p>, and apply the style position:absolute;. Use position:relative; for the <a> tag.

Visit this JSFiddle link

Answer №2

Give this a try. Insert <br> in between your source and text. Your code will resemble the following:
<header>
<div id="logo">
<h1>TecQ</h1>
</div>
<nav class="prime-menu">

<ul> <li><a class="on" href="index.html"><img src="img/icons/home.png">Home</a></li>

<li><a class="on" href="index.html"><img src="img/icons/home.png"></a></li>

<li><a class="on" href="index.html"><img src="img/icons/home.png"></a></li>

<li><a class="on" href="index.html"><img src="img/icons/home.png"></a></li>

</ul>
</nav>
</header>

Answer №3

Place your text at the beginning of <p> within

<p style="position:absolute">Home</p>
and apply position:relative; to connect with <a>link Name</a>

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

Troubleshooting resizing images in React using Material UI's useStyles

When attempting to resize an image using React, I am encountering a problem where adjusting the height and width of the tag with useStyles does not reduce the size of the image but instead moves it around on the page. Here is the code snippet: import { ma ...

Navigating nested loops within multidimensional arrays

Currently, I am experimenting with nested loops to search through nested arrays in order to find a specific value called "codItem". Below is a test model for the array (as I do not have access to the original fetch request on weekends): let teste = [{ it ...

A comprehensive guide on associating a JavaScript function with an element attribute

I am looking for a way to assign a JavaScript function to an HTML attribute. For example: <li data-ng-repeat="job in jobList" class= dynamicClass(str) data-filter = "dynamicFilter(str)"> The reason I want to do this is because the class name and ...

What is the best way to transfer data from an HBS template (HTML) to an Axios POST request?

Just diving into nodejs and express! I want to pass the user input (an email) to axios.post request's data when the "submit" button is clicked. I've verified that hard-coded data in the axios request is functioning correctly. data_email.hbs &l ...

Establish initial content for the specified div area

I need help setting page1.html to display by default when the page loads. Can you provide some guidance? Appreciate your assistance in advance. <head>     <title>Test</title>     <meta http-equiv="content-type" content="tex ...

Tips for showing a value in a disabled text input box

When users access the page, the table should appear as follows: Marks Per Answer Total Marks Marks Remaining (blank text input) 4 4 (blank text inp ...

What is the reason for Safari 13 not displaying the outline during focus when a transition is applied?

In the current scenario, focusing on the button in Safari 13.0.5 does not display the outline until a repaint is forced (such as changing screen size). This issue does not occur in other browsers. Are there any workarounds or hacks to ensure the outline ...

What methods can be used to test scss subclasses within an Angular environment?

Exploring different background colors in various environments is a task I want to undertake. The environments include bmw, audi, and vw, with each environment having its own unique background color. Need help writing an Angular test for this? How can I mod ...

Issue with plain CSS animation not functioning in NextJS with Tailwind CSS

I found this amazing animation that I'm trying to implement from this link. After moving some of the animation code to Tailwind for a React Component, I noticed that it works perfectly in Storybook but fails to animate when running in next dev. It si ...

Adjust the transparency of a `<ul>` element as it descends on the webpage - CSS3

I have a list (<ul>) that I would like to fade out as it scrolls down the page. I attempted to use linear-gradient, but I was unsuccessful. Is this even possible? You can view an example of what I am trying to achieve on JSFiddle here: http://jsfidd ...

Maintain the tab order for elements even when they are hidden

Check out this demonstration: http://jsfiddle.net/gLq2b/ <input value="0" /> <input id="test" value="1" /> <input value="2" /> By pressing the TAB key, it will cycle through the inputs in order. If an input is hidden when focused, press ...

What is the best way to adjust the specific scope of every element generated by ng-repeat within a directive?

Attempting to simplify tables in Angular, I am working on a directive. My goal is for the user to only need to provide the list object and the formatting of each list element in the HTML, using the my-table tag as shown below... <h3>My Table</h3& ...

Select a color by inputting the type as "color" while leaving a space between the border and

I'm having an issue with the color input There seems to be a gap between the black border and the actual color, but I want to get rid of it #color-picker { border: 5px solid black; border-radius: 5px; width: 207px; height: 60px; padding: ...

Chromium CSS blend mode problem

Can anyone help me create a Photoshop overlay effect on my website? My code works perfectly in Firefox, but it's not functioning correctly in Chrome. Here's the demo. This is my current code: HTML <img src="http://lorempixel.com/output/fash ...

Leveraging Columns in HTML and CSS

Looking to create a layout with 2 separate columns for the content on my website. The desired layout is shown below: https://i.stack.imgur.com/V4uX2.jpg On my computer monitor, it displays as intended. However, on my mobile device it appears like this: ...

The bootstrap modal is appearing correctly, but the content within it is not displaying properly

I've been working on a website and added a modal for signup. However, when the user clicks on the signup button, the modal appears but the content inside it is not clickable. Can someone please help me with this issue? Here is the code snippet I am us ...

Utilizing CSS in JS for nested hover styles with Material UI: a step-by-step guide

I am currently utilizing Material UI and in the process of converting regular CSS classes into a JavaScript file. .nav { list-style-type: none; margin: 0; padding: 0; overflow: hidden; } .navItem { float: left; flex: 1; } .navLin ...

Customize Zurb Foundation: Applying styles to specific child elements based on current screen size (large, medium, small)

For wide displays, I aim to give a distinct border to each 7th element. However, on smaller screens, I wish to apply these styles to every 4th element instead. Is there a way for me to nest my styles within .small, .medium, and .large classes? ...

Exploring the jungle. Cursor acting strange while dragging

I am currently working on implementing drag-and-drop functionality in my project, utilizing slip.js from slip.js. To enhance the cursor during dragging, I have assigned class="draggable" to each draggable <tr>. The CSS code for this class is: .drag ...

What is the relationship between font size adjustments and the dimensions of the surrounding parent div element?

I've come across an issue that involves having the following code snippet in the body of an HTML file: html, body { width: 99%; height: 99%; margin: 0px; overflow: hidden; } #container1 { display: flex; gap: 2%; width: 90%; heigh ...