在以下 w3schools 代碼中,我在網頁底部實作了回應式選單,我添加了一個帶有域著作權宣告的 div。我想讓著作權 div在螢屏底部居中,只要它沒有被選單項覆寫,因為瀏覽器視窗變小,然后在頁面底部再次移動選單項下方的選單項被它們覆寫,或者當選單在之前最小化時被相關按鈕打開時。
function myFunction() {
var x = document.getElementById("myNavbar");
if (x.className === "navbar") {
x.className = " responsive";
} else {
x.className = "navbar";
}
}
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.navbar {
overflow: hidden;
background-color: #333;
position: fixed;
bottom: 0;
width: 100%;
}
.navbar a {
float: right;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.navbar a:hover {
background-color: #ddd;
color: black;
}
.navbar a.active {
background-color: #04AA6D;
color: white;
}
.navbar .icon {
display: none;
}
#copyright {
position: absolute;
top: 20%;
left: 25%;
width: 50%;
height: 50%;
color: white;
}
@media screen and (max-width: 600px) {
.navbar a:not(:first-child) {
display: none;
}
.navbar a.icon {
float: right;
display: block;
}
}
@media screen and (max-width: 600px) {
.navbar.responsive .icon {
position: absolute;
right: 0;
bottom: 0;
}
.navbar.responsive a {
float: none;
display: block;
text-align: left;
}
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="navbar" id="myNavbar">
<div id="copyright">? domain.com</div>
<a href="#home" class="active">Home</a>
<a href="#news">News</a>
<a href="#contact">Contact</a>
<a href="#about">About</a>
<a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myFunction()">☰</a>
</div>
<div style="padding-left:16px">
<h2>Responsive Bottom Navbar Example</h2>
<p>Resize the browser window to see how it works.</p>
</div>
</body>
</html>
歡迎任何有關良好實施的想法!
uj5u.com熱心網友回復:
試試這個解決方案:
function myFunction() {
var x = document.getElementById("myNavbar");
if (x.className === "navbar") {
x.className = " responsive";
} else {
x.className = "navbar";
}
}
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.navbar {
overflow: hidden;
background-color: #333;
position: fixed;
display: flex;
justify-content: center;
bottom: 0;
width: 100%;
}
.navbar a {
float: right;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.navbar a:hover {
background-color: #ddd;
color: black;
}
.navbar a.active {
background-color: #04AA6D;
color: white;
}
.navbar .icon {
display: none;
}
#copyright {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
color: white;
}
@media screen and (max-width: 600px) {
.navbar {
display: block;
}
.navbar a:not(:first-child) {
display: none;
}
.navbar a.icon {
float: right;
display: block;
}
#copyright {
margin: 5px;
}
}
@media screen and (max-width: 600px) {
.navbar.responsive .icon {
position: absolute;
right: 0;
bottom: 0;
}
.navbar.responsive a {
float: none;
display: block;
text-align: left;
}
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="navbar" id="myNavbar">
<div id="copyright">? domain.com</div>
<a href="#home" class="active">Home</a>
<a href="#news">News</a>
<a href="#contact">Contact</a>
<a href="#about">About</a>
<a href="javascript:void(0);" style="font-size:15px;" class="icon" onclick="myFunction()">☰</a>
</div>
<div style="padding-left:16px">
<h2>Responsive Bottom Navbar Example</h2>
<p>Resize the browser window to see how it works.</p>
</div>
</body>
</html>
uj5u.com熱心網友回復:
這是你喜歡的東西?。
function myFunction() {
var x = document.getElementById("myNavbar");
if (x.className === "navbar") {
x.className = " responsive";
} else {
x.className = "navbar";
}
}
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.navbar {
overflow: hidden;
background-color: #333;
position: fixed;
bottom: 0%;
right: 0%;
width: 100%;
display: flex;
}
.navbar a {
color: #f2f2f2;
text-decoration: none;
font-size: 17px;
padding: 0 15px;
}
.navbar a:hover {
background-color: #ddd;
color: black;
}
.navbar a.active {
background-color: #04aa6d;
color: white;
}
.navbar .icon {
display: none;
}
/* #copyright {
position: absolute;
top: 20%;
left: 25%;
width: 50%;
height: 50%;
color: white;
} */
#copyright {
flex-grow: 1;
text-align: center;
color: white;
}
#copyright-bottom {
flex-grow: 1;
text-align: center;
color: white;
display: none;
}
@media screen and (max-width: 600px) {
.navbar a:not(:first-child) {
display: none;
}
.navbar a.icon {
float: right;
display: block;
}
}
@media screen and (max-width: 600px) {
.navbar {
display: inline-block;
text-align: center;
}
.navbar.responsive .icon {
position: absolute;
right: 0;
bottom: 0;
}
.navbar.responsive a {
float: none;
display: block;
text-align: left;
}
#copyright {
flex-grow: 1;
text-align: center;
color: white;
display: none;
}
#copyright-bottom {
flex-grow: 1;
text-align: center;
color: white;
display: block;
}
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="navbar" id="myNavbar">
<span id="copyright">? domain.com</span>
<a href="#about">About</a>
<a href="#contact">Contact</a>
<a href="#news">News</a>
<a href="#home" class="active">Home</a>
<a href="javascript:void(0);" style="font-size: 15px" class="icon" onclick="myFunction()"
>☰</a
>
<span id="copyright-bottom">? domain.com</span>
</div>
<div style="padding-left: 16px">
<h2>Responsive Bottom Navbar Example</h2>
<p>Resize the browser window to see how it works.</p>
</div>
</body>
</html>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/347495.html
標籤:javascript html css 响应式设计 反应灵敏
下一篇:如何以編程方式取消選中單選按鈕
