Attempting to align the dropdown menu to the left side

This is a challenge I'm facing:

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

I'm attempting to align it in the following way:

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

Below is the HTML code snippet:

<li class='list-group-item'>
<!-- The dropdown toggle button for the edit / delete options -->
<div class="btn-group editdeletetoogle">
    <button type="button" class="btn btn-default-outline dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        <span class="sr-only">Toggle Dropdown</span>
    </button>
    <div class="dropdown-menu">
        <a class="dropdown-item" href="#">Edit</a>
        <div class="dropdown-divider"></div>
            <a class="dropdown-item" href="#">Delete</a>
        </div>
    </div>
</li>

Here's the corresponding CSS:

.editdeletetoogle .dropdown-toggle
{
    width: 20px;
    height: 20px;
    margin:0;
    padding:0;
    top:-30px;
    right:-30px;
    z-index: 10;
    color: black;
    background-color: transparent;

}/* '' delimiter */

.editdeletetoogle .dropdown-item
{
    font-size: 15x;
    padding:0px 0px 0px 10px;
    width: 5px;
}

.editdeletetoogle .dropdown-menu
{
    margin-top: -25px;
    width: 5px;
}

I've tried using `display: block`, but the dropdown menu displays permanently instead of on button click.

Initially, I attempted this:

.editdeletetoogle .dropdown-menu
{
    margin-top: -5px;
    width: 5px;
    position: relative;
    right: 20px;
}

However, it resulted in the dropdown menu behaving incorrectly.

On trying the following:

.editdeletetoogle .dropdown-item
{
    font-size: 15x;
    padding:0px 0px 0px 10px;
    width: 5px;
    position: relative;
    right: 20px;
}

The outcome was not as intended.

But after making the necessary adjustments, the issue got resolved:

<div class="dropdown-menu pull-right">
<a class="dropdown-item" href="#">Edit</a><div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Delete</a>
</div>

.editdeletetoogle .dropdown-menu
{
    margin-top: -25px;
    right: -30px;
    width: 60px !important;
    max-width: 60px;
    min-width: 60px;
    border-radius: 0px;
}

https://i.sstatic.net/4ZKbr.png

Answer №1

It's difficult to provide a precise solution without a codepen or fiddle, but you can try the following:

.editdeletetoogle .dropdown-menu{
    margin-top: -25px;
    width: 5px;
    position: relative;
    right:30px; /** Adjust this value **/
}

Uncomment your previous code and make necessary adjustments to the right property

Answer №2

Once, I encountered a similar issue that was resolved by simply adding the left: tag.

.dropdown-menu {
border-radius: 10px;
border: solid 1px rgba(100, 100, 100, 0.3);
width: 30%;
padding: 8px 0px;
position: fixed;
top: 80%;
left: 45%;
z-index: -1;
opacity: 0;
transition: opacity ease-in-out 0.2s;
box-shadow: 1px 3px 5px rgba(0,0,0,0.4);
background: #f9f9f9;}

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

Can you use both HTML and JSON in ROR?

The scaffolding process generates controllers that include Create/Update methods. These methods are responsible for rendering HTML as well as JSON data. While I am familiar with HTML, I have limited knowledge about JSON. Should JSON be included in this cod ...

The property 'innerHTML' cannot be assigned to null, as stated in Vue

I am dealing with two components that allow for editing JSON objects. Additionally, I have a button that toggles between these two components. Below is the HTML code snippet: <v-btn @click="switchConfigClicked">Switch config</v-btn> <h4 cla ...

Updating website content dynamically using Javascript and JSON-encoded data

My programming code seems to be acting oddly. I have structured my data in a JSON object as follows: injectJson = { "title": "Champion Challenge Questions", "rules": [ { "idChrono": "chrono-minute", "text": "Top is missing!", ...

Displaying TestNG Reporter information in Gradle-generated HTML test reports

I've been searching high and low for a solution to my problem with no luck, so I'm turning directly to you. Is there any way to display TestNG's Reporter output in Gradle HTML reports? Here's the scenario: I have multiple testNG test m ...

What is the purpose of Firebug adding <tbody> elements to <table> tags?

While analyzing the HTML source code, I noticed that the <tbody> tag is missing. However, when inspecting the code using Firebug in the HTML tab, the <tbody> tag suddenly appears. What could be the reason behind this discrepancy? ...

Having trouble importing CSS in ReactJS?

While working on my project based on next.js, I encountered a situation where loading CSS in other pages was successful: import css from './cssname.css'; <div className={css.myclass}></div> However, now that I am implementing a ligh ...

Stop Bootstrap IE menu from closing when scrollbar is clicked

When using IE, the dropdown menu closes when clicking on the scrollbar. However, it functions properly when scrolling with the mouse wheel. To see the issue in action and potentially offer a solution, you can visit this Codeply link: I'm seeking sug ...

How can we ensure that specific criteria are displayed once a selection is made?

Users have multiple options to choose from. When a user selects one option, I want to display additional options that are dependent on the initial selection. For example, if the user can select between 1 or 2 gates, upon choosing a number I will show all t ...

What is the best way to format or delete text enclosed in quotation marks within an anchor tag using CSS or JavaScript?

I have encountered an issue with a dynamically generated login form. When I select the 'Forgot Password' option, a new 'Back to Login' message appears along with a separating '|' line. Removing this line is proving challenging ...

Fetching JSON data using Javascript/JQuery

My goal is to access JSON data from an online web service that queries a MySQL database for a specific string and use Javascript to present it on an HTML page. My challenge lies in effectively displaying the retrieved information. The relevant part of my ...

Mobile media queries are ineffective despite implementing the viewport meta tag

I am facing an issue that even though I have tried various solutions, my media queries are not working on mobile devices after adding the viewport meta tag. Can anyone provide insight into why this might be happening? Update: Upon further investigation, I ...

An effective method for modifying the active class on an li element in jQuery and ensuring that the user is directed to the desired page upon clicking the li element

I am facing an issue with my script tag. When I click on the links test.php or test2.php, the active class changes from index.php to the respective file but I am not redirected to the clicked page. I have tried solutions from various sources but none of th ...

Display an image with a colored background using CSS

Most of you have probably noticed that images on Facebook come with a default background. How can I achieve a similar background color for images without using an additional div just for the background? My current codes do create a background color, but th ...

Having difficulties with Cypress test for dragging and dropping an element within the same area

I am experimenting with the drag and drop feature using a plugin called 4teamwork/cypress-drag-drop. I have a scenario where there are three elements stacked on top of each other. The task is to select the first element and move it under the last element i ...

A guide to utilizing CSS to showcase the content of all four div elements in HTML body simultaneously

Is there a way to use CSS to display the content of all 4 divs in the same place on the HTML body, based on the URL clicked? Only one div should be displayed at a time in the center of the page. For example, if URL #1 is clicked, it should show the conten ...

Ways to show a corresponding number beneath every image that is generated dynamically

I have a requirement to show a specific image multiple times based on user input. I have achieved this functionality successfully. However, I now need to display a number below each image. For example, if the user enters '4', there should be 4 im ...

Swapping out video files with varying quality using HTML5 and Jquery

Objective: Implementing a feature to change the video being played when a user clicks a button using Jquery. Example website for reference: (click on the "hd" button in the player control) More details: When the page loads, the browser will play the fi ...

Mobile browsers experiencing issues with playing HTML5 videos

Having trouble with HTML5 Video not working on my mobile device? I've encountered several issues when trying to load videos on my mobile browsers. When I attempted to remove controls, the video wouldn't show up on the mobile browser at all. Addin ...

Connect two radio buttons across separate forms

I am encountering an issue with two radio buttons that I am trying to link together. The problem arises because they are located in two separate form elements, causing them not to function as intended. It is important for the forms to be utilized in Bootst ...

One approach to animating elements on a web page is by utilizing Node.js

Imagine you want to programmatically define animated movement for elements on a web page. In JavaScript, this can be achieved using techniques outlined in this helpful guide: How TO - JavaScript HTML Animations. But how would you do this in Node.js? UPDAT ...