html - CSS 图片在小屏幕上几乎在顶部,在大屏幕上更多在中间

标签 html css

基本上我想要的是当屏幕分辨率上升时图片“内容”向下移动到中心。这可能吗??

//html

<html>
<head>
<title>BBQ day</title>
<link href="CSS/stylesheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <div class="container">
        <div class="content"></div>
    </div>
    <div class="powerd"></div>
</body>
</html>

//CSS

body{ background-color:#000;}

.container{ position:relative; width:100%; height:auto;}
.content{background-image:url('../images/BO_BBQdag-webt_03.jpg'); width:768px; height:607px; margin-left:auto; margin-right:auto; margin-top:0px 0.11111%}
.powerd{ background-image:url('../images/BO_BBQdag-webt_07.jpg'); background-repeat:no-repeat; position:absolute; height:72px; width:287px; margin-left:auto; margin-right:auto;bottom:0px; left:50%; margin-left: -143.5px; }

最佳答案

为此,您需要在页面加载事件时获取屏幕分辨率。

 <script>
         function GetScreenHeight_Width()
            {
                        var h = window.innerHeight || document.documentElement.clientHeight || document.getElementsByTagName('body')[0].clientHeight;
                        var w = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;
                         /** then you stored it into Hidden Control
                             As per resolution you can set position of the Content  with absolute or Fixed position.
                     You have to set position of the   <div class="content"></div>  element as per resolution..    
    When page load then call this function to set Actual height width of the Screens 
                         */                
              }
// Call function on page load.
GetScreenHeight_Width();
 </script>

如果不工作请告诉我。

关于html - CSS 图片在小屏幕上几乎在顶部,在大屏幕上更多在中间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9602947/

相关文章:

javascript - 减少 HTML 代码的长度

javascript - 为什么会发生这种换行?

html - Bootstrap 列重新排序和 2 列跨越。我的布局可能吗?

html - 调整边距时顶部有白线

jquery - 如何在选择菜单中为选项设置单独的样式 (css) (jquery-ui : selectmenu)

java - 截断 p :dataTable and exporting the table with the full text 中的大文本值

html - margin-top in parent, negative top in child, 如何摆脱下面的剩余高度

php - 如何使用 foreach 循环根据所选选项将数据检索到文本区域?

javascript - 使用 HTML anchor 标记在 Electron 中打开外部链接

css - 如果禁用悬停路由器按钮时禁用指针事件