Aligning the first row of the sidebar navigation

I recently tried out a tutorial on creating a Sidebar in my _Layout code, which I found at this link. The sidebar element "Test Sidebar" is not centered as I would like it to be. I'm looking for a responsive solution without relying solely on margin values. Can anyone provide guidance on achieving this?

_Layout.cshtml code

<div class="container">
    <ul id="gn-menu" class="gn-menu-main">
        <li class="gn-trigger">
            <a class="gn-icon gn-icon-menu"><span>Menu</span></a>
            <nav class="gn-menu-wrapper">
                <div class="gn-scroller">
                    <ul class="gn-menu">
                        <li class="gn-search-item">
                            <input placeholder="Search" type="search" class="gn-search">
                            <a class="gn-icon gn-icon-search"><span>Search</span></a>
                        </li>
                        <li>
                            <a class="gn-icon gn-icon-download">Popular</a>
                        </li>
                        <li><a class="gn-icon gn-icon-cog">Settings</a></li>
                        <li><a class="gn-icon gn-icon-help">About us</a></li>
                    </ul>
                </div><!-- /gn-scroller -->
            </nav>
        </li>
        <li><a href="http://tympanus.net/codrops">Test Sidebar</a></li>
        <li></li>
    </ul>

     @RenderBody()
</div><!-- /container -->
<script src="../../Scripts/classie.js"></script>
<script src="../../Scripts/gnmenu.js"></script>
<script>
    new gnMenu(document.getElementById('gn-menu'));
</script>

https://i.sstatic.net/9Bf9y.png

Check out the Codepen version here.

Answer №1

Here are some essential steps you should follow for your solution.

1 - Remove float:left from .gn-menu-main > li and add it to .gn-menu-main li.gn-trigger.

2 - Replace display:block with display:inline-block

3 - Add text-align:center and font-size:0 (to set margin) to .gn-menu-main

4 - Set the font size according to your design, such as 13px for .gn-menu-main > li

Following these steps may assist you in achieving your goal. You can also refer to this JSFiddle link for clarification.

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

Secure your online file with a password

I need to access a specific file on my computer through a program, not a web browser. However, I want to ensure that only authorized users can view the file by requiring a password with the request. How can I set up the file to prompt for a password befor ...

What is the most dependable method for referencing a CSS class through programming?

Within my Sharepoint project, I am dynamically generating controls in the overridden CreateChildControls() method. I am uncertain which approach is more preferable when it comes to referencing the .css file: protected override void CreateChildControls() { ...

What is the best method for using CSS/HTML to showcase text at a height of 2mm consistently across various devices with varying screen resolutions and dimensions?

Designing a basic webpage to showcase the text "Hello, World!": <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <meta charset="utf-8"> </head> <body> <p>Hello, Wor ...

How can I automatically select an option in Vue JS based on a nested v-for value?

I am encountering a challenge with a nested v-for inside of another v-for in my Vue project. Although I am able to retrieve the correct data, I am facing difficulty using a select dropdown to populate a field and automatically selecting the option based on ...

Deduct a digit from a variable

My goal is to decrease the value of revlength each time the loop runs. For example, if there are 2 posts by 'A Google user', then subtract 2 from revlength. This is my attempted solution: var revlength = place.reviews.length; if (place.reviews[ ...

How about creating a fresh variable in Assemble or merging two comparison helpers together?

Is it possible to create a new variable within a partial in Assemble (assemble.io) or combine two comparison helpers? For example: {#is somevar "yes" || anothervar "no"} In my partial, I have HTML that should only display if one of two different variable ...

Attempting to incorporate real-time search functionality into an input field

Looking to incorporate live search functionality in a text box, with the options being fetched from the server. If an item is not available, it should be added dynamically. For example, if typing "gre" and selecting that word, it should automatically be ad ...

Having trouble getting custom tabs in jQuery to function properly?

I am facing an issue with a simple script I have created. The script is supposed to display a specific div when a user clicks on a link, and hide all other divs in the container. However, when I click on the link, nothing gets hidden as expected. Even afte ...

Tips for adding information into a designated DIV using JQUERY

Having a bit of trouble with my JQUERY at the moment. Basically, I have this Facebook-style layout for displaying posts. Each post has an <input> box where members can leave comments. When a user presses <enter>, my jQuery (AJAX) will fetch th ...

What are the different ways to utilize the "%" symbol in CSS for adjusting the size of elements?

I have attempted multiple solutions, however, the percentage symbol is the only thing that is not working. I am unsure of the reason for this issue. p{ width:100%; } ...

Incorporating Computer Modern Serif into Your Jekyll GitHub Page

I have customized a version of the Jekyll GitHub page from here and am trying to incorporate Computer Modern Serif font as the main body font across all pages. Following instructions from an informative answer, I have downloaded the necessary files from th ...

How can I align content to the left within a div that is right-aligned?

When I attempt this, the content aligns to the right as expected: <div class="text-right"> ... ... ... </div> I had hoped that this would result in left-aligned content in relation to itself, but right-aligned within the ...

Is there a method to display text on the screen after a countdown has finished?

I am looking for a way to display some text or an image of a cake on the screen once this countdown reaches zero. It's a countdown leading up to my birthday, and I really want it to have that special touch at the end. However, I've been strugglin ...

Using CSS transition on the height property does not produce the desired effect

I'm currently working on a menu interaction that activates on click. Here is the code snippet for reference: let btn = document.querySelector('.trigger'); let icons = document.querySelector('.icons'); let labels = document.query ...

How can validation of input fields be implemented in React Js?

Currently, I am dealing with a variable (in my actual application it is an API) named data, which contains nested items. Starting from the first level, it includes a title that is already displayed and then an array called sublevel, which comprises multip ...

Getting the value of dynamically generated buttons when they are clicked in PHP - a simple guide

In my PHP code, I have successfully created dynamic buttons. However, I am facing an issue where I need to retrieve the value of a specific button when it is clicked, and populate all the information in a form. Below is the code snippet for handling the b ...

How to vertically align a div within ion-slides

Currently, I am utilizing Ionic 2 to develop a mobile application. My goal is to incorporate two buttons (next and previous) within a slideshow of images sourced from the internet. However, I am uncertain about how to vertically align these buttons inside ...

Generate spacing between rows of content in HTML or CSS without affecting the spacing between lines of text

In my R Markdown document in R, I want to replace the header labeled "Preface" with grey lines for visual indication. Here's the code snippet I've tried: :::{#preface} <p> Text </p> ::: However, there seems to be no margin at the beg ...

My attempts at locating child elements using XPATH have been unsuccessful in finding an exact match

I have a specific requirement to input a string into the webdriver and then compare it with the label of a radio button. <input type="radio" onclick="Element.show('indicator_radio_term_190');render_selected_term('190','1', ...

Designing a versatile pop-up window with jQuery or JavaScript that functions seamlessly across all web browsers

I've encountered an issue with my code where it displays a popup message correctly in Chrome, but when testing it on Firefox and Edge, it creates a strange box at the end of the page instead. Here is the code snippet I'm referring to: var iframe ...