gpt4 book ai didi

css - Bootstrap 4 模态未显示

转载 作者:太空宇宙 更新时间:2023-11-03 22:29:10 24 4
gpt4 key购买 nike

我有一个简单的设计,在居中的 div 中有一个图像。图像上方是一个带有 h1 元素的半透明文本框。我希望在单击 h1 后弹出一个 bootstrap 4 模态组件。我已经按照各种教程构建模态,但我似乎无法让它工作。我不确定可能是什么问题。

如果有人可以看一下并给我一些指导,将不胜感激。

代码笔:https://codepen.io/dayna-j/pen/RMZdej?editors=0010

HTML:

<head>
<link href="https://fonts.googleapis.com/css?family=Fredericka+the+Great" rel="stylesheet">
</head>
<body>

<div class='img-div'>
<img src="https://image.ibb.co/eZcdEn/nature_3084841_1920.jpg" alt='close up of grass'/>
<div class='textBox-div'>
<h1 class = no-select data-toggle="modal" data-target="#Modal">Click Me</h1>
</div>


<!-- Modal (inside img-div) -->
<div id="Modal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</body>

CSS:

.no-select {
user-select: none;
}

html {


box-sizing: border-box;
background-color: black;
// overflow:hidden;
}

*, *:before, *:after {
box-sizing: inherit;
}

* {
margin: 0;
padding: 0;
}

body{
background: #232526;
// background: papayawhip;
display: flex;
justify-content: center;
align-items: center;
// border: 5px solid green;
// border-radius: 1000px;
height: 100vh;
width: 100vw;
overflow: hidden;
}

.container-fluid {
position: relative;
height: 100%;
width: 100%;
}

.img-div {
position: relative;
display: flex;
justify-content: center;
align-items: center;
}

img {
// position: relative;
max-height: 500px;
max-width: 850px;
width: 100%;
border: 1px solid grey;
// border-radius: 1000px;
}

.textBox-div {
position: absolute;
margin: 0 auto;
text-align: center;
width: 100%;
background: whitesmoke;
opacity: .5;
}

.textBox-div h1 {
font-family: 'Fredericka the Great', cursive;
margin: auto 0;
font-weight: 900;
}

@media screen and (max-width:400px)
{
h1 {font-size: 1.5em;}
}

@media screen and (max-width:200px)
{
h1 {font-size: 1em;}
}

JavaScript:

$( document ).ready(function() {

$('#Modal').modal('hide');


$('h1').on('click', function(){
$('#Modal').modal('show');
});

});

最佳答案

代码有几个问题...

  • 您需要 popper.js,它不包含在 Codepen 中。
  • data-toggle="modal"$('#Modal').modal('show') 的 JS 代码相互抵消阻止模态显示
  • 在 CSS (html{}) 中使用 // 不是正确的注释。

使用 data-toggle="modal" $('#Modal').modal('show'),但不使用两者。

https://www.codeply.com/go/zcHpRWcMA5


链接到 popper.min.jsbootstrap.min.css替代方法是使用 bootstrap.bundle。 min.js 结合了两者..

CDN:https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.bundle.min.js

关于css - Bootstrap 4 模态未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49479829/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com