跳至内容
菜单
此问题已终结
1 回复
3869 查看

How do I set a condition to pop-up a block when we click a button using the HTML/CSS editor?

Thanks in advance.

形象
丢弃
最佳答案

Hi,

You can use the following code to raise a pop-up

HTML:

<button id="popupButton">Click Me</button>
<div id="popupBlock" class="hidden">
  <!-- Content of the popup goes here -->
  <p>This is the popup content.</p>
</div>




CSS:
#popupBlock {
  display: none; /* Initially hidden */
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 20px;
  background-color: #fff;
  border: 1px solid #ccc;
}

Javascript:

<script>
const popupButton = document.getElementById('popupButton');
const popupBlock = document.getElementById('popupBlock');

popupButton.addEventListener('click', function() {
popupBlock.classList.toggle('hidden');
  });
</script>




Hope it helps

形象
丢弃
相关帖文 回复 查看 活动
2
3月 15
3595
1
3月 20
13613
0
12月 19
2559
7
12月 24
25775
0
3月 15
4238