I am looking to reposition the navbar span tag so that it appears beneath the icon, utilizing both HTML and CSS

I'm currently working on a navbar design with 5 items, each containing an icon and a span tag. However, I'm facing difficulties in aligning the span tag below the icon for all 5 items in the navbar. Despite my best efforts, I have been unable to achieve the desired layout.

I would appreciate any guidance on how to implement this functionality using HTML and CSS.

Here is the relevant code from index.html:

 <div class="navbar-center">
            <ul>
                <li class="text-center"><a href="#" class="active-link"><img src="images/home.png"><br><span>Home</span></a></li>
                <li><a href="#"><img src="images/network.png"><span>My Network</span></a></li>
                <li><a href="#"><img src="images/jobs.png"><span>Jobs</span></a></li>
                <li><a href="#"><img src="images/message.png"><span>Messaging</span></a></li>
                <li><a href="#"><img src="images/notification.png"><span>Notifications</span></a></li>
         
            </ul>
        </div>

And here is the corresponding styling from style.css:

.navbar-center ul li{
    display: inline-block;
    list-style: none;
}
.navbar-center ul li a{
    display: flex;
    align-items: center;
    font-size: 14px;
    margin: 5px 8px;
    padding-right: 5px;
    position: relative;
}

.navbar-center ul span{
    font-size: 15px;
}

/*span tag change side to bottom for .navbar-center ul li a span*/

.navbar-center ul li a img{
    width: 30px;
}

.navbar-center ul li a::after{
    content: '';
    width: 0;
    height: 2px;
    background-color: #045be6;
    position: absolute;
    bottom: -14px;
    transition: width 0.3s;
}
.navbar-center ul li a:hover::after,
.navbar-center ul li a.active-link::after{
    width: 100%;
}

Answer №1

It seems the issue lies in using Flex on the <li> tags. Try removing the flex property or consider adding flex-direction: column.

.navbar-center ul li{
    display: inline-block;
    list-style: none;
}
.navbar-center ul li a {
    display: flex;
    align-items: center;
    font-size: 14px;
    margin: 5px 8px;
    padding-right: 5px;
    position: relative;
    flex-direction: column;
}

.navbar-center ul span{
    font-size: 15px;
}

/*span tag change side to bottom for .navbar-center ul li a span*/

.navbar-center ul li a img{
    width: 30px;
}

.navbar-center ul li a::after{
    content: '';
    width: 0;
    height: 2px;
    background-color: #045be6;
    position: absolute;
    bottom: -14px;
    transition: width 0.3s;
}
.navbar-center ul li a:hover::after,
.navbar-center ul li a.active-link::after{
    width: 100%;
}
<div class="navbar-center">
        <ul>
            <li class="text-center">
                <a href="#" class="active-link">
                    <img src="https://picsum.photos/id/238/120/100" alt="">
                    <div>Home</div>
                </a>
            </li>
            <li>
                <a href="#">
                    <img src="https://picsum.photos/id/239/120/100" alt="">
                    <div>My Network</div>
                </a>
            </li>
            <li>
                <a href="#">
                    <img src="https://picsum.photos/id/240/120/100" alt="">
                    <div>Jobs</div>
                </a>
            </li>
            <li>
                <a href="#">
                    <img src="https://picsum.photos/id/241/120/100" alt="">
                    <div>Messaging</div>
                </a>
            </li>
            <li>
                <a href="#">
                    <img src="https://picsum.photos/id/242/120/100" alt="">
                    <div>Notifications</div>
                </a>
            </li>

        </ul>
    </div>

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

Stop storing CSS data for nopCommerce

Currently, I am looking for a method to avoid caching CSS files on my nopCommerce website. In the past, I have achieved this by adding the date and another element at the end of the CSS call. Html.AppendCssFileParts("~/Themes/CustomTheme/Content/css/site. ...

How can I use jQuery to automatically redirect to a different HTML page after updating a dynamic label?

When I click on a button in first.html, a function is called to update labels in second.html. However, despite being able to see second.html, I am unable to see the updated values in the labels. Can someone please advise me on how to achieve this? functi ...

What is the best way to apply maximum height to an element using CSS?

Looking for help with my website: I made some changes in the code using Firebug and identified these elements that I want to modify (but changes are not live yet) The following code represents the elements on my site: This is the HTML code: <di ...

Can the CSS color of struts2-jquery-grid-tags be modified?

Is there a way to customize the CSS style of my Struts2 jQuery grid tags? I'm having trouble adjusting the font size of the header layer. Can someone please advise on how to change the style, color, and other formatting of the grid similar to regular ...

When using font size in rem units, it will remain consistent across different screen sizes and not be subject to scaling

When setting padding, margin, and font size using rem units, I noticed that on larger screens the output looks good. However, on smaller screen devices, the sizes do not reduce proportionally - instead, the measurements from the larger screen persist. Wh ...

What is the best way to ensure a div container fills the entire height of the screen?

I am currently working on developing my very first iOS HTML5 app, which is a simple quote application. One challenge I am facing is how to set the height of my container div to match that of an iPhone screen. You can view the design I have so far on this j ...

Is it possible to customize the placement of the login or register success message?

I would like to display a message indicating whether the login/register process was successful or not above my form. I am using Boostrap 3 along with some PHP functions. The message appears above my navbar but vanishes after 3 seconds, which is a bit anno ...

Experiencing difficulty inputting data into database using PDO

Attempting to save user input data to a database using PDO, I have created a form for users to input their information. However, when I submit the form, it redirects to proses_input.php and displays a blank page. I tried combining the code into one file, b ...

The text should be wrapped to overlap with an image positioned above it

Currently, I am in the process of enhancing a webpage that contains a significant amount of old legacy code. One issue I have encountered pertains to text wrapping within a fixed-height and width container, as illustrated in the image below: The first ima ...

Tips for avoiding flickering in a background image when it is being changed

Utilizing JavaScript, I am setting a repeated background image from a canvas to a div in the following way: var img_canvas = document.createElement('canvas'); img_canvas.width = 16; img_canvas.height = 16; img_canvas.getContext('2d' ...

When anchor is set programmatically, the focus outline is not displayed

I am currently facing an issue with my application where I am programmatically setting focus on elements in certain scenarios. While it generally works well, I have noticed that when I set the focus on an anchor element using $("#link1").focus(), the focus ...

Embedding CSS stylesheets in a Django template

I'm currently working on a large Django website and in the process of adding the HTML templates. Here is the file tree for the main part: C:. +---forums | | admin.py etc | | | +---migrations | | | ... | | | +---templa ...

Accessing embedded component within an Angular template

I have a ng-template that I utilize to generate a modal with a form on top of one of my other components like this: <div> <h1>Main component content...</h1> <button (click)="modals.show(newthingmodal)">Create New T ...

Steps for positioning a z-indexed division

In my main wrapper, which has a fixed width of 960px, there is a login button located at the top right corner. When this button is pressed, a div layer opens directly below and in front of the main wrapper using z-index: 1. The issue I am facing is that I ...

Ways to update row background color based on specific column values

I need to customize the background color of my table rows based on the value in the "Category" column. For example: Name Category Subcategory A Paid B C Received D If the Category value is 'Paid', I want the ro ...

Developing and integrating views within a node-webkit desktop application

For my file copier desktop application built with node webkit, I aim to create a seamless flow where the initial check for existing profile data determines the first page displayed. The header with static links/buttons to various views remains consistent ...

Using regular expressions in Python with PyQt4 to eliminate anchor tags from HTML links in text

When using my QTextBrowser, I am able to identify links such as "www.test.com" with the following regular expression: re.compile( r"(\b(?:(?:https?|ftp|file)://|www\.|ftp\.)[-A-Za-z0-9+&@#/%?=~_()|!:,.;]*[-A-Za-z0-9+&@#/%=~_()|])" ...

When using the ngFor directive, the select tag with ngModel does not correctly select options based on the specified

Issue with select dropdown not pre-selecting values in ngFor based on ngModel. Take a look at the relevant component and html code: testArr = [ { id : '1', value: 'one' }, { id : '2', ...

Issue Encountered While Loading CSS using Webpack and Babel

I am currently working on a SSR React App using Webpack3 and Babel6. However, when I launch the server, it is not able to locate any css file (Error: Cannot find module './file.css'). Here is an overview of my current folder structure: src/ | ...

Is Javascript necessary for submitting a form to a PHP script?

In my current project, I am working on a page to edit information in a database. While I know how to create the form in HTML and the PHP script that runs on the server, I am facing a challenge with JavaScript. My understanding of JavaScript is limited, and ...