What is the best method for implementing border-radius on select2 elements?

I previously had a default bootstrap user select box with a border-radius style applied:

<div class="container">
  <select class="form-control" style="border-radius: 1rem;">
    <option value="1">User 1</option>

    <option value="2">User 2</option>

    <option value="3">User 3</option>

    <option value="4">User 4</option>

    <option value="5">User 5</option>

  </select>
</div>

However, I decided to switch to using the jQuery library select2 for its searching feature, but noticed that the border-radius formatting was lost.

<div class="container">
  <select class="form-control js-example-basic-single" style="border-radius: 1rem;">
    <option value="1">User 1</option>

    <option value="2">User 2</option>

    <option value="3">User 3</option>

    <option value="4">User 4</option>

    <option value="5">User 5</option>

  </select>
</div> 


$(document).ready(function() {
    $('.js-example-basic-single').select2();
});

Is there any way to maintain the border-radius styling when using select2 with my select boxes?

Answer №1

To customize Select2, you can add another element after the original select and style it using the selector

.select2-container .select2-selection
. For a more targeted approach, if you only want to style the Select2 of .js-example-basic-single, use the selector
.js-example-basic-single + .select2-container .select2-selection
.

View Working Fiddle 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

Utilizing web components in React by solely relying on a CDN for integration

I have a client who has provided us with a vast library of UI elements that they want incorporated into our project. These elements are stored in javascript and css files on a CDN, and unfortunately I do not have access to the source code. All I have at my ...

JavaScript code for Tree not functioning correctly on Internet Explorer

Seeking assistance to fix a bug in my JavaScript program. The code works perfectly on Google Chrome and Firefox, however it encounters an error in Internet Explorer 8 as indicated below. Any suggestions on how to resolve this issue would be greatly appreci ...

The android webview is having trouble loading HTML that includes javascript

I have been attempting to showcase a webpage containing HTML and JavaScript in an android webview using the code below. Unfortunately, it doesn't seem to be functioning properly. Can someone provide assistance? Here is the code snippet: public class ...

Get rid of all the formatting on an HTML button or submit

Is there a method to entirely eliminate the styling of a button in Internet Explorer? I am utilizing a CSS sprite for my button and everything appears fine. However, when I click on the button, it shifts slightly upwards which distorts its appearance. Are ...

"Stay informed with the latest updates on Wordpress through our

I am currently working on creating a static homepage with a newsfeed, but I only want to display the title and date posted. I considered using a widget, but I plan to integrate this news feed with a slideshow in the future and didn't want to limit my ...

Access the checkboxes that were previously selected and store them for future use when the page is

I am working on an HTML code where checkboxes are automatically checked and upon clicking a button, the values of checkboxes are passed through a function. Additionally, when a user checks a checkbox, the corresponding children checkboxes are also checked. ...

Bootstrap allows for multiple items to be displayed on the same line, creating

I am currently utilizing Bootstrap framework and have a total of four items. However, the last item is displaying beneath the other three items instead of being on the same line. The current code snippet is as follows: <div class="text-center linksblok ...

How to change the padding of a parent element in CSS3?

I've created a circle-shaped div element using the following code: #circle{ width: 320px; height: 320px; background-image: url('image.jpg'); border-radius: 50%; background-position: 50% 50%; transition: all 1s; } This circle expands on hov ...

Encountering problems with Node Sass versions while trying to import custom scss files into app.js

I've encountered several articles on stack that didn't quite solve my issues. The problem arose when I tried to import a custom SCSS file into my React app.js to override bootstrap theme colors. Here are the style imports in my App.js: import &q ...

Exploring the possibilities of integrating jQuery into Firefox extensions

Can someone provide guidance on effectively implementing jQuery within a Firefox extension? My research has not yielded any up-to-date methods that address the latest version of jQuery, and I am aware that directly including it via script tag may lead to c ...

Creating sequential hover animations with CSS in HTML

I have a total of four divs that I want to hover continuously, one after the other. Here is the code I am currently using: #rij1 .content-overlayz, #rij1 .content-details { animation-duration: 2s; animation-name: stepped-pulse; animation-iterati ...

JavaScript Scrolling Functionality Not Functioning as Expected

I have implemented a scroll function on my website $('#lisr').scroll( function() { if($(this).scrollTop() + $(this).innerHeight()>= $(this)[0].scrollHeight) { //Perform some action here } } However, I am encountering an ...

Getting base64 data from Node.js and showcasing it with jQuery

I have a scenario in which I store images or other types of files in my database as a blob. When retrieving that blob, I convert it to base64 by putting it in a buffer like this: file = Buffer.from(blob,'binary').toString('base64'); re ...

What is the best way to trigger a jQuery function after adding a <div> element through Ajax loading?

When I use Ajax to append a <div>, the dynamic inclusion of jQuery functions and CSS for that particular <div> does not seem to work. The insertion is successful, but the associated jQuery functions and CSS do not load properly. How can this be ...

Issue with the formatting of the disabled button

I am facing an issue with styling a disabled button. Whenever I try to apply custom styling, it reverts back to the default styling. I have already cleared my cache but the problem persists. The button is disabled using JavaScript with document.getElementB ...

What are the advantages of using REM instead of PX?

When is it ideal to choose rem over px units in CSS? Many articles advocate for using REM to accommodate user preferences, particularly when it comes to font size. However, the focus tends to be solely on font size rather than considering other aspects lik ...

Change the body selector in CssResource to apply custom styles

I have implemented a CssResource within a ClientBundle following the guidelines provided in the documentation at this link. To access the styles from my UiBinder xml, I have used ui:with as explained in the documentation available at this guide. While th ...

What is the process for incorporating a side group input with Bootstrap?

description of image here I am looking to add 4 small input boxes next to the third input box. Please refer to the image I have attached for reference. In the image, I have included 4 boxes. I am specifically looking for a similar layout. ...

When the div tag exceeds its boundaries, apply a new class

I am working on a div with set dimensions, and I am populating it with content using ng-repeat. My goal is to apply a CSS class to this div when it exceeds its limits. I attempted to use the length property but without success. var app = angular.module( ...

A JButton named "action" with HTML styling and a specific keyboard shortcut

My JButton is created with an Action that contains HTML in its name. To set the mnemonic on the JButton, I first need to extract the first character from the name by parsing out the HTML tags. For instance, if the JButton name is "Test Button", after re ...