What steps can I take to design a personalized button using Bootstrap?

I recently developed a fresh ASP.Net Core 5 application with Bootstrap integrated. My goal is to design a replica of the btn-primary button but in a different color without altering btn-primary itself.

Upon inspecting, I noticed that bootstrap.min.css and bootstrap.bundle.min.js are being brought in.

How can I correctly craft a new button and include it in the project build?

Answer №1

Instead of just using CSS, consider exploring other options like SASS or creating a customized version of btn-default

To customize, simply add an additional class modifier like mybtn

.mybtn{
        background-color: pink!important;
        
}
.mybtn:hover{ background-color: #fa7aa0!important; color: white!important;}
.mybtn:active{
    background-color: #E75480!important;
    color: white!important;
        
}
<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
 
</head>
<body>

<div class="container">
  <button type="button" class="btn btn-default mybtn">Custom BTN</button>
</div>

</body>
</html>

Answer №2

To customize the color of a button in Bootstrap, simply add a new class after the btn-primary class. For example:

<button type="submit" class="btn-primary red_button">Submit</button>

Next, create a new stylesheet with styling for the newly created class like this:

.red-button {
    background-color: red;
}

Be sure to write your own custom class and include it after the bootstrap class definition.

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

Execute the code only if the variable is not null

I encountered an issue with my code: setInterval(function() { $.ajax({ url: url, success: function(data, count){ var obj = jQuery.parseJSON(data); var content = obj.results[0].content; }}) }, 2000) The code runs every 2 seconds an ...

How can you create a sticky navigation bar specifically designed for horizontal scrolling on a website?

I am facing a challenge with a large table that extends beyond the screen, requiring both horizontal and vertical scrolling. My goal is to create a sticky navbar that remains at the top when I scroll horizontally, but hides when I scroll vertically, only t ...

How to include an image in a CSS file for a React project

I'm attempting to use an image from public/assets/subtract.png, but I am encountering a resolution issue. Here is the code snippet in question: body { background-image: url("./assets/subtract.png"); } The specific problem I am facing is ...

Having difficulty retrieving the PDF through a jQuery AJAX request

I am currently utilizing the FPDF library to generate PDF files. I have been successful in generating the PDF file through a hyperlink, but I am facing difficulties when trying to do the same on button click. Below is the code snippet: createReport.php ...

Tips for customizing the appearance of the "Read More" button on an Elementor card

I'm new to the world of wordpress and I'm struggling to customize the CSS for a button on a card. My goal is to center the "Read more" button on the post card and give it a border, but I'm not having any luck in Elementor. I tried tweaking t ...

What is the best way to merge my ajax request into a single line of code?

My AJAX data looping process is successful, however, when I console log, the data appears on a new line. How can I fix this? $.ajax(settings).done(function(response) { $.get(settings).then(data => makeTable(data.contracts)) const makeTable = (contra ...

Ways to customize pixel scrolling on page reload or through the use of a hyperlink to a specific tab in a page

I have implemented a Bootstrap panel using the following code: <ul class="nav nav-tabs" role="tablist"> <li class="nav-item"> <a class="nav-link active" data-toggle="tab&qu ...

Issue with custom font not appearing correctly within SVG pattern background image

I am currently utilizing an SVG design featuring a unique font in order to apply that design as a background image on an HTML page. While everything displays correctly in Chrome and Safari, Firefox seems to be giving me some trouble: Firefox properly re ...

Ways to align list items in the middle of a webpage with CSS

Currently, I am working on a website and looking to create a customized list where the pictures act as clickable links. You can check out the website here. My goal is to have the links adjust to align left based on the browser size, and also have the imag ...

Having difficulty generating a footer for a page that includes a Material-UI Drawer component

Looking to create a standard full-width footer at the bottom of my page, I need help with the implementation. Utilizing the "Permanent drawer" from Material-UI Drawer for reference here. If you're interested in experimenting with it, CodeSandbox link ...

When the document is fully loaded and processed, a script will be executed immediately following

I'm facing an issue with a modal plugin on my website. The plugin is triggered on $(document).ready, but I have another function (innerHTML) that inserts an <a> element 5-10 seconds after the page loads. This causes the modal not to work properl ...

What is the best way to store textarea information into a session using the jQuery AJAX post method in Codeigniter?

I am having trouble saving the text from a textarea to the Controller session using jQuery AJAX post method in Codeigniter Smarty. I am unable to save the data to the session. Can someone please provide me with guidance and a detailed example of how to ach ...

Incorporating Fontello spinner icons into CSS styling

Currently, I have a background image set in the CSS and I am looking to replace it with a Fontello spinner image class. How can I achieve this? #divOverLay.show { background-color: rgba(0, 0, 0, 0.0); background-image: url('../images/spinner_ ...

A guide on leveraging the each() method for looping through a JSON document

I am hoping to display elements sourced from a JSON file. Here is the JSON data "2015": { "img": "<img src = \"../images/images/images_of_members/image1.jpg\">", "img2": "<img src = \"../images/images/images_of_members/image2.jpg& ...

Making jQuery / Javascript delay until the php script has fully loaded

I am encountering an issue with an ajax request that needs to wait for a PHP script to load. The code works fine in Chrome but not in IE, where the alert box displays too quickly and the script does not run at all. Upon pressing a button, the script shoul ...

Transmit a combination of selection and text inputs through AJAX to PHP, and then save the data in a

Is it possible to send multiple inputs (one text and one select multiple) via AJAX to a PHP file? The data is successfully sent using form serialize, as evidenced by the complete array in prod_multi when logging with console.log. However, I am facing an is ...

Update the content on the webpage to display the SQL data generated by selecting options from various dropdown

My database table is structured like this: Name │ Favorite Color │ Age │ Pet ────────┼────────────────┼───────┼─────── Rupert │ Green │ 21 │ ...

What is the best method to choose the initial offspring of the primary brother or sister within a list item?

Is there a way to specifically target the nested li elements in my css selector? Check out the Demo li:first-child { background-color: rgb(236, 236, 236); list-style-type: none; margin-bottom: 3px; padding: 8px; } <ul> <li& ...

What is the best way to add an image within a div without affecting the layout of the subsequent div?

I have created an HTML form with 4 inputs and a text area using bootstrap. I am looking to add an image to the right of two divs without pushing one of them down. I want it to look like the first image attached, but currently, it looks like the second ima ...

Images not showing in Vue.js

I have been working on setting up a carousel using bootstrap-vue. It is being generated dynamically through an array containing three objects with keys such as id, caption, text, and image path. The issue I am facing now is that while the caption and text ...