{"id":1898,"date":"2018-04-28T20:21:03","date_gmt":"2018-04-29T01:21:03","guid":{"rendered":"http:\/\/bluegalaxy.info\/codewalk\/?p=1898"},"modified":"2018-04-28T21:45:29","modified_gmt":"2018-04-29T02:45:29","slug":"html-css-set-bootstrap-3-modal","status":"publish","type":"post","link":"https:\/\/bluegalaxy.info\/codewalk\/2018\/04\/28\/html-css-set-bootstrap-3-modal\/","title":{"rendered":"HTML &#038; CSS: How to set up a Bootstrap 3 modal"},"content":{"rendered":"<p>In this article I will show how to set up a modal using Bootstrap 3. This example looks like this at 800px width:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1917\" src=\"http:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/04\/bootstrap3modal800.png\" alt=\"\" width=\"871\" height=\"445\" srcset=\"https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/04\/bootstrap3modal800.png 871w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/04\/bootstrap3modal800-300x153.png 300w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/04\/bootstrap3modal800-768x392.png 768w, https:\/\/bluegalaxy.info\/codewalk\/wp-content\/uploads\/2018\/04\/bootstrap3modal800-676x345.png 676w\" sizes=\"auto, (max-width: 871px) 100vw, 871px\" \/><\/p>\n<p>To set up a Bootstrap 3 modal, we will need these three resources:<\/p>\n<ol>\n<li>bootstrap.min.css<\/li>\n<li>bootstrap.min.js<\/li>\n<li>jquery.min.js<\/li>\n<\/ol>\n<p>These can be called via CDN at the top of our HTML file. For example:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\">&lt;link rel=\"stylesheet\" href=\"https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/3.3.7\/css\/bootstrap.min.css\"&gt;\r\n&lt;script src=\"https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/3.3.1\/jquery.min.js\"&gt;&lt;\/script&gt;\r\n&lt;script src=\"https:\/\/maxcdn.bootstrapcdn.com\/bootstrap\/3.3.7\/js\/bootstrap.min.js\"&gt;&lt;\/script&gt;<\/pre>\n<p>Here is the HTML for the modal. This block is not displayed unless the modal is triggered via click of an HREF link or button. All of the class names in this block are specific to Bootstrap 3 modal, except for any divs placed inside the modal body content in the middle of this block:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\">&lt;div class=\"modal fade\" id=\"myModal\" role=\"dialog\"&gt;\r\n  &lt;div class=\"modal-dialog modal-lg\"&gt;\r\n\t&lt;!-- Modal content--&gt;\r\n\t&lt;div class=\"modal-content\"&gt;\r\n\t  &lt;div class=\"modal-header\"&gt;\r\n          &lt;!-- modal header  --&gt;\r\n\t\t  &lt;button type=\"button\" class=\"close\" data-dismiss=\"modal\"&gt;&amp;times;&lt;\/button&gt;\r\n\t\t  &lt;h4 class=\"modal-title\"&gt;Bootstrap 3 Modal Header&lt;\/h4&gt;\r\n\t  &lt;\/div&gt;\r\n\t  &lt;div class=\"modal-body\"&gt;\r\n\t  &lt;!-- begin modal body content  --&gt;\r\n\t\t  &lt;section class=\"stage\"&gt;\r\n\t\t  &lt;figure class=\"ball\"&gt;&lt;span class=\"shadow\"&gt;&lt;\/span&gt;&lt;\/figure&gt;\r\n\t\t  &lt;\/section&gt;\r\n\t  &lt;!-- end modal body content  --&gt;\r\n\t  &lt;\/div&gt;\r\n\t  &lt;div class=\"modal-footer\"&gt;\r\n          &lt;!-- modal footer  --&gt;\r\n\t\t  &lt;center&gt;Bootstrap 3 Modal Footer&lt;\/center&gt;\r\n\t\t  &lt;button type=\"button\" class=\"btn btn-default\" data-dismiss=\"modal\"&gt;Close&lt;\/button&gt;\r\n\t  &lt;\/div&gt;\r\n       &lt;\/div&gt;\r\n   &lt;\/div&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>Here is the CSS that allows you to set the width of the modal, specifically <code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">min-width: 500px; <\/code><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"css\">\/* modal details *\/\r\n.modal-dialog{\r\n  position: relative;\r\n  display: table; \/* This is important *\/\r\n  width: auto;\r\n  min-width: 500px; \r\n  \/* overflow-y: scroll; *\/\r\n  overflow-x: auto;\r\n}<\/pre>\n<p>If you want to add a vertical scrollbar, this can be done by adding the following CSS:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"css\">\/* Vertical scroll bar part 1 *\/\r\n.modal-dialog{\r\n  overflow-y: initial !important;\r\n}\r\n\r\n\/* Vertical scroll bar part 2 *\/\r\n.modal-body{\r\n  max-height: 800px;\r\n  overflow-y: auto;\r\n}\r\n<\/pre>\n<p>Here is a demo of this modal on codepen which shows how to launch the modal via an HREF link and a button.<\/p>\n<p class='codepen'  data-height='500' data-theme-id='0' data-slug-hash='WJRQxX' data-default-tab='css,result' data-animations='run' data-editable='' data-embed-version='2'>\nSee the Pen Bootstrap 3 modal demo by Chris Nielsen (@Chris_Nielsen) on CodePen.<\/p>\n\n<p>&nbsp;<\/p>\n<p>For more information about setting up a Bootstrap 3 modal, see:<br \/>\n<a href=\"https:\/\/www.w3schools.com\/bootstrap\/bootstrap_modal.asp\">https:\/\/www.w3schools.com\/bootstrap\/bootstrap_modal.asp<\/a><\/p>\n<p>Bootstrap 4 modal instructions:<br \/>\n<a href=\"https:\/\/getbootstrap.com\/docs\/4.0\/components\/modal\/\">https:\/\/getbootstrap.com\/docs\/4.0\/components\/modal\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article I will show how to set up a modal using Bootstrap 3. This example looks like this at 800px width: To set up a Bootstrap 3 modal, we will need these three resources: bootstrap.min.css bootstrap.min.js jquery.min.js These can be called via CDN at the top of our HTML file. For example: &lt;link &hellip; <a href=\"https:\/\/bluegalaxy.info\/codewalk\/2018\/04\/28\/html-css-set-bootstrap-3-modal\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">HTML &#038; CSS: How to set up a Bootstrap 3 modal<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[104],"tags":[134,10,105],"class_list":["post-1898","post","type-post","status-publish","format-standard","hentry","category-html-css","tag-bootstrap-3","tag-css","tag-html"],"_links":{"self":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/1898","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/comments?post=1898"}],"version-history":[{"count":15,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/1898\/revisions"}],"predecessor-version":[{"id":1918,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/posts\/1898\/revisions\/1918"}],"wp:attachment":[{"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/media?parent=1898"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/categories?post=1898"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bluegalaxy.info\/codewalk\/wp-json\/wp\/v2\/tags?post=1898"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}