0

I'm trying to include only the modal bs4/5 component whitin a simple html page. I don't want to include the whole library cause it breaks my original css template. I've seen that there exists a BS3 Customize builder but just for versions 3.4.1 and ealier.

The problem with the link shared is that the 3.4.1 bootstrap modal version doesn't look as nice as the newer (BS4 or further). For instance, as the image shows, the 'x' buton isn't properly vertically aligned and the button style isn't so fashion.

BS3 modal

Against BS4/5 modal version

BS4 modal

Is there a way to achieve that? To only get BS4 or BS5 modal component to be imported into a simple html landing page? Avoiding conflicts with others css files?

For exporting just the 3.4.1 bootstrap modal version I've followed this well explained link.

Thanks!

4aLifeTime
  • 117
  • 9

1 Answers1

0

You've got the extract the CSS classes you want. (and the JS functions that triggers the behaviour you expect but as you wrote only about css, i will not demonstrate a working JS show/hide)

According to the first example in Bootstrap's Modal documentation page :

Here are the needed selectors used on the simple modal :

  • .modal
  • .modal-dialog
  • .modal-content
  • .modal-header
  • .modal-title
  • .modal-body
  • .modal-footer
  • .btn
  • .btn-close
  • .btn-primary
  • .btn-secondary
  • h5

Here is a working CodePen, with custom Google Font

You can see the HTML used here :

<div class="modal" tabindex="-1">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">Modal title</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <p>Modal body text goes here.</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

And CSS classes :

@import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@400&display=swap');

* {
    font-family: 'Open Sans', sans-serif;
    font-size: Arem;
}

h5 {
    font-size: 1.25rem;
    margin-top: 0;
    font-weight: 500;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1055;
    /*display: none;*/
    /* by default modals are hidden as they are meant to be triggered */
    width: 100%;
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    outline: 0;
}

.modal-dialog {
    max-width: 500px;
    margin: 1.75rem auto;
    position: relative;
    margin: 0.5rem;
    pointer-events: none;
}

.modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    pointer-events: auto;
    background-color: #fff;
    background-clip: padding-box;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 0.3rem;
    outline: 0;
}

.modal-header {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1rem;
    border-bottom: 1px solid #dee2e6;
    border-top-left-radius: calc(0.3rem - 1px);
    border-top-right-radius: calc(0.3rem - 1px);
}

.modal-header .btn-close {
    padding: 0.5rem 0.5rem;
    margin: -0.5rem -0.5rem -0.5rem auto;
}

.modal-title {
    margin-bottom: 0;
    line-height: 1.5;
}

.modal-body {
    position: relative;
    flex: 1 1 auto;
    padding: 1rem;
}

.modal-footer {
    display: flex;
    flex-wrap: wrap;
    flex-shrink: 0;
    align-items: center;
    justify-content: flex-end;
    padding: 0.75rem;
    border-top: 1px solid #dee2e6;
    border-bottom-right-radius: calc(0.3rem - 1px);
    border-bottom-left-radius: calc(0.3rem - 1px);
}

.modal-footer>* {
    margin: 0.25rem;
}

.btn {
    display: inline-block;
    font-weight: 400;
    line-height: 1.5;
    color: #212529;
    text-align: center;
    text-decoration: none;
    vertical-align: middle;
    cursor: pointer;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
    background-color: transparent;
    border: 1px solid transparent;
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    border-radius: 0.25rem;
    transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.btn:hover {
    color: #212529;
}

.btn-check:focus+.btn,
.btn:focus {
    outline: 0;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

.btn:disabled,
.btn.disabled,
fieldset:disabled .btn {
    pointer-events: none;
    opacity: 0.65;
}

.btn-primary {
    color: #fff;
    background-color: #0d6efd;
    border-color: #0d6efd;
}

.btn-primary:hover {
    color: #fff;
    background-color: #0b5ed7;
    border-color: #0a58ca;
}

.btn-check:focus+.btn-primary,
.btn-primary:focus {
    color: #fff;
    background-color: #0b5ed7;
    border-color: #0a58ca;
    box-shadow: 0 0 0 0.25rem rgba(49, 132, 253, 0.5);
}

.btn-check:checked+.btn-primary,
.btn-check:active+.btn-primary,
.btn-primary:active,
.btn-primary.active,
.show>.btn-primary.dropdown-toggle {
    color: #fff;
    background-color: #0a58ca;
    border-color: #0a53be;
}

.btn-check:checked+.btn-primary:focus,
.btn-check:active+.btn-primary:focus,
.btn-primary:active:focus,
.btn-primary.active:focus,
.show>.btn-primary.dropdown-toggle:focus {
    box-shadow: 0 0 0 0.25rem rgba(49, 132, 253, 0.5);
}

.btn-primary:disabled,
.btn-primary.disabled {
    color: #fff;
    background-color: #0d6efd;
    border-color: #0d6efd;
}

.btn-secondary {
    color: #fff;
    background-color: #6c757d;
    border-color: #6c757d;
}

.btn-secondary:hover {
    color: #fff;
    background-color: #5c636a;
    border-color: #565e64;
}

.btn-check:focus+.btn-secondary,
.btn-secondary:focus {
    color: #fff;
    background-color: #5c636a;
    border-color: #565e64;
    box-shadow: 0 0 0 0.25rem rgba(130, 138, 145, 0.5);
}

.btn-check:checked+.btn-secondary,
.btn-check:active+.btn-secondary,
.btn-secondary:active,
.btn-secondary.active,
.show>.btn-secondary.dropdown-toggle {
    color: #fff;
    background-color: #565e64;
    border-color: #51585e;
}

.btn-check:checked+.btn-secondary:focus,
.btn-check:active+.btn-secondary:focus,
.btn-secondary:active:focus,
.btn-secondary.active:focus,
.show>.btn-secondary.dropdown-toggle:focus {
    box-shadow: 0 0 0 0.25rem rgba(130, 138, 145, 0.5);
}

.btn-secondary:disabled,
.btn-secondary.disabled {
    color: #fff;
    background-color: #6c757d;
    border-color: #6c757d;
}

.btn-close {
    box-sizing: content-box;
    width: 1em;
    height: 1em;
    padding: 0.25em 0.25em;
    color: #000;
    background: transparent url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23000'%3e%3cpath d='M.293.293a1 1 0 011.414 0L8 6.586 14.293.293a1 1 0 111.414 1.414L9.414 8l6.293 6.293a1 1 0 01-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 01-1.414-1.414L6.586 8 .293 1.707a1 1 0 010-1.414z'/%3e%3c/svg%3e") center/1em auto no-repeat;
    border: 0;
    border-radius: 0.25rem;
    opacity: 0.5;
}

.btn-close:hover {
    color: #000;
    text-decoration: none;
    opacity: 0.75;
}

.btn-close:focus {
    outline: 0;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
    opacity: 1;
}

.btn-close:disabled,
.btn-close.disabled {
    pointer-events: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
    opacity: 0.25;
}
z4nzi
  • 71
  • 1
  • 2
  • 7
  • Thanks @z4nzi! The problem there is that i also want the transitions efects everytime the modal is shown/hidden. I've been trying with theming and importing only the necessesary modules (modal, buttons, transitions, utilities) but doesn't work properly. Mainly if I add transitions, never shows up. – 4aLifeTime Oct 27 '21 at 12:02
  • I'd suggest using jquery show/hide with a fade effect then, is jQuery a library you can add or will it break content ? – z4nzi Oct 27 '21 at 12:13
  • Here is an example how it behaves: [example](https://codepen.io/4aLifeTime/pen/abyWxPO). No transition when shows up! – 4aLifeTime Oct 27 '21 at 12:23
  • Add the .fade and .fade.in and you're good to go ;) (see your work with those two classes : https://codepen.io/hotlinedelite/pen/porwvXY) – z4nzi Oct 27 '21 at 16:06
  • Maybe I wasn't clear. I want to achieve the same effects and style as [bootstrap 4 modal examples](https://getbootstrap.com/docs/4.0/components/modal/). Modal showing from top, separately from top. Like [this example](https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_modal&stacked=h). Without including all BS4 components. – 4aLifeTime Oct 27 '21 at 17:12
  • The classes used are `.fade` `.fade.in` and `.show` (showing from top) – z4nzi Oct 27 '21 at 18:02