HTML code
This is the html code used to create this bootstrap snippet, You can copy and paste the following html code inside a page with bootstrap 5.1.3 included, to get the result that you can see in the preview selection
Download<!DOCTYPE html>
<html lang="pt-br" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
</head>
<body>
<!-- created by @BrCodeSnippets -->
<div class="container mt-3 pt-3">
<div id="div_buttons" class="row g-3 m-0 p-0">
</div>
</div>
<!-- modal element -->
<div id="my_modal" class="modal shadow rounded" tabindex="-1">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div id="modal_header" class="modal-header">
<h5 id="modal_title" class="modal-title">Modal title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div id="modal_body" class="modal-body">
<p>Modal body text goes here.</p>
</div>
<div id="modal_footer" class="modal-footer">
footer do modal
<button data-action="0" type="button" class=" ms-3 btn btn-secondary" data-bs-dismiss="modal">Fechar</button>
</div>
</div>
</div>
</div>
</body>
</html>
CSS code
This is the css code used to create this bootstrap snippet, You can copy and paste the following css code inside a page with bootstrap 5.1.3 included, to get the result that you can see in the preview selection
Downloadbody{margin-top:20px;}
Javascript/Jquery code
This is the javascript code used to create this bootstrap snippet, You can copy and paste the following javascript code inside a page with bootstrap 5.1.3 included, to get the result that you can see in the preview selection
Download var myModalEl = domElementId('my_modal');
var myModal = new bootstrap.Modal(myModalEl, {});
var element = domElementId('modal_header'); //myModalEl.getElementsByClassName('modal-content')[0];
var elementModalTitle = domElementId('modal_title');
var divButtons = domElementId('div_buttons');
var modalFooter = domElementId('modal_footer');
var objColors = colors();
// Quando fechar
eventModal('hidden.bs.modal', function(data) {
});
// Quando abrir
eventModal('show.bs.modal', function(data) {
});
function eventModal(event, cb) {
myModalEl.addEventListener(event, function(event) {
cb(event);
});
}
function domElementId(id) {
return document.getElementById(id)
}
function createStyle() {
let style = document.createElement('style');
style.type = 'text/css';
style.innerText = '.cssClass { color: #F00; }';
document.getElementsByTagName('head')[0].appendChild(style);
}
function render() {
let classHtml = '';
let style = document.createElement('style');
style.type = 'text/css';
Object.keys(objColors).forEach(function(key, i) {
//let colorRGBA = item.code.rgba.join(',');
let bg = 'class' + i + '';
let divCol = document.createElement('div');
divCol.className = 'col-6 col-sm-4 col-lg-3 col-xxl-2';
// criando as classes CSS
classHtml += '.class' + i + ' { color: #000;filter: invert(200%); background-color: ' + key + '; }';
let a = document.createElement('a');
a.href = 'javascript:void(0);';
a.setAttribute('data-css', bg);
a.innerHTML = objColors[key] +' ' + key;
a.className = 'btn text-center w-100 h-100 border-0 p-5 ' + 'class' + i + '';
divCol.appendChild(a);
divButtons.appendChild(divCol);
a.addEventListener('click', function() {
element.className = 'modal-header bg-gradient';//'modal-content';
modalFooter.className = 'modal-footer bg-gradient';
console.log(this);
elementModalTitle.innerHTML = 'Teste com a cor: '+ objColors[key] ;
element.classList.add(bg);
modalFooter.classList.add(bg);
myModal.show();
}, false);
});
style.innerText = classHtml;
// adiciona as classes CSS criadas no documento
document.getElementsByTagName('head')[0].appendChild(style);
}
render();
function colors() {
return {
"#4c4f56": "Abbey",
"#0048ba": "Absolute Zero",
"#1b1404": "Acadia",
"#7cb0a1": "Acapulco",
"#b0bf1a": "Acid Green",
"#7cb9e8": "Aero",
"#c9ffe5": "Aero Blue",
"#714693": "Affair",
"#b284be": "African Violet",
"#00308f": "Air Force Blue",
"#72a0c1": "Air Superiority Blue",
"#d4c4a8": "Akaroa",
"#af002a": "Alabama Crimson",
"#fafafa": "Alabaster",
"#f5e9d3": "Albescent White",
"#93dfb8": "Algae Green",
"#f0f8ff": "Alice Blue",
"#84de02": "Alien Armpit",
"#e32636": "Alizarin Crimson",
"#c46210": "Alloy Orange"
}
}

About this bootstrap example/template
This example/template, Custom modal, was published on Aug 18th 2022, 17:50 by Gilberto Martins Goncalves and it is free.
We hope you will enjoy this awesome snippet and stay tuned for the latest updates, bootdey snippets are already used in thousands of blogs, websites and projects. We believe it will save your precious time and gives trendy look to your next web project.
We always try to offer the best beautiful and responsive source of Bootstrap code examples and components.
This code example currectly have 261 views, Using this bootstrap snippet you have the following benefits:
Bootstrap 5.1.3
<link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css'>
<script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js'></script>
This code example is based on bootstrap 5.1.3 and the grid system of this framework
Responsive
Based on bootstrap framework makes all the layouts perfectly responsive for all devices
Crossbrowser compatibility
Tested on all major browsers, it works smoothly on all of them
Jquery plugins
Great built-in plugins with jquery framework, you can easy to change all declarations
semantic html 5
Built on html / css3 the code quality is really amazing
Simple Integration
This code example can be simply integrated on existing sites and new ones too, all you need to do is copy the code and start working