What CSS properties can I modify to adjust the alignment of a collapsible UL menu activated by a click?

Looking for a way to adjust the alignment of your menu bar? Let's dive in:

https://i.sstatic.net/qThGX.png

The left "hamburger" menu expands smoothly from left to right. Everything looks good:

https://i.sstatic.net/b2cRa.png

However, the right menu also opens from left to right, which might not be ideal:

https://i.sstatic.net/1fcqO.png

If you want the right menu to align with the right edge, similar to how the left one aligns with the left edge, here's what you can do:

Check out the HTML snippet below. The CSS code is a bit lengthy, so I've provided a link for it.

<div id='header'>
    <div id='headerContent'>
        <div id='breadcrumbs'>
            <div id='hamburger' class='headerMenu'>
                <i class='fa fa-bars'></i>
                <ul>
                    <li><a href='/'>Page</a></li>
                    <li><a href='/'>Whatever</a></li>
                    <li><a href='/'>Other stuff</a></li>
                </ul>
            </div> Title
        </div>
        <div id='login'>
            <div class='headerMenu'>
                <i class='fa fa-user-circle'></i>
                <ul>
                    <li><a href='/user/logout/'>Logout</a></li>
                </ul>
            </div>
        </div>
    </div>
</div>

Answer №1

In my opinion, creating a container to house the button and menu with position: relative and applying text-align: right, then utilizing right: 0 on the menu seems like the appropriate approach:

#header {
  background: lightblue;
}
.right {
  text-align: right;
  position: relative;
  width: 200px;
}
.popup {
  position: absolute;
  padding-left: 0;
  margin: 0;
  right: 0;
  background: lightgreen;
}
<div id="header">
  <div class="right">
    <a>Menu</a>
    <ul class="popup">
      Popup menu
    </ul>
  </div>
</div>

The container div can be adjusted in various ways (such as changing its width, margin, adding display: inline-block, etc) without affecting its functionality.

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

A JavaScript Regex that eliminates all content outside specific HTML tags, including the tags themselves

Trying to parse a SOAP output using JS REGEX, even though it's not the ideal method. The format is as follows: *huge header* <NewDataSet> *content* </NewDataSet> *rest of footer* The goal is to remove everything outside the <NewDataSe ...

Responsive design parameters

After creating a media query specifically for phones, I realized that I needed one for desktop as well. @media screen and (max-device-width: 480px), screen and (max-width: 480px) { ...css here... body {width:50%;} However, when I attempted to add a sim ...

Specifying a zero margin on a Bootstrap container does not remove the margin

I am trying to make my right container elements fill the entire width of their column. After inspecting in Chrome, I noticed that my bootstrap container had default margins on both sides. To fix this, I set the margins to zero. Although the left margin di ...

Assigning a class to every alternate item

Currently, I am in the process of compiling a list of products. To enhance the layout, I would like to assign a specific class to every other element. This class could be :before, :after, or simply .My-clas <div class="product-single"></div> ...

The website is plagued by the presence of unwanted hyperlinks

There seems to be unwanted hyperlinks appearing in the text content on my website. Website URL: http://www.empoweringparents.com/my-child-refuses-to-do-homework-heres-how-to-stop-the-struggle.php# Could you please review the 10th point? There are links b ...

What is the best way to automatically redirect visitors from the homepage to the specific tab section on the about

Within the slider on my home page, there is a "read more" link in each slide. Upon clicking the read more link, it redirects to the "industriessolutions_trial.php" page which contains four categories. By clicking on a category, the details for that specifi ...

Creating an HTML element with jQuery using the before() method

Here is the code snippet I am working with: $(document).on("click", "#add", function() { console.log("clicked"); $(this).before('<lable>'+ current +'.</label><input type="text", id="option"><br>'); ...

The functionality of my bootstrap carousel seems to be malfunctioning as the fdi-Carousel slide is

Whenever I check for errors in the Chrome console, I come across this error: Uncaught ReferenceError: $ is not defined. It seems to be related to my code. Can anyone help me identify what might be causing this issue? Below is a snippet of my code from &apo ...

Simple: What is causing the error message "TypeError: 'int' object is not callable" to appear? (refer to line 24 in the code)

I'm struggling with a coding issue and can't seem to find a solution. Would appreciate it if someone could provide some guidance on what's going wrong. Essentially, this script is designed to fetch the HTML content of a URL, extract specific ...

Use the Arrow Keys to guide your way through the Page

I am looking to enhance user experience by allowing them to easily navigate through my webpage using the arrow keys on their keyboard. The goal is for users to be able to move from one section to the next in a seamless manner, unless they are focused on an ...

What could be the reason for my submit button failing to submit data to mySQL?

My PHP form, referred to as "php1," utilizes AJAX to populate input text boxes from a MySQL database using a secondary page called "php2." The issue I am facing is that the submit button on php2 does not work properly, unless I test php2 individually. When ...

Incorporating information into an HTML webpage

Question: How can I create a dropdown menu in HTML with a list of languages (e.g. English, French) and display them based on the native language? I want to show the languages in their respective native language on the combo box (e.g. "french" displayed a ...

I can't seem to get the button to function properly, and it's really

I am having an issue with my "Let's Get Fit" button. When I hover over it or click it, the cursor doesn't change and it doesn't lead to index.html. I'm not sure why it's not working. .btn { display: inline-block; text-transf ...

What could be causing my bootstrap to overlap?

Hello everyone, I am currently in the process of creating a basic template to enhance the overall design of my website. I recently started utilizing Bootstrap and encountered an issue where my footer is overlapping when I resize my browser to a smaller siz ...

How can I set random background images on my Wordpress site?

I am currently using WP version 3.5.1 along with a twenty twelve child theme and PHP 5.2 on my server. I have been attempting to implement a php script (which has successfully worked on my other websites) to display random background images, however, it se ...

Implementing Hover Effects on Images in WordPress

I'm searching for the best way to create an Image Transparency - Hover Effect in WordPress. I have a set of company logos that I want to fade until hovered over. Is there a simple solution out there? Any recommended code snippets or CSS suggestions wo ...

Utilizing the power of JavaScript/JQuery to showcase a compilation of all input values within an HTML form

I'm struggling to showcase all the input values from my HTML form on the final page before hitting the "submit" button. Unfortunately, I am facing a challenge as the values are not appearing on the page as expected. Despite several attempts, the valu ...

Changing the size of a background image is proving to be quite a challenge for me

I'm completely new to HTML and CSS. I've been working through a book titled The Missing Manual, CSS3 but I've hit a roadblock when it comes to changing the size of an image that I want to use as a background. In order to troubleshoot the iss ...

Tips for choosing the most current or upcoming item from a list using buttons

I am currently working on a small website project for one of my lessons. The task involves selecting items from a list and using two arrows to navigate to the item above or below the current selection. Here is an example: https://i.stack.imgur.com/FxZCN. ...

Is it possible to create a torn border effect in CSS with no images?

Is there a straightforward method to achieve a torn border on just one side of a div block without the need for external images? ...