Tips for positioning bootstrap-vue dropdown button items evenly

Can anyone help me align the dropdown button child items horizontally? I've tried customizing it with CSS but no luck. The control link can be found here

Check out a sample on Js Fiddle here

This is how I expect the design to look like:

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

    new Vue({
  el: '#app',
 
data:{
       
         fruits: ['Apple', 'Banana', 'Orange'],
         selectedFruit: '',
       
     },
     methods: {
    selectFruit (index) {
      this.selectedFruit = this.fruits[index]
        }
      }
})
   

 .dropdown-demo {
  width: 200px;
  background-color: white;
  border-bottom: solid 1px black;
  >div {
    background-color: azure;
    width: 100%;
    button {
      background-color: yellow !important;
      padding-left: 0;
      padding-right: 0;
      width: 100%;
      text-align: right
    }
  }
  <link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.js"></script>
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.css"/>

<script src="//unpkg.com/babel-polyfill@latest/dist/polyfill.min.js"></script>
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.js"></script>
<div id="app">
         <div class="dropdown-demo">
            <b-dropdown variant="link" size="lg" no-caret>
              <template slot="button-content">
                <span>Fruits:</span>
                <span> {{selectedFruit}}</span>
                &#x1f50d;<span class="sr-only">Search</span>
              </template>
              <b-dd-item v-for="(item, id) in fruits"
                         @click="selectFruit(id)"
                         :key="id">
                {{item}}
              </b-dd-item>
            </b-dropdown>
          </div>
</div>

Answer №1

Make sure to add a class called dd to your div that has the attribute slot="button-content". The class should have the following CSS rules:

  .dd{
    width:190px;
    display:flex;
    flex-direction:row;
    justify-content:space-between;
    align-items:center;
    }

new Vue({
  el: '#app',
 
data:{
       
         fruits: ['Apple', 'Banana', 'Orange'],
         selectedFruit: '',
       
     },
     methods: {
    selectFruit (index) {
      this.selectedFruit = this.fruits[index]
        }
      }
})
.dropdown-demo {
  width: 200px;
  background-color: white;
  border-bottom: solid 1px black;
}

.dd{

width:190px;
display:flex;
flex-direction:row;
justify-content:space-between;
align-items:center;
}
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.js"></script>
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.css"/>

<script src="//unpkg.com/babel-polyfill@latest/dist/polyfill.min.js"></script>
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.js"></script>
<div id="app">
     <div class="dropdown-demo">
        <b-dropdown variant="link" size="lg" no-caret>
          <div slot="button-content" class="dd">
            <div>Fruits:</div>
            <div> {{selectedFruit}}</div>
            &#x1f50d;<span class="sr-only">Search</span>
          </div>
          <b-dd-item  v-for="(item, id) in fruits"
                     @click="selectFruit(id)"
                     :key="id">
            {{item}}
          </b-dd-item>
        </b-dropdown>
      </div>
</div>

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

Is it possible to combine margin auto with a transform on the left simultaneously?

While examining a webpage, I noticed a positioning issue and decided to remove some CSS code to determine the root of the problem. It appears that the navbar has a 1px gap on the left side from the edge of the screen. After removing the last two lines of c ...

Activate the toggle feature on the navigation bar using Bootstrap

Below is the code I am using: <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8defe2e2f9fef9ffecfdcdb8a3bda3bf">[email protected]</a>/dist/css/bootstrap.min.css" rel ...

Date selection does not activate the onChange event

I've integrated Bootstrap 4 into my React JS project. To add the bootstrap datepicker, I simply linked it in my index.html file like this: <!doctype html> <html className="no-js" lang="zxx"> <head> <meta cha ...

Is it possible to hide the <dd> elements within a <dl> using knockout's custom data binding upon initialization?

I have implemented a <dl> where the <dd> can be expanded/collapsed by clicking on the corresponding <dt> using knockout's data binding. The inspiration for my solution came from a tutorial on creating custom bindings. Currently, I h ...

Expand Bootstrap navbar search box outside collapse menu

Currently, I am working on designing a navigation bar that showcases my brand on the left side, a full-width search bar in the center, and additional pages on the right. I am facing challenges in maintaining the full-width of the search bar without causing ...

Utilizing an Apollo query that relies on the outcome of a previous query

I’m in the process of constructing an Apollo query within a Vue/Nuxt environment that relies on the outcome of another query. The sessions query requires the presence of person to access this.person.id. How can I make sure that person is available befor ...

Is it beneficial to utilize CSS3 hardware acceleration translate3d for benchmarking purposes? Is it advisable to implement it on the body element

While browsing through content, I stumbled upon a query regarding the impact of transform: translate3d(0,0,0) or transform: translateZ(0) on enabling CSS3 hardware acceleration for animations across different platforms and browsers. It mentioned that combi ...

Counting the number of visible 'li' elements on a search list: A guide

In the following code snippet, I am attempting to create a simple search functionality. The goal is to count the visible 'li' elements in a list and display the total in a div called "totalClasses." Additionally, when the user searches for a spec ...

How can we prevent the text from shifting when the border width is adjusted

I've run into an irritating issue. My left menu text keeps shifting when I expand the border using jQuery. I've tried various solutions to prevent the text from moving, but nothing seems to work. Any suggestions? Could it be a CSS problem with t ...

Display content in two columns. If the width of the left column is too narrow, move the content in the right column

In my layout, there is a wrapper div with two child elements: left div and right div. The left div contains text which can be lengthy, while the right div holds an image loaded asynchronously without known width: <div id="wrapper"> <div id="l ...

Organize the Div elements in the form of a message

Here is the code I am working with: https://jsfiddle.net/bdqgszv5/1/ This is the same code without jsfiddle: <section id="aussteller" class="row separated"> <div class="section-header text-center"> <h2& ...

The fancybox's excess content is concealed

I've recently integrated fancybox 2 into my project and have encountered an issue when appending HTML content to the modal. I disabled scrolling, but now any overflowing content is being hidden. Could this be related to the max-height of the modal? Ho ...

Mastering the Art of Utilizing $(this) in jQuery

$(".item_listing").hover(function(){ $(".overlay_items").display(); },function(){ $(".overlay_items").hide(); } ); This is my jQuery code. I am trying to display the "overlay_items" div when the "item_listing" div is hovered ov ...

Does the icon vanish once you alter the button's color?

Warning: Adult content Check out this website: link When you visit this page, you'll notice that the Add to Cart button is orange. The button also has an icon of a shopping cart. This icon only appears if you remove the following code. To make th ...

Personalized CSS styling for Jquery Mobile version 1.3

Having trouble with styling a page in jquery using CSS, specifically aligning #navgroup to the center of the footer and removing an additional white counter from the slider. Here is my code: <!doctype html> <html lang="en> <head> < ...

Use Javascript to display an image based on the date, otherwise hide the div

I'm looking to implement an image change on specific dates (not days of the week, but actual calendar dates like August 18th, August 25th, September 3rd, etc). Here's the div I'm working with: <div id="matchday"> <img id="home ...

Rearrange two elements by flipping their positions using CSS

I'm working with the following div that contains an input and a label: <div class="js-form-item "> <input type="checkbox" id="checkboxes-11" class="type-checkboxes form-checkbox"> <label for="option-a-checkboxes-11" class=" ...

JavaScript-powered horizontal sliderFeel free to use this unique text

I'm new to JS and trying to create a horizontal slider. Here's the current JS code I have: var slideIndex = 0; slider(); function slider() { var i; var x = document.getElementsByClassName("part"); for (i = 0; i < x.length; i++) { x[i].styl ...

Choose certain table cells that do not have an identifier or any classes assigned to them

My table has 3 rows and 3 data cells. To select the first row, first data cell, and all bold tags from it: tr + td b {} To select the second row, second data cell, and all bold tags from it: tr+tr > td+td b {} I need help selecting them without usi ...

Unable to display values in Fusion Charts zoomline chart using the showValues chart property

I'm struggling to figure out how to display the data plot values with showValues: '1' in a zoomline chart using Fusion Charts. You can see and test it on this fiddle: http://jsfiddle.net/60oeahc1/4/ Is there a way to make this feature work ...