Preserve the button interface when it is clicked

Just diving into the world of CSS for the first time with a front end styling task, so apologies in advance for any errors or misunderstandings!

I have a placeholder button that triggers a Modal (1):

https://i.sstatic.net/1wT9Y.png

When clicked, the button transforms like this when the Modal appears (2):

https://i.sstatic.net/7OIIy.png

You'll notice a border on the button once it's clicked, giving the impression it's being held down. However, if I click anywhere else on the screen while the Modal is open, the button reverts to this state (3):

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

In simple terms, this is how the button component is structured:

<button className={`btn position-relative  ${className}`} onClick={onClick}>
...
</button>

The component responsible for triggering the Modal contains this snippet of code:

<Button onClick={() => setModal(true)} className={'btn btn-primary mr-2'}>
  (info icon)
</Button>

Any ideas on how to maintain the button appearance from (1) to (3), and skip the transition seen in (2)?

Answer №1

By default, Bootstrap adds a blueish box-shadow to buttons when they are clicked, as defined in its partial SCSS file _buttons.scss.

To override this style, you need to create a more specific selector in your own stylesheet. Simply using .btn:focus { } will not be enough. In the example below, I have included the tag name as well: button.btn:focus {}

button.btn:focus {
  box-shadow: none;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<button class="btn">Button</button>

P.S. You can use the dev tools in modern browsers to inspect styles applied to different states (hover, focus, active) on any element.

Answer №2

Give this a shot ______________________________________________________

.btn-primary:focus{
  outline: none !important;
  box-shadow: none !important;
}
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="40222f2f34333432213000756e716e71">[email protected]</a>/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f2909d9d868186809382b2c7dcc3dcc3">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>

<button type="button" class="btn btn-primary">Save changes</button>

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's the connection between CSS and frameset?

Currently, I have an .html document with XHTML 1.0 Frameset doctype and the following code: <frameset rows="20%, 80%" border="1"> ... </frameset> Upon validating this code on W3C Validator, it gives me the error message: there is no a ...

Determine the difference between a CSS selector string and an XPath string

Developing a compact querying module (using js) for html is my current project, and I aim to create a versatile query(selector) function that can handle both css selectors and XPath selectors in string form. My dilemma lies in determining whether a given ...

Difficulty in breaking text within flexbox styling

I'm facing an issue where the text inside a flex container does not break correctly when the horizontal space is too small to display it all. But shouldn't it still not break even in the "normal" state? What mistake have I made here? (functio ...

Looking for a solution to organize the dynamically generated list items in an HTML page

I am currently working on a movie listing website where all the movies are displayed in sequence based on their #TITLE#. The webpage is generated automatically by the software using a template file. Here is the section of code in the template file that sho ...

Bootstrap does not conform to standard image sizing conventions

Why is the sizing property of Bootstrap not applying to images when using h-100? When I try to style them inline, everything works as expected, but setting it as h-100 doesn't work for the images. Can someone please explain this issue? <div id=" ...

Drag a dropdown menu to the bottom left corner and set it to full width on mobile using CSS

Check out this code snippet with CSS and HTML: CSS .flyout { position: absolute; top: 30px; right: 15px; background-color: #FFF; padding: 20px; border: 1px solid #eaeaea; z-index: 999; width: 400px; border-top: 3px solid #337AB7; disp ...

Looking for straightforward tips on parsing CSS code

Seeking advice on how to extract rules and property/values from a .css file or <style></style>. I am not in need of an elaborate parser, as the validity of selector text, property name, or value is not important. My main focus is ensuring that ...

Is it possible to replicate a slow image loading experience in React.js?

Referenced the solution below How to simulate slow loading of image Slowing down internet connection with Chrome DevTools works, but the entire site loads slowly. I want to specifically focus on slowing down the image reloading. One of the suggestions w ...

Having trouble adding Bootstrap to Angular with Webpack? You might come across the error message: "File to import not found or unreadable: ../bootstrap/sc

I have decided to incorporate Bootstrap into my project. My attempt at installation involved using "bootstrap": "^4.0.0-alpha.5" I followed a tutorial found at https://github.com/AngularClass/angular2-webpack-starter/wiki/How-to-use-Bootstrap-4-and-Sass- ...

How can I prevent the content from sliding out of view in a Bootstrap carousel?

I am looking to create a slider that includes a form or text. However, I have noticed that when scaling up by 50-75% or when there is a lot of content, the content extends beyond the slider. Image Check out my code on jsfiddle: jsfiddle.net/sL70r2an/ ...

Content and visual side by side

My logo and header image are giving me trouble. Whenever I attempt to center the header image, it keeps moving to the next row. How can I make sure it stays on the same row? Check out our website Thank you ...

Adjust the dimensions of the icon

My current project involves creating a sidebar with icons and associated text to represent each icon. However, I encountered an issue while trying to adjust the size of the icons within the sidebar using the "useStyles()" method. For some reason, the size ...

Scaling down a retina image sprite using CSS: A step-by-step guide

Struggling with loading retina images? You're not alone. Many web developers face the challenge of scaling down high-resolution images effectively. Take, for example, two image sprites: one normal and one retina. The issue arises when you need to adju ...

Trouble with Bootstrap 5 Padding Distorting the Aspect Ratio of Image Collection

I am struggling to manage three images in a layout where they span one row and two columns (please refer to the image). While I can make it look perfect at one screen resolution, the ratio of the images becomes distorted when viewed in other screen sizes d ...

The footer seems to be malfunctioning

Let's start with the code: CSS: *{ margin:0; padding:0; } body,html{ height:100%; } body{ background:url('../images/bg.png'); background-position:center; background-repeat:no-repeat; background-attachment:fixed; height:100%; ...

Date Selector Tool for Input Field

Does anyone know how to change the color of the date picker that appears in certain browsers but is unsure about the selector's name? HTML: <form action="pledge.html" method="post"> <input type="date" id="birthday" name="user_bda ...

What steps do I need to take to develop a feature similar to Tabzilla?

Exploring the innovative navigation bar on Mozilla.org seems intriguing; commonly referred to as tabzilla, it smoothly moves down to reveal the menu at the top of the page. I wonder if there are any existing libraries or ready-made jQuery code snippets tha ...

Arrangement of Columns in a Vertical Bootstrap Layout

When the xs layout displays as expected, how can I move the sidebar up to the navigation in order to eliminate the gap between them in the lg layout? <div class="row"> <div class="col-xs-12 col-lg-3 col-lg-push-9"> navigation & ...

"Transitioning from Bootstrap version 3.3.7 to the latest Bootstrap version 4.1.3

Everywhere I look, it says that Bootstrap 4.1 is compatible with Bootstrap 3, but when I update my project to the newer version, a lot of things stop working, such as this cookie consent feature. @{ Layout = ""; } @using Microsoft.AspNetCore.Http ...

Enhance the appearance of the circular heading

Is there anyway to customize the look of this rounded header? I am having trouble setting a white background. Update #1: This is my current header HTML code: Here is how it currently appears: I utilized Bootstrap along with some custom CSS. Update #2: ...