javascript - 将信息框居中并拉伸(stretch)所有内容以适应任何屏幕?

标签 javascript css html

我们如何制作居中并拉伸(stretch)以适合任何屏幕的信息框?

最佳答案

check JsFiddle Here

function toggle_login() {
    var div = document.getElementById('infobg');
    div.style.display = div.style.display == 'none' ? 'block' : 'none';
    return false;
}
#bgfr {
  position: fixed;
  width: 100%;
  height: 100%;
  z-index:-10;
}
#infobg {
  position: fixed;
  background: rgba(0, 0, 0, 0.75);
  width: 100%;
  height: 100%;
  z-index:20;
}
#mcenter {
  position: fixed;
  background: black;
  color: lime;
  font-size: 4vw;
  width: 40vw;
  height: 10vw;
  padding: 2vw 2vw 5vw 2vw;
  left: 50%;
  top: 50%;
  border-radius: 10px;
  transform: translate(-50%, -50%);
}

#mcenter p {
  text-align: center;
}

#closeo {
  background:url('http://1.bp.blogspot.com/-hu1XPBgM5zc/VjT4spC8tOI/AAAAAAAAAHk/n9RsI39X9v4/s1600/1431064341362.png') no-repeat;
  background-size: 3vw;
  position: absolute;
  width: 4vw;
  height: 4vw;
  right: -5%;
  top: -5%;
  cursor: pointer;
}

#closeo:hover {
  background-size: 4vw;
  right: -4%;
  top: -8%;
}

#closeo:active {
  background-size: 3.5vw;
  right: -4.5%;
  top: -6%;
}
<iframe id="bgfr" src="http://www.w3schools.com/" border="0" width="100%" height="100%"></iframe>
<div id="infobg">
  <div id="mcenter">
    <span id="closeo" onclick="toggle_login()"></span>
    <p>Pakistan Zindabad</p>
  </div>
</div>

关于javascript - 将信息框居中并拉伸(stretch)所有内容以适应任何屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33454719/

相关文章:

php - 使用自定义模板引擎如何用 php 替换内容

javascript - ion-content 和 ion-footer 有不同的 $scope

css - 奇怪的呈现问题 IE11

html - 防止破坏负数

css - 纯 CSS : hide gif as preloading animation

html - css3自适应图像绝对位置

javascript - 当文本框在javascript中只读时,如何将键盘事件添加到文本框?

javascript - Flex 容器图像 slider 轮播

javascript - firebase上托管的node.js/express.js无法导出数据库和身份验证监听器

javascript - 为什么在 Backbone.js 中第二次渲染后事件没有触发?