我在我的 web 應用程式的前端苦苦掙扎,我使用 Bootstrap 和一些自定義 css 定義進行一些調整;桌面界面還可以,但對于智能手機來說,導航欄中仍然存在問題,因此當您單擊滾動選單時,按鈕不會在一行中對齊。為了更好地理解,我附上了界面現在的樣子1以及我打算如何實作它的照片2。
下面是使用的代碼:
body {
background-color: black;
font-family: "Futura-CondensedExtraBold", sans-serif;
font-weight: bold;
background-image: url("wallpaper.png");
background-position: center top;
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
}
.navbar{
background-color: #000b29;
width: 100%;
}
.input-field-warn{
color: orangered;
font-size: small;
}
.input-field-ok{
color: forestgreen;
font-size: small;
}
.btn-home{
border-radius: 10%;
background-color: darkgrey;
border-color: white;
border-width: medium;
font-weight: bold;
margin-left: 2%;
color: #222222;
font-size: 1.5vw;
width: 12.5vw;
height: calc(3.2vw 10px);
overflow: hidden;
white-space: nowrap;
}
.btn-home:hover{
background-color: #525252;
}
.row-1{
margin-top: 2%;
margin-left: 10%;
text-decoration: underline;
text-underline-offset: 20%;
color: white;
}
.home-box{
background: rgba(0, 0, 0, 0.5);
margin-left: 10%;
padding: 3%;
border-radius: 5%;
font-size: calc(0.7vw 0.55vh);
color: #ffffff;
border: solid white;
}
.home-box-1{
width: 35%;
margin-top: 2.5%;
}
.home-box-2{
width: 55%;
margin-top: 5%;
}
.home-box-3{
width: 40%;
margin-top: 5%;
}
.home-box-4{
width: 80%;
margin-top: 2.5%;
}
.button-img{
margin-left: 10%;
height: 1.5vw;
width: 1.5vw;
}
#main-container{
width: 99vw;
height: 100%;
}
#login-form{
align-content: center;
padding: 5%;
}
#logo-home{
margin-left: 10%;
font-size: 2.5vw;
}
#info-img{
margin-left: 3%;
width: 5%;
height: 5%;
}
#home-navbar{
width: 100vw;
height: 10%;
}
#nav-container{
width: 100vw;
height: 10%;
}
#logo{
width: 2.5vw;
height: 2.5vw;
margin-bottom: 20%;
}
@media screen and (max-width: 992px) {
#home-button-container{
justify-content: center;
overflow: hidden;
white-space: nowrap;
width: 100%;
text-align: center;
}
.btn-home{
padding: 0;
margin: 0;
font-size: 2.5vw;
overflow: hidden;
white-space: nowrap;
display: inline-block;
}
.home-box-1{
width: 80%;
margin-top: 2.5%;
}
.home-box-2{
width: 80%;
margin-top: 5%;
}
.home-box-3{
width: 80%;
margin-top: 5%;
}
#navbarSupportedContent{
overflow: hidden;
white-space: nowrap;
}
}
<!doctype html>
<html lang="en">
<head>
<title>WhoIsOnline</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg OMhuP IlRH9sENBO0LRn5q 8nbTov4 1p" crossorigin="anonymous"></script>
<script src="index.js" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link href="indexStyle.css" rel="stylesheet">
<link rel="shortcut icon" href="icon.ico" type="image/x-icon">
</head>
<body onload="loadInfo()">
<div id="main-container">
<div id="nav-container">
<nav class="navbar py-3 navbar-expand-lg navbar-dark" id="home-navbar">
<div class="container-fluid">
<div id="logo-home">
<a class="navbar-brand" href="/">
<img src="LOGO WHOSONLINE.png" alt="Logo" id="logo">
</a>
</div>
<a class="navbar-brand" href="/">WhoIsOnline</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<div class="navbar-nav me-auto mb-2 mb-lg-0">
</div>
<div class="d-grid gap-2 d-md-flex justify-content-md-end" id="home-button-container">
<form action="/info" id="info-form"></form>
<button class="btn btn-primary me-md-2 btn-home" form="info-form" type="submit" onmouseover="changeColorImage(this, 'white')" onmouseout="changeColorImage(this, 'black')">Info<img src="info.png" class="button-img"></button>
<button class="btn btn-primary me-md-2 btn-home" type="button" data-toggle="modal" data-target="#ModalRegister" onmouseover="changeColorImage(this, 'white')" onmouseout="changeColorImage(this, 'black')">SignIn<img src="account.png" class="button-img"></button>
<button class="btn btn-primary me-md-2 btn-home" type="button" data-toggle="modal" data-target="#ModalLogIn" onmouseover="changeColorImage(this, 'white')" onmouseout="changeColorImage(this, 'black')">LogIn<img src="lock.png" class="button-img"></button>
</div>
</div>
</div>
</nav>
</div>
</div>
</body>
</html>
uj5u.com熱心網友回復:
洗掉d-grid您的課程#home-button-container。flex并且grid通常可以在布局中很好地協同作業。但在這種情況下,它會適得其反flex。
body {
background-color: black;
font-family: "Futura-CondensedExtraBold", sans-serif;
font-weight: bold;
background-image: url("wallpaper.png");
background-position: center top;
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
}
.navbar {
background-color: #000b29;
width: 100%;
}
.input-field-warn {
color: orangered;
font-size: small;
}
.input-field-ok {
color: forestgreen;
font-size: small;
}
.btn-home {
border-radius: 10%;
background-color: darkgrey;
border-color: white;
border-width: medium;
font-weight: bold;
margin-left: 2%;
color: #222222;
font-size: 1.5vw;
width: 12.5vw;
height: calc(3.2vw 10px);
overflow: hidden;
white-space: nowrap;
}
.btn-home:hover {
background-color: #525252;
}
.row-1 {
margin-top: 2%;
margin-left: 10%;
text-decoration: underline;
text-underline-offset: 20%;
color: white;
}
.home-box {
background: rgba(0, 0, 0, 0.5);
margin-left: 10%;
padding: 3%;
border-radius: 5%;
font-size: calc(0.7vw 0.55vh);
color: #ffffff;
border: solid white;
}
.home-box-1 {
width: 35%;
margin-top: 2.5%;
}
.home-box-2 {
width: 55%;
margin-top: 5%;
}
.home-box-3 {
width: 40%;
margin-top: 5%;
}
.home-box-4 {
width: 80%;
margin-top: 2.5%;
}
.button-img {
margin-left: 10%;
height: 1.5vw;
width: 1.5vw;
}
#main-container {
width: 99vw;
height: 100%;
}
#login-form {
align-content: center;
padding: 5%;
}
#logo-home {
margin-left: 10%;
font-size: 2.5vw;
}
#info-img {
margin-left: 3%;
width: 5%;
height: 5%;
}
#home-navbar {
width: 100vw;
height: 10%;
}
#nav-container {
width: 100vw;
height: 10%;
}
#logo {
width: 2.5vw;
height: 2.5vw;
margin-bottom: 20%;
}
@media screen and (max-width: 992px) {
#home-button-container {
justify-content: center;
overflow: hidden;
white-space: nowrap;
width: 100%;
text-align: center;
}
.btn-home {
padding: 0;
margin: 0;
font-size: 2.5vw;
overflow: hidden;
white-space: nowrap;
display: inline-block;
}
.home-box-1 {
width: 80%;
margin-top: 2.5%;
}
.home-box-2 {
width: 80%;
margin-top: 5%;
}
.home-box-3 {
width: 80%;
margin-top: 5%;
}
#navbarSupportedContent {
overflow: hidden;
white-space: nowrap;
}
}
<!doctype html>
<html lang="en">
<head>
<title>WhoIsOnline</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg OMhuP IlRH9sENBO0LRn5q 8nbTov4 1p" crossorigin="anonymous"></script>
<script src="index.js" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="indexStyle.css" rel="stylesheet">
<link rel="shortcut icon" href="icon.ico" type="image/x-icon">
</head>
<body>
<div id="main-container">
<div id="nav-container">
<nav class="navbar py-3 navbar-expand-lg navbar-dark" id="home-navbar">
<div class="container-fluid">
<div id="logo-home">
<a class="navbar-brand" href="/">
<img src="LOGO WHOSONLINE.png" alt="Logo" id="logo">
</a>
</div>
<a class="navbar-brand" href="/">WhoIsOnline</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<div class="navbar-nav me-auto mb-2 mb-lg-0">
</div>
<div class="gap-2 ms-4 d-md-flex justify-content-md-end" id="home-button-container">
<form action="/info" id="info-form"></form>
<button class="btn btn-primary me-md-2 btn-home" form="info-form" type="submit" onmouseover="null" onmouseout="null">Info<img src="info.png" class="button-img"></button>
<button class="btn btn-primary me-md-2 btn-home" type="button" data-toggle="modal" data-target="#ModalRegister" onmouseover="null" onmouseout="null">SignIn<img src="account.png" class="button-img"></button>
<button class="btn btn-primary me-md-2 btn-home" type="button" data-toggle="modal" data-target="#ModalLogIn" onmouseover="null" onmouseout="null">LogIn<img src="lock.png" class="button-img"></button>
</div>
</div>
</div>
</nav>
</div>
</div>
</body>
</html>
uj5u.com熱心網友回復:
您正在使用表單外的按鈕 - 試試這個:
<form action="/info" id="info-form">
<button class="btn btn-primary me-md-2 btn-home" form="info-form" type="submit" onmouseover="changeColorImage(this, 'white')" onmouseout="changeColorImage(this, 'black')">Info<img src="info.png" class="button-img"></button>
<button class="btn btn-primary me-md-2 btn-home" type="button" data-toggle="modal" data-target="#ModalRegister" onmouseover="changeColorImage(this, 'white')" onmouseout="changeColorImage(this, 'black')">SignIn<img src="account.png" class="button-img"></button>
<button class="btn btn-primary me-md-2 btn-home" type="button" data-toggle="modal" data-target="#ModalLogIn" onmouseover="changeColorImage(this, 'white')" onmouseout="changeColorImage(this, 'black')">LogIn<img src="lock.png" class="button-img"></button>
</form>
body {
background-color: black;
font-family: "Futura-CondensedExtraBold", sans-serif;
font-weight: bold;
background-image: url("wallpaper.png");
background-position: center top;
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
}
.navbar{
background-color: #000b29;
width: 100%;
}
.input-field-warn{
color: orangered;
font-size: small;
}
.input-field-ok{
color: forestgreen;
font-size: small;
}
.btn-home{
border-radius: 10%;
background-color: darkgrey;
border-color: white;
border-width: medium;
font-weight: bold;
margin-left: 2%;
color: #222222;
font-size: 1.5vw;
width: 12.5vw;
height: calc(3.2vw 10px);
overflow: hidden;
white-space: nowrap;
}
.btn-home:hover{
background-color: #525252;
}
.row-1{
margin-top: 2%;
margin-left: 10%;
text-decoration: underline;
text-underline-offset: 20%;
color: white;
}
.home-box{
background: rgba(0, 0, 0, 0.5);
margin-left: 10%;
padding: 3%;
border-radius: 5%;
font-size: calc(0.7vw 0.55vh);
color: #ffffff;
border: solid white;
}
.home-box-1{
width: 35%;
margin-top: 2.5%;
}
.home-box-2{
width: 55%;
margin-top: 5%;
}
.home-box-3{
width: 40%;
margin-top: 5%;
}
.home-box-4{
width: 80%;
margin-top: 2.5%;
}
.button-img{
margin-left: 10%;
height: 1.5vw;
width: 1.5vw;
}
#main-container{
width: 99vw;
height: 100%;
}
#login-form{
align-content: center;
padding: 5%;
}
#logo-home{
margin-left: 10%;
font-size: 2.5vw;
}
#info-img{
margin-left: 3%;
width: 5%;
height: 5%;
}
#home-navbar{
width: 100vw;
height: 10%;
}
#nav-container{
width: 100vw;
height: 10%;
}
#logo{
width: 2.5vw;
height: 2.5vw;
margin-bottom: 20%;
}
@media screen and (max-width: 992px) {
#home-button-container{
justify-content: center;
overflow: hidden;
white-space: nowrap;
width: 100%;
text-align: center;
}
.btn-home{
padding: 0;
margin: 0;
font-size: 2.5vw;
overflow: hidden;
white-space: nowrap;
display: inline-block;
}
.home-box-1{
width: 80%;
margin-top: 2.5%;
}
.home-box-2{
width: 80%;
margin-top: 5%;
}
.home-box-3{
width: 80%;
margin-top: 5%;
}
#navbarSupportedContent{
overflow: hidden;
white-space: nowrap;
}
}
<!doctype html>
<html lang="en">
<head>
<title>WhoIsOnline</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg OMhuP IlRH9sENBO0LRn5q 8nbTov4 1p" crossorigin="anonymous"></script>
<script src="index.js" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link href="indexStyle.css" rel="stylesheet">
<link rel="shortcut icon" href="icon.ico" type="image/x-icon">
</head>
<body onload="loadInfo()">
<div id="main-container">
<div id="nav-container">
<nav class="navbar py-3 navbar-expand-lg navbar-dark" id="home-navbar">
<div class="container-fluid">
<div id="logo-home">
<a class="navbar-brand" href="/">
<img src="LOGO WHOSONLINE.png" alt="Logo" id="logo">
</a>
</div>
<a class="navbar-brand" href="/">WhoIsOnline</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<div class="navbar-nav me-auto mb-2 mb-lg-0">
</div>
<div class="d-grid gap-2 d-md-flex justify-content-md-end" id="home-button-container">
<form action="/info" id="info-form">
<button class="btn btn-primary me-md-2 btn-home" form="info-form" type="submit" onmouseover="changeColorImage(this, 'white')" onmouseout="changeColorImage(this, 'black')">Info<img src="info.png" class="button-img"></button>
<button class="btn btn-primary me-md-2 btn-home" type="button" data-toggle="modal" data-target="#ModalRegister" onmouseover="changeColorImage(this, 'white')" onmouseout="changeColorImage(this, 'black')">SignIn<img src="account.png" class="button-img"></button>
<button class="btn btn-primary me-md-2 btn-home" type="button" data-toggle="modal" data-target="#ModalLogIn" onmouseover="changeColorImage(this, 'white')" onmouseout="changeColorImage(this, 'black')">LogIn<img src="lock.png" class="button-img"></button>
</form>
</div>
</div>
</div>
</nav>
</div>
</div>
</body>
</html>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/473108.html
