Steps for aligning a dropdown menu using CSS

Having difficulties aligning the dropdown menu in my Angular app.

Attached is a screenshot showing the issue. The menu currently extends too far to the right of the screen, and I need it to align to the "top right" of the ellipses instead of the "top left." It's functioning within a table.

Any help in adjusting the menu to shift to the left side would be highly appreciated.

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

HTML/CSS code snippet: 
              <td class="dropup">
                <div class="dropup">
                  <button style="background-color: white;" class="dropbtn">
                    <img class="icon" src="assets/ellipsis.png">
                  </button>
                  <div class="dropup-content">
                    <a href="#">Admin Functionality</a>
                    <a href="#" (click)="downloadBucket(j._id)"> Download Project Snapshot</a>
                    <a [routerLink]="['/project/'+j._id+'/project-activity']">View Project Activity</a>
                    <a href="#">Archive Project</a>
                    <a *ngIf="j.creatorid != user._id" (click)="onLeaveProjectClick(j._id, j.projectname, n)">Leave Project</a>
                  </div>
                </div>
              </td>

    .dropbtn {
  color: white;
  padding: 16px;
  font-size: 16px;
  border: none;
}
.dropup {
  position: relative; 
  display: inline-block;
  float:right;
}
.dropup-content {
  display: none;
  position: absolute;
  transform-origin: 60% 40%;
  top: 20px;
  background-color: #f1f1f1;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
  border-radius: 10px;
}
.dropup-content :hover {
  border-radius: 10px;
}
.dropup-content a {
  color: black;
  padding: 8px 16px;
  text-decoration: none;
  display: block;
}
.dropup-content a:hover {
  background-color: #ddd;
  color: #00aca8 !important;
}
.dropup:hover .dropup-content {
  display: block;
  border-radius: 10px;
}

Answer №1

When you specify the position of .dropup-content as absolute, it will be aligned to the left relative to .dropup since .dropup-content is nested within .dropup. However, because your class is already set to absolute positioning, you can simply add:

right: 0;
left: auto; // It's unclear if this is necessary though

to the .dropup-content class. This adjustment will ensure that the element is aligned to the right side in relation to the parent .dropup.

Answer №2

Include the following code in the .dropup-content class:

  right:0;

Link to example

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

"Effortless alignment: Centralizing CSS styling across the entire

I need help placing a loading spinner in the center of my screen, ensuring it works on both mobile and desktop devices. Here is my current CSS code: .spinner { width: 100px; height: 100px; position:absolute; top: 50%; left: 50%; margin: 100px ...

Developing a custom layer type in OL3

I am in the process of transitioning a unique dynamic layer type that I developed for OpenLayers from OL2 to OL3. This layer showcases markers (quite a substantial amount, typically around 1000) that move along predetermined trajectories. These trajectorie ...

Guide to utilizing a Boolean with a checkbox in PHP and MySQL

Trying to set up a boolean with a checkbox and save it to the database. I have experience working with strings and integers in PHP and MySQL, but struggling with booleans as I am relatively new to PHP. Can booleans be handled similarly to strings or ints ...

Show the information in an array that corresponds to the selected option in a dropdown menu

I have an array with country data and I want to display specific information based on a selected option from a dropdown menu. The 'making_calls' value should be displayed in the .price-call paragraph, and the 'sending_texts' value in t ...

Tips for maintaining the full width of an image within the viewport while also preserving a fixed aspect ratio of 16:9

After extensive research on the topic, I find the solution to implementing a parallax effect using GSscrolltrigger a bit complex. This is mainly because I need to dynamically adjust the height of the parent div based on @media CSS, while ensuring that the ...

Ensure that divs remain in a static position within the dialog box

Within the jQueryUI dialog, I have gray boxes at the top and bottom of the visible area represented by the .nav elements. I want these gray boxes to stay fixed in their position even when scrolling within the dialog. Despite setting position: absolute, the ...

Tips for appending a new row to the ToolBarContent within a MudTable

I am currently facing a challenge in adding a second row with MudChipSet for my Filter within the ToolBarContent of MudTable. My main concern is ensuring that the first row remains unaffected by this addition. Below is my existing code, and I would appreci ...

Strategies for creating a dynamic progress bar using jQuery and JavaScript

I'm currently working on a project that involves increasing a percentage number while filling up the background color inside it based on the percentage value. The current setup is functional in terms of animating the background, but I need it to dynam ...

Troublesome display problem with photo gallery

I have encountered an issue with the image gallery in my HTML file. The images are displaying nicely, but on the second row, three of the images are slipping down. Here is a screenshot for reference: https://i.sstatic.net/YmPdv.png I attempted to address ...

Updating a row individually in SQL Server 2008 with ASP.NET: A step-by-step guide

In my form, I have a variety of fields displayed in the image below: View Image of the Form Attached is a screenshot of the database with three different values inserted into three separate rows. Surprisingly, when I updated one row, all three rows were ...

Implementing Pagination Functionality Using Knockout.js

Sample JSON Data [{ "name": "A Goofy Movie (1995) 720p HDTVRip x264 Eng Subs [Dual Audio] [Hindi DD 2.0 - English DD 2.0] Exclusive By -=!Dr.STAR!=-", "progress": 0, "size": "1.06 GB", "downloaded": "87.98 KB", "hash": "8fe65e43464debe ...

Transmit an HTML table to PHP

I have successfully created a dynamic table within a form, but for some reason, it's the only element that is not being fetched. To build this table, I utilized the bootstable framework which allows for easy creation of tables with interactive featur ...

How can heights be shared among rows in HTML?

<div class="container-fluid"> <div calss="row" style="height:20%; display: block;"> <h1>20% height</h1> </div> <div calss="row"> <h1>height should be 80%</h1> </div> < ...

Showing information in a table on a webpage using JavaScript and HTML

After running a console log, I am presented with the following data: 0: {smname: "thor", sim: "9976680249", pondo: "10"} 1: {smname: "asd", sim: "9999999999", pondo: "0"} 2: {smname: "asd", sim: "4444444444", pondo: "0"} 3: {smname: "bcvb", sim: "78678967 ...

Issues with concealing the side menu bar in Vue.js

I've been attempting to conceal the side menu bar, with the exception of the hamburger icon when in the "expanded" state. Despite my efforts to modify the CSS code, I am still struggling to hide the small side menu bar. The following images represent ...

How can we use Reactjs to dynamically populate HTML content?

I'm currently working on populating navigation bar items, specifically the navigation list, using JSON data. I am attempting to iterate through the data and display dropdown navigation items. Here's an example code snippet for a dropdown navigat ...

Integrating a PHP function within an ECHO statement

Here is a code snippet I'm currently using in my Wordpress: function wpstudio_doctype() { $content = '<!DOCTYPE html>' . "\n"; $content .= '<html ' . language_attributes() . '>'; echo apply_filte ...

Using the Requests library in Python to transmit POST data

I am encountering difficulties sending POST data to access my account using the requests library in Python. The resulting soup remains unchanged as if no POST request was made. Here is the code I have been utilizing, which previously worked on a different ...

Alter the loaded image based on the switch's current status

I am working with AngularJS material and I want to dynamically load an image based on the status of a switch. Here is the relevant HTML code: If the switch status sw_status.sw1 is true, then load the image truePic.jpg. If it is false, load the image false ...

Displaying information stored in a database (using Python) on a webpage using HTML

I need assistance displaying the RandomId stored in my database on my HTML page. Can someone provide guidance on how to achieve this? Below is the snippet of my code: </script> <button onclick="myFunction()"><input type="submit" value=" ...