html - css 弹出窗口影响 html 布局

标签 html css css-position

我在点击时触发了 css 驱动的弹出窗口,我只是不希望它影响用户界面。

在下面的示例中,我让它自动出现以显示布局上的效果。

有人可以告诉我如何更改弹出窗口,使其不影响下面的 html 吗?谢谢。

div.callout {
  background-color: #FFF;
  background-image: -moz-linear-gradient(top, #444, #444);
  position: relative;
  color: #ccc;
  padding: 10px;
  border-radius: 3px;
  box-shadow: 0px 0px 20px #999;
  margin: 25px;
  min-height: 30px;
  border: 1px solid #0079C2;
  text-shadow: 0 0 1px #000;
  /*box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset;*/
}
.callout::before {
  content: "";
  width: 0px;
  height: 0px;
  border: 0.8em solid transparent;
  position: absolute;
}
.callout.right::before {
  left: -20px;
  top: 40%;
  border-right: 10px solid #0079C2;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<body>
  <table class="table" style="margin:0 auto; width:100%; align:center;">
    <col width="25%">
      <col width="25%">
        <col width="25%">
          <col width="25%">
            <tbody>
              <tr>
                <th>group A</th>
                <th>group B</th>
                <th>group C</th>
                <th>group D</th>
              </tr>
              <tr>
                <td>
                  <p><a href="" onclick="">click for more info</a>
                    <br>
                    <a href="" id="rate">++display popup++</a>
                  </p>

                  <div id="flag" class="callout right" style="">


                    <iframe id="frame" src="https://yahoo.com" scrolling="no" width="200px" height="250px" frameborder="0">

                    </iframe>

                  </div>

                  <p style="text-align: left;">
                    <img src="images/1.png" alt="1.png" style="margin: 0px;" />​
                    <br/>
                  </p>

                </td>
                <td>
                  <p><a href="" onclick="openFit()">click to learn</a>
                    <br>click to learn</p>
                  <p style="text-align: left;">
                    <img src="images/2.png" alt="2.png" style="margin: 0px; " />​
                    <br/>
                  </p>

                </td>
                <td>
                  <p>click to learn</br>
                    Earn your pOints​​​​​​​</p>
                  <p style="text-align: left;">
                    <img src="images/3.png" alt="3.png" style="margin: 0px; " />​
                    <br/>
                  </p>
                </td>
                <td>
                  <p>click to learn
                    <br>Earn your Points​​​​​​​</p>
                  <p style="text-align: left;">
                    <img src="4.png" alt="ace_4.png" style="margin: 0px; " />​
                    <br/>
                  </p>
                </td>

              </tr>
            </tbody>
  </table>

最佳答案

在弹出窗口中不要使用 position:relative,而是使用 position:absolute

 div.callout {
    background-color: #FFF;
    background-image: -moz-linear-gradient(top, #444, #444);
    position: absolute; /*ADJUSTED*/
    color: #ccc;
    padding: 10px;
    border-radius: 3px;
    box-shadow: 0px 0px 20px #999;
    margin: 25px;
    min-height: 30px;
    border: 1px solid #0079C2;
    text-shadow: 0 0 1px #000;
    /*box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset;*/
  }

使用position:relative,元素保留在文档的正常流程中。换句话说,它继续占用空间并影响布局。

使用 position:absolute 元素将从正常流中删除,周围的元素就像不存在一样。

一旦元素绝对定位,您就可以使用 CSS 偏移属性(topbottomleftright) 来移动它。

请记住,绝对定位的元素是相对于其 nearest positioned ancestor 定位的。 。因此,请确保将 position:relative 添加到要设置为弹出窗口的包含 block 的元素。否则,默认情况下,abspos 元素将相对于视口(viewport)定位。

https://jsfiddle.net/vdxhnfsp/1/

关于html - css 弹出窗口影响 html 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40251273/

相关文章:

css - 设置图像来填充 div 的背景

html - 使按钮与 Firefox 中的文本输入字段宽度相同

html - CSS 选择器选择 div 内的所有 img 标签,而不考虑子级别

css - 仅在 IE 中页脚下方有空白

javascript - 如何让我的 div 以水平方式显示?

html - 在 Outlook html 消息中使用相对位置

css - 为什么具有 z-index 值的元素不能覆盖其子元素?

html - flex 元素 - 填充剩余的容器高度

css - React-Native:替代 flex-basis

html - 在我的情况下如何正确使用 "position: relative"?