Tips for Concealing the Border in a Select Element using HTML and CSS

I am trying to achieve a select element without borders before and after the option is selected. I have attempted to use the following CSS code, but unfortunately, it has not been successful.

.custom-select{
  font-family: Raleway;
  font-size: 18px;
  color: grey;
  min-height: 75px;
  width: 99%;
  height: auto;
}

select{
  min-width: 40px;
  min-height: 40px;
  width: 99%;
  border: 0;
  border-width: 0px;
  box-shadow: 5px 5px 10px rgba(0, 40, 0, 0.5);
  border-radius: 5px;
  box-sizing: content-box;
}

select option:checked{
  background-color: grey;
  border-width: 0px;
  box-sizing: content-box;
  border: 0;
}

select:active{
  background-color: grey;
  border-width: 0px;
  box-sizing: content-box;
  border: 0;
}
 <div class="cutom-select">
    <select>
        <option>India</option>
        <option>India</option>
        <option>India</option>
    </select>
</div>

 

https://i.sstatic.net/ZpvAE.png Please advise on where I might be making a mistake. Thank you.

Answer №1

Give this a try:

.custom-select select:focus{
    outline: none !important;
}

Here is a demonstration of the code in action:

.custom-select{
  font-family: Roboto;
  font-size: 16px;
  color: lightgrey;
  min-height: 70px;
  width: 98%;
  height: auto;
}

select{
  min-width: 35px;
  min-height: 35px;
  width: 98%;
  border: 0;
  border-width: 0px;
  box-shadow: 3px 3px 6px rgba(0, 20, 0, 0.5);
  border-radius: 3px;
  box-sizing: content-box;
}

select option:checked{
  background-color: lightgrey;
  border-width: 0px;
  box-sizing: content-box;
  border: 0;
}

select:active{
  background-color: lightgrey;
  border-width: 0px;
  box-sizing: content-box;
  border: 0;
}

.cutom-select select:focus{
    outline: none !important;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

<div class="cutom-select">
        <select>
            <option>USA</option>
            <option>Canada</option>
            <option>Mexico</option>
        </select>
    </div>

Answer №2

apply select:focus {outline: none;}

Answer №3

Remember, that's not a border - it's an outline. To get rid of it, you'll need to use outline: none;. For more information on outlines, check out this link.
like this

.custom-select{
  font-family: Raleway;
  font-size: 18px;
  color: grey;
  min-height: 75px;
  width: 99%;
  height: auto;
}

select{
  min-width: 40px;
  min-height: 40px;
  width: 99%;
  border: 0;
  border-width: 0px;
  box-shadow: 5px 5px 10px rgba(0, 40, 0, 0.5);
  border-radius: 5px;
  box-sizing: content-box;
  outline: none; /* <-------[added line] (if it doesn't work like this adding !important) */
}

select option:checked{
  background-color: grey;
  border-width: 0px;
  box-sizing: content-box;
  border: 0;
}

select:active{
  background-color: grey;
  border-width: 0px;
  box-sizing: content-box;
  border: 0;
}
<div class="cutom-select">
    <select>
        <option>India</option>
        <option>India</option>
        <option>India</option>
    </select>
</div>
Be cautious! This code always eliminates the outline (even when the element is not focused). To remove it only when focused, apply :focus.

Keep in mind that Outline and borders differ! Unlike borders, the outline is drawn outside the element's border and may overlap other content. Additionally, the outline does NOT contribute to the element's dimensions; the overall width and height remain unaffected by the outline's width.
In certain browsers, such as Google Chrome, the outline is automatically set when selected on elements like select or button
Also note (from W3Schools) that outline comes with the following properties.

dotted - Defines a dotted outline
dashed - Defines a dashed outline
solid - Defines a solid outline
double - Defines a double outline
groove - Defines a 3D grooved outline
ridge - Defines a 3D ridged outline
inset - Defines a 3D inset outline
outset - Defines a 3D outset outline
none - Defines no outline
hidden - Defines a hidden outline

https://i.sstatic.net/QeIfT.jpg

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

What is the best way to align these JavaScripts side by side using div elements?

After searching many sources and attempting various methods, I am still struggling to position two lines of code side by side on my website. My attempted solution can be found at the bottom of the code. http://pastebin.com/mV1DUbg0 The code looked strang ...

Verify Departure on External Links within Wordpress

Let me set the stage for you: We're dealing with a bank website here. So, whenever a user wants to click on an external link (could be to a Facebook page or a partner website), we need to have a notification box pop up saying "You are about to lea ...

CSS: The relative positioned element now functions correctly with the inclusion of overflow-x

Is there a way to ensure that the images in the day_time_block cover the title class? I would also like all contents within the day_time_block to be displayed using overflow-x. However, when I add overflow-x: auto; to the scroll div, the images in the d ...

ReactStrap: Difficulty concealing navbar item based on screen dimensions

Currently, I am referring to the official documentation to implement a scenario where a NavItem is only displayed for screen sizes greater than sm. As per the guidelines provided in the documentation, I have included the following attributes: https://i ...

The image will remain hidden until it is fully loaded and ready to be displayed

I am currently working on a script that involves displaying a loading icon until an image is fully loaded, at which point the loading icon should disappear and the image should be shown. Unfortunately, my current code is not working as intended. Here is a ...

Intersecting Hyperlink Elements Creating a Hover Effect

I've encountered a perplexing CSS display issue and I'm at a loss for alternative solutions besides simply widening the width of the parent div. Allow me to explain the layout: <div> <ul> <li> <a href="javascrip ...

Ways to send data to a popup in svelte

Hey there, I could really use some assistance with my Svelte app. I'm trying to implement a modal and pass a parameter to the modal component in order to customize its content. However, when using the open() function of Modal, we only need to provide ...

The navigation bar is malfunctioning on Bootstrap 4.0.0-beta.2 framework

I have recently updated to the latest version of Bootstrap: "@ng-bootstrap/ng-bootstrap": "^1.0.0-beta.5", "bootstrap": "^4.0.0-beta.2", "core-js": "^2.4.1", "jquery": "^3.2.1", "popper.js": "^1.12.9", As part of this update, I incorporated a navbar: &l ...

Getting the present location on Google Maps for the web: A step-by-step guide

As a newcomer to this API, I have successfully generated an API key but am unsure of how to implement Google Maps. Despite my extensive research, I have been unable to find a solution that works for me. I am seeking assistance in locating users or devices ...

"The PHP script was executed despite having a MIME type of "text/html", which is not an appropriate JavaScript MIME type" error

I'm encountering an issue while trying to add data to an Oracle database using PHP from a Bootstrap form. When attempting to run the HTML file in Mozilla Firefox, the following error is displayed: The script from “http://localhost/CustomerPartInAs ...

Turn off scroll bar to create a seamless browsing experience on your website

As I work on creating the frontend for a single-page website with seamless scrolling between divs, I'm looking to eliminate mouse scrolling altogether. I understand that using overflow:hidden; can hide scroll bars, but my goal is to make the page scr ...

Centering spans and divs is proving to be a challenge, as well as getting the margin-top and margin-bottom properties to function properly

I encounter this issue frequently, where my usual methods for centering objects do not seem to work. I am in search of a universal way to accomplish this task: <div> <span>content</span> <span> content</span> < ...

What is causing the animate callback to not properly wait for the completion of the animations?

Both animations are triggered simultaneously (sometimes even multiple times).... <div id="home-bt" class="button"></div> <div id="about-bt" class="button"></div> <div id="beauty-bt" class="button"></div> <div id="pam ...

What is the best way to ensure that my header remains responsive across all devices and screen sizes?

The header is not responding despite inputting width: 100%. How can I ensure that the header is responsive on all browsers, as well as iPads and phones? .head-wrap { background: url(http://envisionmediallc.com/prodigy/wp-content/uploads/2014/02/We-are-p ...

Clicking the button to send the form using JavaScript

Currently, I am dealing with a shopping cart plugin that relies on a basic form on the product page to send values such as price and product name. However, I am facing an issue where this plugin uses a standard submit button to transmit the values, and I w ...

What could be causing my footer to appear anywhere but the bottom of the page?

I have been struggling to position the footer of my webpage at the bottom, but it seems to be stuck in the middle. Despite watching tutorial videos and attempting to follow along, I haven't been able to resolve this issue. Admittedly, my code is a b ...

Is it possible for asp.net to include <tbody id="blah" runat="server">?

Currently, I am dealing with a situation where I need to hide a <table> <tbody>..some content</tbody> <tbody id="sometimesHidden" runat="server">...</tbody> </table> Despite my efforts, the .cs code throws an ...

The issue of ngx-bootstrap tabs persisting even after removal

I have implemented a method that resembles what can be seen on the demo site My objective is to display tabs for each record, with some records having just one tab and others having multiple tabs. While it seems like the correct number of tabs is being di ...

What steps should I take to create a submenu?

Visit this website for more information. Looking to add a new submenu in the Services section under Office 365 Consulting, we have completed the backend work and now need to style it using CSS to resemble a submenu. Attempts at giving padding or margin res ...

Modify the NAME attribute when clicked using Jquery

I am attempting to modify the NAME attribute of a DIV with the text from a textbox using jQuery. Take a look at my code snippet: http://jsfiddle.net/e6kCH/ Can anyone help me troubleshoot this issue? ...