html - 在所有分辨率下保持元素的相同高度

标签 html css

enter image description here

我有三个元素,红色的是 div,以图像为背景,显示我客户的 Logo 。白色的是一个“模态”窗口,当你点击菜单上的一个元素时出现(不显示),这个模态窗口使用百分比作为它的高度,并使用一个固定的位置保持在页面的中心(垂直和水平) ).模态的底部与两个红色框对齐。对于我的解决方案,它工作完美,但在 Macbook 上(例如)全屏时,该网站看起来像这样

enter image description here

我应该怎么做才能解决这个问题?

如果有人需要,这里是模态的 CSS

   .modal{
    cursor: auto;
    position: absolute;
    z-index: 11;
    top: 45px;
    bottom: 15px;
    right: 0;
    left: 0;
    margin: auto;
    width: 940px;
    max-width: 1072px;
    height: 81%;
    padding: 40px;
    background-color: rgb(255, 255, 255);
    -webkit-border-radius: 3px;
    -moz-border-radius: 3px;
    border-radius: 3px;
    color: #1C1C1C;
    text-align: left;
    overflow-y: auto;
    overflow-x: hidden;
   }

最佳答案

删除模态中的高度属性,您必须使用topbottom 拉伸(stretch)模态。这将确保模态框的底部距屏幕底部 15 像素。

The bottom of the modal as to be aligned with the two red boxes..

使用 topbottom 将相同的 Css 规则添加到您的红色 div

this modal window uses percentages for its height and uses a fixed position to stay in the center of the page (both vertically and horizontally)

如果您说模态框甚至垂直居中,那么您如何期望侧面的红色 div 在底部正确对齐?

为此,您必须使用 jquery,并且每当 显示 模态时,计算从窗口底部到模态底部的像素数,然后将此像素作为 CSS 规则添加到两侧 div 的底部属性。这样你就可以对齐了

关于html - 在所有分辨率下保持元素的相同高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36522639/

相关文章:

html - 触摸友好的嵌套导航菜单的解决方案?

php - 创建高度灵活的 HTML 表格时应遵循的最佳实践是什么?

javascript - HTML Canvas 元素不显示图像

javascript - 用固定宽度/高度 'items' 动态填充可变宽度列

html - 垂直对齐(行高法)不起作用

html - 中心 Bootstrap 下拉菜单

php - Jquery点击链接发送信息到php

javascript - 使用 Jquery 加载方法和 Slick 插件

javascript - 在弹出窗口外关闭弹出窗口,但在内部保持打开状态

javascript - Django 问题 : manage. py runserver 错误信息