亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Div 本身工作得很好,但在合并到項目中時卻沒有

Div 本身工作得很好,但在合并到項目中時卻沒有

慕萊塢森 2022-12-22 14:28:04
我正在研究模態框。當我制作單獨的 html 和 css 文件來測試它時,它工作得很好。問題是當我將該代碼放入我正在處理的網頁的 html 和 css 中時,模態框沒有出現,唯一顯示的是模態容器的深色覆蓋。幫助將不勝感激。謝謝。僅模態const open = document.getElementById("open");const modalContainer = document.getElementById("modal-container");const close = document.getElementById("close");open.onclick = function() {  modalContainer.style.display = "block";};close.onclick = function() {  modalContainer.style.display = "none";};.modal-container {  background-color: rgba(0, 0, 0, 0.4);  position: fixed;  top: 0;  left: 0;  z-index: 1;  width: 100%;  height: 100%;  overflow: auto;  display: flex;  justify-content: center;  align-items: center;  font-family: fantasy;  display: none;}.modal {  background-color: whitesmoke;  width: 35%;  height: 90%;  margin: 5% auto;  padding: 20px 40px;  box-shadow: 5px 5px 5px gray;  border-radius: 10px;}.modal span {  display: flex;  justify-content: flex-end;  margin-right: -15px;  cursor: pointer;}<!DOCTYPE html><html><head>  <link rel="stylesheet" href="modal.css"></head><body>  <button id="open" onclick="openModal()">open modal</button>  <div class="modal-container" id="modal-container">    <div class="modal">      <span id="close">&times;</span>      <h1>Swimming Pools (Drank)</h1>      <hr>      <p>Pour up, drank, head shot, drank <br> Sit down, drank, stand up, drank <br> Pass out, drank, wake up, drank <br> Faded, drank, faded, drank</p>    </div>  </div></body></html>
查看完整描述

1 回答

?
白豬掌柜的

TA貢獻1893條經驗 獲得超10個贊

Boostrap StyleSheets 可能是造成這種情況的原因。BS 有一個原生的“模態”類,它可能會與您的自定義模態產生沖突。


嘗試將 BS cdn 添加到您的清晰示例中,這樣您就會知道這是否是問題所在:


<!DOCTYPE html>


<html>


<head>

  <link rel="stylesheet" href="modal.css">

  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">

</head>


<body>

  <button id="open" onclick="openModal()">open modal</button>


  <div class="modal-container" id="modal-container">

    <div class="modal">

      <span id="close">&times;</span>


      <h1>Swimming Pools (Drank)</h1>

      <hr>

      <p>Pour up, drank, head shot, drank <br> Sit down, drank, stand up, drank <br> Pass out, drank, wake up, drank <br> Faded, drank, faded, drank</p>

    </div>

  </div>

</body>


</html>

如果是問題所在,您可以將課程重命名為“模態”


CSS:


.custom-modal {

    background-color: whitesmoke;

    width: 35%;

    height: 90%;

    margin: 5% auto;

    padding: 20px 40px;

    box-shadow: 5px 5px 5px gray;

    border-radius: 10px;

}


.custom-modal span {

    display: flex;

    justify-content: flex-end;

    margin-right: -15px;

    cursor: pointer;

}

網址:


<div class="modal-container" id="modal-container">

     <div class="custom-modal">

     <span id="close">&times;</span>                

     <h1>Swimming Pools (Drank)</h1>

     <hr>

     <p>Pour up, drank, ...</p>

</div>


查看完整回答
反對 回復 2022-12-22
  • 1 回答
  • 0 關注
  • 102 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號