繁体   English   中英

JS的Alert Box是否有HTML5替代品?

[英]Is there a HTML5 alternative to JS's Alert Box?

JS的Alert Box是否有纯HTML5 替代品 我从来没有涉足JS或其他脚本/代码,我只对HTML5和CSS3感到满意,(我真的很喜欢语义:))

如果不是,不用担心,比需要更好奇。

谢谢! 枷锁

HTML5是一个平台和品牌。 它包括许多JavaScript API,CSS3模块等。尝试使用:target CSS3 例如 alert。 它使用CSS3的顶级功能。

笔代码:

HTML

<div class="wrap">
  <h1>Modal - Pure CSS (no Javascript)</h1>
  <p>Example of modal in CSS only, here I use the pseudo selector ":target" and no javascript for modal action.</p>
  <p>This works in IE9+ and all modern browsers.</p>
  <p>View <a href="http://www.felipefialho.com/css-components/">Pure CSS Components</a> project.</p>
  <hr />
  <a href="#modal-one" class="btn btn-big">Modal!</a>
</div>

<!-- Modal -->
<div class="modal" id="modal-one" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-header">
      <h2>Modal in CSS?</h2>
      <a href="#" class="btn-close" aria-hidden="true">×</a>
    </div>
    <div class="modal-body">
      <p>One modal example here! :D</p>
    </div>
    <div class="modal-footer">
      <a href="#" class="btn">Nice!</a>
    </div>
  </div>
</div>
<!-- /Modal -->

CSS

body {
  color: #333333;
  font-family: 'Helvetica', arial;
}
.wrap {
  padding: 40px;
  text-align: center;
}
hr {
  clear: both;
  margin-top: 40px;
  margin-bottom: 40px;
  border: 0;
  border-top: 1px solid #aaaaaa;
}
h1 {
  font-size: 30px;
  margin-bottom: 40px;
}
p {
  margin-bottom: 20px;
}
.btn {
  background: #428bca;
  border: #357ebd solid 1px;
  border-radius: 3px;
  color: #fff;
  display: inline-block;
  font-size: 14px;
  padding: 8px 15px;
  text-decoration: none;
  text-align: center;
  min-width: 60px;
  position: relative;
  transition: color .1s ease;
}
.btn:hover {
  background: #357ebd;
}
.btn.btn-big {
  font-size: 18px;
  padding: 15px 20px;
  min-width: 100px;
}
.btn-close {
  color: #aaaaaa;
  font-size: 30px;
  text-decoration: none;
  position: absolute;
  right: 5px;
  top: 0;
}
.btn-close:hover {
  color: #919191;
}
.modal:before {
  content: "";
  display: none;
  background: rgba(0, 0, 0, 0.6);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
}
.modal:target:before {
  display: block;
}
.modal:target .modal-dialog {
  -webkit-transform: translate(0, 0);
  -ms-transform: translate(0, 0);
  transform: translate(0, 0);
  top: 20%;
}
.modal-dialog {
  background: #fefefe;
  border: #333333 solid 1px;
  border-radius: 5px;
  margin-left: -200px;
  position: fixed;
  left: 50%;
  top: -100%;
  z-index: 11;
  width: 360px;
  -webkit-transform: translate(0, -500%);
  -ms-transform: translate(0, -500%);
  transform: translate(0, -500%);
  -webkit-transition: -webkit-transform 0.3s ease-out;
  -moz-transition: -moz-transform 0.3s ease-out;
  -o-transition: -o-transform 0.3s ease-out;
  transition: transform 0.3s ease-out;
}
.modal-body {
  padding: 20px;
}
.modal-header,
.modal-footer {
  padding: 10px 20px;
}
.modal-header {
  border-bottom: #eeeeee solid 1px;
}
.modal-header h2 {
  font-size: 20px;
}
.modal-footer {
  border-top: #eeeeee solid 1px;
  text-align: right;
}

编辑:

Chrome Canary 37+具有dialog元素。 代码示例中的更多信息。 它的主要利润是showcloseshowModal方法以及::backdrop css选择器。

不,没有办法显示不使用任何JavaScript的弹出窗口(至少,没有什么是实用的)。 这是因为您需要某种代码来管理弹出窗口的消息,甚至是要显示弹出窗口。

仅CSS示例依赖于用户单击要显示的弹出窗口的内容。

你可以看一下jQueryUI的模态 但这是html / css / js的组合

如果您不想使用alert() ,最好的选择是从头开始编写一个。 有很多库可以为你做,环顾四周,你会找到至少一个。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM