gpt4 book ai didi

android - Android 版 Chrome 在滚动时隐藏地址栏,在页脚下方展开背景图片

转载 作者:行者123 更新时间:2023-12-04 15:30:51 30 4
gpt4 key购买 nike

我创建了一个页脚 #bottom_footer,它在滚动时粘在网页底部。它设置为距边距顶部 100%。它适用于桌面 View 的所有浏览器以及 ios 上的 chrome。但是,在 chrome for android 上,我遇到了一个问题,即正文的背景图像扩展到页脚下方。当用户向下滚动导致地址栏隐藏但网页本身没有溢出 y 轴(全屏显示)时,就会发生这种情况。我不想阻止地址栏隐藏,我想阻止背景在浏览器全屏模式下扩展到页脚之外。我正在用 flask 应用程序开发这个网站。

此代码 fragment 需要 Bootstrap 4.5,但我无法运行脚本和样式表。如果任何人都可以将它添加到谁知道如何将它添加到代码 fragment 中,那将不胜感激。

body {
background-position: center center;
background-size: auto;
position: absolute;
overflow-x: hidden;
overflow-y: scroll;
width: 100%;
height: 100%;
font-family: 'Montserrat', sans-serif;
color: white;
}

a {
color: white;
}

a:hover {
text-decoration: none;
color: white;
}

#content-wrapper {
overflow-y: scroll;
-ms-overflow-style: none;
overflow: -moz-scrollbars-none;
}

#content-wrapper::-webkit-scrollbar {
display: none;
}

#top_navbar {
padding: 0;
}

.navbar-brand {
padding: 0;
}

#navbar_logo {
width: 15vw;
margin-right: 6vw;
margin-left: 0 !important;
}

.nav-link {
font-family: Arial, Helvetica, sans-serif;
font-size: 2vw;
-webkit-text-fill-color: white;
-webkit-text-stroke-width: 1px;
-webkit-text-stroke-color: #1b1b1b;
letter-spacing: 1px;
}

.nav-link:hover {
-webkit-text-fill-color: #1b1b1b;
-webkit-text-stroke-width: 1px;
-webkit-text-stroke-color: white;
}

.nav-item {
margin-left: 3vw;
margin-right: 3vw;
}

#bottom_footer,
#legal_documents {
background-color: #1b1b1b;
width: 100%;
position: absolute;
display: table;
bottom: 0;
text-align: center;
padding-top: 1%;
padding-bottom: .4%;
}

#legal_documents {
bottom: unset;
font-size: 10px;
padding-bottom: .6% !important;
}

#social_buttons::selection {
color: none;
background: none;
}

#social_buttons::-moz-selection {
color: none;
background: none;
}

#social_buttons a {
display: inline-block;
margin: 0 15px;
background-position: center center;
background-repeat: no-repeat;
background-size: contain;
}

#bottom_footer a:hover,
#legal_documents a:hover {
opacity: 0.5;
}
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, shrink-to-fit=no">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/js/bootstrap.min.js"></script>
</head>
<body>
<nav id="top_navbar" class="navbar navbar-expand-sm navbar-dark">
<a class="navbar-brand" href="" title="">
<img id="navbar_logo" src="">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar_items" aria-controls="navbar_items" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbar_items">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="">LABEL</a>
</li>
<li class="nav-item">
<a class="nav-link" href="">LABEL</a>
</li>
<li class="nav-item">
<a class="nav-link" href="">LABEL</a>
</li>
<li class="nav-item">
<a class="nav-link" href="">LABEL</a>
</li>
</ul>
</div>
</nav>

<main id="content-wrapper" class="container-fluid">
</main>

<div id="bottom_footer">
<div id="social_buttons">
<a href="" class="facebook" title="Facebook" target="_blank"></a>
<a href="" class="twitter" title="Twitter" target="_blank"></a>
<a href="" class="instagram" title="Instagram" target="_blank"></a>
<a href="" class="snapchat" title="Snapchat" target="_blank"></a>
<a href="" class="youtube" title="YouTube" target="_blank"></a>
</div>
<div id="legal_documents">
<a href="" title="Privacy Policy" target="_blank">PRIVACY POLICY</a> |
<a href="" title="Terms and Conditions" target="_blank">TERMS AND CONDITIONS</a>
</div>
</div>
</body>

</html>

最佳答案

已更新

您问题的直接答案 - 有一个技巧可以根据浏览器面板的显示和折叠来更正 100vh 设备高度。取自 here .

// First we get the viewport height and we multiple it by 1% to get a value for a vh unit
let vh = window.innerHeight * 0.01;
// Then we set the value in the --vh custom property to the root of the document
document.documentElement.style.setProperty('--vh', `${vh}px`);

// We listen to the resize event
window.addEventListener('resize', () => {
// We execute the same script as before
let vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
});
html {
height: 100%;
}

body {
background-position: center center;
background-size: auto;
position: absolute;
overflow-x: hidden;
overflow-y: scroll;
width: 100%;
height: calc(var(--vh, 1vh) * 100);
font-family: 'Montserrat', sans-serif;
color: white;
}

a {
color: white;
}

a:hover {
text-decoration: none;
color: white;
}

#content-wrapper {
overflow-y: scroll;
-ms-overflow-style: none;
overflow: -moz-scrollbars-none;
}

#content-wrapper::-webkit-scrollbar {
display: none;
}

#top_navbar {
padding: 0;
}

.navbar-brand {
padding: 0;
}

#navbar_logo {
width: 15vw;
margin-right: 6vw;
margin-left: 0 !important;
}

.nav-link {
font-family: Arial, Helvetica, sans-serif;
font-size: 2vw;
-webkit-text-fill-color: white;
-webkit-text-stroke-width: 1px;
-webkit-text-stroke-color: #1b1b1b;
letter-spacing: 1px;
}

.nav-link:hover {
-webkit-text-fill-color: #1b1b1b;
-webkit-text-stroke-width: 1px;
-webkit-text-stroke-color: white;
}

.nav-item {
margin-left: 3vw;
margin-right: 3vw;
}

#bottom_footer,
#legal_documents {
background-color: #1b1b1b;
width: 100%;
position: absolute;
display: table;
bottom: 0;
text-align: center;
padding-top: 1%;
padding-bottom: .4%;
}

#legal_documents {
bottom: unset;
font-size: 10px;
padding-bottom: .6% !important;
}

#social_buttons::selection {
color: none;
background: none;
}

#social_buttons::-moz-selection {
color: none;
background: none;
}

#social_buttons a {
display: inline-block;
margin: 0 15px;
background-position: center center;
background-repeat: no-repeat;
background-size: contain;
}

#bottom_footer a:hover,
#legal_documents a:hover {
opacity: 0.5;
}
<html lang="en">

<head>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, shrink-to-fit=no">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/js/bootstrap.min.js"></script>
</head>

<body>
<nav id="top_navbar" class="navbar navbar-expand-sm navbar-dark">
<a class="navbar-brand" href="" title="">
<img id="navbar_logo" src="">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar_items" aria-controls="navbar_items" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbar_items">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="">LABEL</a>
</li>
<li class="nav-item">
<a class="nav-link" href="">LABEL</a>
</li>
<li class="nav-item">
<a class="nav-link" href="">LABEL</a>
</li>
<li class="nav-item">
<a class="nav-link" href="">LABEL</a>
</li>
</ul>
</div>
</nav>

<main id="content-wrapper" class="container-fluid">
</main>

<div id="bottom_footer">
<div id="social_buttons">
<a href="" class="facebook" title="Facebook" target="_blank"></a>
<a href="" class="twitter" title="Twitter" target="_blank"></a>
<a href="" class="instagram" title="Instagram" target="_blank"></a>
<a href="" class="snapchat" title="Snapchat" target="_blank"></a>
<a href="" class="youtube" title="YouTube" target="_blank"></a>
</div>
<div id="legal_documents">
<a href="" title="Privacy Policy" target="_blank">PRIVACY POLICY</a> |
<a href="" title="Terms and Conditions" target="_blank">TERMS AND CONDITIONS</a>
</div>
</div>

</body>

</html>

附言但我认为您的模板中存在几个核心错误。这不是一个严格的规定,仅在我看来。

  1. 使用 position: absolute; 作为正文。可以替换为relative
  2. 用于 body height: 100%;。为了获得更好的体验,请使用 min-height: 100%;
  3. 这部分 #bottom_footer, #legal_documents 是非常错误的,因为它为父子设置了相同的行为,即 position: absolute;bottom: 0;.
  4. 您希望 #top_navbar#bottom_footerto 具有粘性和滚动到法律文件是相互排斥的。

我会再写一个版本,根据我的设想重写,但你总是可以使用第一个。

setDimensions();

window.addEventListener('resize', () => {
setDimensions();
});

function setDimensions() {
// this part is for prevent overlapping content by 'fixed' nav and footer, by adding 2 blocks with the same height, but with unset position
let topHeight = $('#top_navbar').outerHeight();
let footerHeight = $('#bottom_footer').outerHeight();
$('#pre_top_navbar').css('height', (topHeight) + 'px');
$('#pre_bottom_footer').css('height', (footerHeight) + 'px');

let vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
}
html {
height: 100%;
}

body {
background-position: center center;
background-size: auto;
position: relative;
overflow-x: hidden;
overflow-y: scroll;
width: 100%;
min-height: 100vh;
min-height: calc(var(--vh, 1vh) * 100);
font-family: 'Montserrat', sans-serif;
color: #333;
}

a {
color: white;
}

a:hover {
text-decoration: none;
color: white;
}

#content-wrapper {
overflow-y: scroll;
-ms-overflow-style: none;
overflow: -moz-scrollbars-none;
}

#content-wrapper::-webkit-scrollbar {
display: none;
}

#top_navbar {
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 2;
padding: 0;
background: #fff;
}

.navbar-brand {
padding: 0;
}

#navbar_logo {
width: 15vw;
margin-right: 6vw;
margin-left: 0 !important;
}

.nav-link {
font-family: Arial, Helvetica, sans-serif;
font-size: 2vw;
-webkit-text-fill-color: white;
-webkit-text-stroke-width: 1px;
-webkit-text-stroke-color: #1b1b1b;
letter-spacing: 1px;
}

.nav-link:hover {
-webkit-text-fill-color: #1b1b1b;
-webkit-text-stroke-width: 1px;
-webkit-text-stroke-color: white;
}

.nav-item {
margin-left: 3vw;
margin-right: 3vw;
}

#bottom_footer {
background-color: #1b1b1b;
width: 100%;
position: fixed;
display: table;
bottom: 0;
text-align: center;
padding-top: 1%;
padding-bottom: .4%;
z-index: 2;
}

#legal_documents {
bottom: unset;
font-size: 10px;
padding-bottom: .6% !important;
}

#social_buttons::selection {
color: none;
background: none;
}

#social_buttons::-moz-selection {
color: none;
background: none;
}

#social_buttons a {
display: inline-block;
margin: 0 15px;
background-position: center center;
background-repeat: no-repeat;
background-size: contain;
}

#bottom_footer a:hover,
#legal_documents a:hover {
opacity: 0.5;
}
<html lang="en">

<head>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, shrink-to-fit=no">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/js/bootstrap.min.js"></script>
</head>

<body>
<div id="pre_top_navbar"></div>
<nav id="top_navbar" class="navbar navbar-expand-sm navbar-dark">
<a class="navbar-brand" href="" title="">
<img id="navbar_logo" src="">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar_items" aria-controls="navbar_items" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbar_items">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="">LABEL</a>
</li>
<li class="nav-item">
<a class="nav-link" href="">LABEL</a>
</li>
<li class="nav-item">
<a class="nav-link" href="">LABEL</a>
</li>
<li class="nav-item">
<a class="nav-link" href="">LABEL</a>
</li>
</ul>
</div>
</nav>

<main id="content-wrapper" class="container-fluid">
first<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>last
</main>

<div id="pre_bottom_footer"></div>
<div id="bottom_footer">
<div id="social_buttons">
<a href="" class="facebook" title="Facebook" target="_blank"></a>
<a href="" class="twitter" title="Twitter" target="_blank"></a>
<a href="" class="instagram" title="Instagram" target="_blank"></a>
<a href="" class="snapchat" title="Snapchat" target="_blank"></a>
<a href="" class="youtube" title="YouTube" target="_blank"></a>
</div>
<div id="legal_documents">
<a href="" title="Privacy Policy" target="_blank">PRIVACY POLICY</a> |
<a href="" title="Terms and Conditions" target="_blank">TERMS AND CONDITIONS</a>
</div>
</div>
</body>

</html>

关于android - Android 版 Chrome 在滚动时隐藏地址栏,在页脚下方展开背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61264725/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com