javascript - How to style the button in bootstrap vue dropdown like a circle - Stack Overflow

I am using Bootstrap Vue b-dropdown () like so:I want to be able to style the button (to open the drop

I am using Bootstrap Vue b-dropdown () like so:

I want to be able to style the button (to open the dropdown) as a circle with a + icon inside of it.

I can create the circle using the following css:

.btn-circle.btn-xl {
    width: 70px;
    height: 70px;
    padding: 10px 16px;
    border-radius: 35px;
    font-size: 24px;
    line-height: 1.33;
}
.btn-circle {
    width: 30px;
    height: 30px;
    padding: 6px 0px;
    border-radius: 15px;
    text-align: center;
    font-size: 12px;
    line-height: 1.42857;
}

And then using

<b-button
   class="btn btn-circle btn-xl"
>
    <i class="far fa-plus" />
</b-button>

Generates my circular button.

However,when using bootstrap vue dropdown, the option to style the button is with using the template:

<template #button-content>
        <b-button
          class="btn btn-circle btn-xl"
        >
          <i class="far fa-plus" /><span class="sr-only">{{ $tU('general_actions') }}</span>
        </b-button>
      </template>

This does however give the correct result, but semantically, it creates a button inside a button.

How do I solve this so that it's not longer a button inside a button, but it still gives the correct layout?

EDIT: I tried creating a codepen, but I don't know why nothing is showing up...

I am using Bootstrap Vue b-dropdown (https://bootstrap-vue/docs/ponents/dropdown) like so:

I want to be able to style the button (to open the dropdown) as a circle with a + icon inside of it.

I can create the circle using the following css:

.btn-circle.btn-xl {
    width: 70px;
    height: 70px;
    padding: 10px 16px;
    border-radius: 35px;
    font-size: 24px;
    line-height: 1.33;
}
.btn-circle {
    width: 30px;
    height: 30px;
    padding: 6px 0px;
    border-radius: 15px;
    text-align: center;
    font-size: 12px;
    line-height: 1.42857;
}

And then using

<b-button
   class="btn btn-circle btn-xl"
>
    <i class="far fa-plus" />
</b-button>

Generates my circular button.

However,when using bootstrap vue dropdown, the option to style the button is with using the template:

<template #button-content>
        <b-button
          class="btn btn-circle btn-xl"
        >
          <i class="far fa-plus" /><span class="sr-only">{{ $tU('general_actions') }}</span>
        </b-button>
      </template>

This does however give the correct result, but semantically, it creates a button inside a button.

How do I solve this so that it's not longer a button inside a button, but it still gives the correct layout?

EDIT: I tried creating a codepen, but I don't know why nothing is showing up... https://codepen.io/anjazb/pen/zYBoMQp

Share Improve this question edited Oct 22, 2020 at 17:27 Dennis asked Oct 22, 2020 at 17:04 DennisDennis 3,7303 gold badges39 silver badges59 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

If you want to add classes to the toggle button inside <b-dropdown>, use the toggle-class prop.

There might also be an easier way for you to create a round button by using the utility class rounded-circle, to create a round border radius, and px-2 to adjust the padding to fit correctly.

new Vue({
  el: '#app'
})
<script src="https://unpkg./[email protected]/dist/vue.min.js"></script>
<script src="https://unpkg./[email protected]/dist/bootstrap-vue.js"></script>
<script src="https://unpkg./[email protected]/dist/bootstrap-vue-icons.js"></script>

<link href="https://unpkg./[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://unpkg./[email protected]/dist/bootstrap-vue.css" rel="stylesheet" />


<div id="app">
  <b-button variant="primary" class="rounded-circle px-2">
    <b-icon icon="plus" scale="2"></b-icon>
  </b-button>

  <b-dropdown variant="primary" toggle-class="rounded-circle px-2" no-caret>
    <template #button-content>
      <b-icon icon="plus" scale="2"></b-icon>
    </template>

    <b-dropdown-item>Item 1</b-dropdown-item>
    <b-dropdown-item>Item 2</b-dropdown-item>
    <b-dropdown-item>Item 3</b-dropdown-item>
  </b-dropdown>
</div>

Even this will work in version 4 by using:

css:border-radius:100%;

bootstrap: removing dropdown-toggle and using

<i class="fa fa-plus" aria-hidden="false"></i></button>

the whole code is like :

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="https://cdnjs.cloudflare./ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare./ajax/libs/font-awesome/5.10.0-11/css/all.min.css">
    <link rel="stylesheet" href="style.css">
    <title>Title</title>
    <style>

    </style>
</head>

<body>


    <div>
        <button class="btn btn-primary " style="border-radius:100%;" id="dropdownMenuButton" data-toggle="dropdown">
            <i class="fa fa-plus" aria-hidden="false"></i></button>
        </button>

        <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
            <a class="dropdown-item" href="#">1</a>
            <a class="dropdown-item" href="#">2</a>
            <a class="dropdown-item" href="#">3</a>
        </div>
    </div>
    <script src="https://cdnjs.cloudflare./ajax/libs/jquery/3.4.1/jquery.slim.min.js"></script>
    <script src="https://cdnjs.cloudflare./ajax/libs/popper.js/1.15.0/umd/popper.min.js"></script>
    <script src="https://cdnjs.cloudflare./ajax/libs/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
</body>

</html>

see: https://jsfiddle/9ubdkm2r/1/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745352504a4623919.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信