Switch up the initial caret position in a Bootstrap 4 dropdown

This task seems trickier than I expected. I am trying to create a Bootstrap dropdown list where the caret initially points to the right and then rotates downward when expanded. Rotating the caret is not the problem, but starting with it facing right is challenging. Do I need to hide the caret and replace it completely?

CSS for rotation:

    .dropdown-toggle[aria-expanded="true"]:after {
        transform: rotate(90deg);
    }
    /*for animation*/
    .dropdown-toggle:after {
        transition: 0.7s;
    }

HTML:

<div class="dropdown">
    <span class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
        <span>
             Dropdown Example

        </span>
    </span>
    <ul class="dropdown-menu">
        <li><a href="#">HTML</a></li>
        <li><a href="#">CSS</a></li>
        <li><a href="#">JavaScript</a></li>
    </ul>
</div>

Update

To @mahan who thinks 'I must be doing something wrong". Here is the code for my test page where the caret does point right initially, but fails to rotate and expand the menu:

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>TestPage</title>
    <link href="~/Content/bootstrap.min.css" rel="stylesheet" />
</head>
<body>

<style>
         .dropdown-toggle::after {
             border-top: .3em solid transparent !important;
             border-right: .3em solid transparent !important;
             border-bottom: .3em solid transparent !important;
             border-left: .3em solid !important;
             vertical-align: middle !important;
             transition: 0.7s;
         }

         .dropdown-toggle[aria-expanded="true"]:after {
             transform: rotate(90deg);
             /*
     You may transform origin of the caret.
    */
             transform-origin: 0.15em 0.32em;
         }
</style>
<div class="dropdown">
    <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        Dropdown button
    </button>
    <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
        <a class="dropdown-item" href="#">Action</a>
        <a class="dropdown-item" href="#">Another action</a>
        <a class="dropdown-item" href="#">Something else here</a>
    </div>
</div>
</body>
</html>
<script src="~/Scripts/jquery-3.4.1.slim.js"></script>
<script src="~/Scripts/popper.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>

Answer №1

this particular style points the dropdown downward

<div class="dropdown">
</div>

this specific design opens it to the right first, then downwards.

<div class="dropright">
</div>

That's how it appears on the Bootstrap website.

Answer №2

If you're looking to update your caret icon, try this solution after hiding your current caret icon. I'm providing this different answer as the code in the question doesn't seem to be functional.

.dropdown-toggle::after {
    content: ">";
    transform: rotate(270deg);
}

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

Expansion issue with Bootstrap panel

I am currently using Bootstrap 3 for the development of a social networking site. The issue I'm encountering involves displaying comments within a panel footer on toggle. However, the comments are extending beyond the footer area. Can anyone provide g ...

Unable to generate a menu with bootstrap

Hey there, I've been experimenting with creating a responsive menu using Bootstrap, but I'm struggling with the implementation. My vision is to have a logo on the left side and a menu on the right side. Below is the concept for my menu design. ...

Is there a way to eliminate the black bar appearing on my progress bars in Chrome due to a glitch?

I've created a simple slideshow with a progress bar that functions as a 5-second timer before moving to the next slide. However, there's a strange black section on the progress bar in Chrome that I can't figure out. Here you can view the cod ...

Emblem pointing towards the header

Seeking advice for modifying arrow function: <script> $(window).scroll(function() { var pxFromBottom = 1300; if ($(window).scrollTop() + $(window).height() > $(document).height() - pxFromBottom) { $('#nagore').fa ...

What is the best way to showcase a product's star rating using a variable or input from the user?

I'm seeking a solution to dynamically display a star rating in Spring Boot/Java without specifying a fixed value. While I can show star ratings with a set value, how can I update the rating based on an average of user ratings? Most tutorials only cove ...

Enhance the appearance of your HTMLEditorField in SilverStripe 3.2 by customizing its CSS style using

I have configured the HtmlEditorConfig for a Content HTMLEditorField. The issue I am facing is that I have to refresh or reload the browser page in order to see my custom CSS settings... Here is my code: HtmlEditorConfig::get('cms')->setOpti ...

Exploring the growth of CSS offsetting alongside with AngularJS

I am working on an Angular app where I need to increase the left offset of a div by 90px every time the slideThis() function is called. In jQuery, I would typically achieve this using left: '+=90', but I'm struggling to find a similar method ...

Modify the text of a label for an individual series in Highcharts

I have customized my stacked bar highchart so that the last series is colored grey. However, I am wondering if there is a way to change the text color to black for this specific series where the background color is grey. plotOptions: { series: { ...

Unable to modify the color of UML state elements within JointJS

I need some help with jointjs as I am in the process of adjusting the color of a UML state diagram graph using this command: graph.getElements()[4].attributes.attrs[".uml-state-body"]["fill"] = "#ff0000"; However, despite trying this, the color of the st ...

Tips for aligning the menu content of a mobile view navbar to the center using bootstrap 4

When viewing on mobile, my text is left aligned instead of centered. I am using bootstrap4. How can I center the menu contents when it collapses? https://i.sstatic.net/VAs2O.png <ul class="navbar-nav ml-auto"> <li ...

Customized icons for Contact Form 7 on your Wordpress website

Currently, I am in the process of customizing a contact form by incorporating placeholder icons and text using the 'Contact Form 7' plugin within Wordpress. This particular contact form is situated on a website that I am constructing with the &ap ...

Merging Fewer with Visual Studio 2012

Combining all Less files into a single stylesheet? After following the instructions in the above link, I have successfully merged my Less files together for easier CSS reading during development. However, I would like to ensure that end users only need to ...

Position a DIV above another DIV

Recently, I was given the task of replicating a JavaScript popup that our former web developer created. While I've managed to make it very similar, there is one thing I'm struggling with - getting the close button (X) to float over the popup in t ...

Enhancing User Interaction with Bootstrap Input Forms

Struggling with a CSS and Bootstrap issue, I am unable to find a solution. The problem I am facing is that the content in a div form is not responsive within its parent div. It always extends beyond the parent div and does not adjust its size when the scre ...

Adjust the checkbox dimensions within the cells of a bootstrap table

I am utilizing bootstrap-table along with a column containing checkboxes. I need to adjust the size of the checkboxes in my code to be 25x25 pixels. However, when I try using the height and width CSS attributes, it does not seem to take effect. html < ...

Guide to updating the value of a CSS seconds dynamically

let timerSeconds = 10; // This value will be retrieved from a database function StartCountDownTimer() { let timerStart = new Date(); let css_seconds = `${timerSeconds}s`; const css_root = document.querySelector(':root'); let cssVa ...

"Stay entertained with a captivating animated gif that appears when you refresh the

I just implemented this code snippet to enable animated gifs to work after refreshing a webpage. It's functioning properly in Chrome, Safari, and Internet Explorer except for Firefox. Can someone please offer assistance? jQuery: $(img).css("backgrou ...

Creating uniform height for Definition Terms (DT) and Definition Descriptions (

Looking to creatively style a description list <dl> in a way that showcases two columns, even when there are multiple <dd>s following the <dt>. The challenge lies in wanting this design to be dynamic without resorting to floating the < ...

What is the best way to adjust the width of these elements for a perfect fit?

I'm currently working on a website where I have arranged squares in a grid layout. My goal is to make these squares perfect, with equal width and height. The only issue I'm encountering is that they tend to change between fitting two and three sq ...

Problem saving videos when using the right-click function

Hello, I am currently working on retrieving videos from a database, but I have encountered an issue with the video saving option. When a user right-clicks on the video, they are able to save it in their system's storage. What I would like to achieve ...