gpt4 book ai didi

php - 导航项只能在元素下点击?

转载 作者:太空宇宙 更新时间:2023-11-04 08:45:26 24 4
gpt4 key购买 nike

首先我知道这个问题很困惑,我想不出任何其他方式来解释它。基本上,出于某种原因,我在我的网站广告上做了一个测试登录系统,当你将鼠标悬停在主页上时,导航栏工作正常,但在登录和注册页面上,你必须在元素下找到某个位置导航栏以便能够将鼠标悬停在它上面或单击它。出于某种原因,这不会发生在主页上,而只会发生在这两个页面上。

网站:http://www.abyssallogin.hol.es/

索引.php

<?php
session_start();

require 'login/database.php';

if( isset($_SESSION['user_id']) ){
$records = $conn->prepare('SELECT id,username,password FROM users WHERE id = :id');

$records->bindParam(':id', $_SESSION['user_id']);

$records->execute();

$results = $records->fetch(PDO::FETCH_ASSOC);

$user = NULL;

if( count($results) > 0){
$user = $results;
}
}
?>

<DOCTYPE html>
<html lang="en">
<head>
<title>Login Test</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/index.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans">
</head>
<body>
<?php if( !empty($user) ): ?>

<nav class="navigation">
<div class="navigation-logo">Website</div>
<ul>
<li><a href="#" class="navigation-item">Home</a></li>
<li><a href="#" class="navigation-item">Deposit</a></li>
<li><a href="#" class="navigation-item">Withdraw</a></li>
<li><a href="#" class="navigation-item">Free Coins</a></li>
<li><a href="#" class="navigation-item">Support</a></li>
</ul>
<form id="button" action='login/logout' method='POST'><button class="btn" name='logout' type='submit'>Logout</button></form>
</nav>
<span class="login-message">You are now logged in.</span>

<? else: ?>

<nav class="navigation">
<div class="navigation-logo">Website</div>
<ul>
<li><a href="index" class="navigation-item">Home</a></li>
<li><a href="#" class="navigation-item">Deposit</a></li>
<li><a href="#" class="navigation-item">Withdraw</a></li>
<li><a href="#" class="navigation-item">Free Coins</a></li>
<li><a href="#" class="navigation-item">Support</a></li>
</ul>
<form id="button" action='login/login' method='POST'><button class="btn" name='login' type='submit'>Login</button></form>
</nav>
<span class="login-message">You are not currently logged in.</span>

<? endif; ?>
</body>
</html>

登录.php

<?php
session_start();

if( isset($_SESSION['user_id']) ){
header("Location: /");
}

require 'database.php';

$message = '';

if(!empty($_POST['username']) && !empty($_POST['password'])):
$records = $conn->prepare('SELECT id,username,password FROM users WHERE username = :username');

$records->bindParam(':username', $_POST['username']);

$records->execute();

$results = $records->fetch(PDO::FETCH_ASSOC);

if(count($results) > 0 && password_verify($_POST['password'], $results['password']) ){
$_SESSION['user_id'] = $results['id'];
header("Location: /");
} else {
$message = 'Incorrect username or password.';
}
endif;
?>

<!DOCTYPE html>
<html lang="en">
<head>
<title>Login Test</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="../css/login.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans">
</head>
<body>
<nav class="navigation">
<div class="navigation-logo">Website</div>
<ul>
<li><a href="../index" class="navigation-item">Home</a></li>
<li><a href="#" class="navigation-item">Deposit</a></li>
<li><a href="#" class="navigation-item">Withdraw</a></li>
<li><a href="#" class="navigation-item">Free Coins</a></li>
<li><a href="#" class="navigation-item">Support</a></li>
</ul>
<form id="button" action='login' method='POST'><button class="btn" name='login' type='submit'>Login</button></form>
</nav>
<form action="login" method="POST">
<input type="text" placeholder="Username" name="username">
<input type="password" placeholder="Password" name="password">
<input type="submit" name="login" value="Login">
<span class="register-text">Don't have an account? <a href="register">Register Here</a></span>
</form>
</body>
</html>

注册.php

<?php
session_start();

if( isset($_SESSION['user_id']) ){
header("Location: /");
}

require 'database.php';

if(!empty($_POST['username']) && !empty($_POST['password'])):

$sql = "INSERT INTO users (username, password) VALUES (:username, :password)";

$stmt = $conn->prepare($sql);

$stmt->bindParam(':username', $_POST['username']);

$hash = password_hash($_POST['password'], PASSWORD_BCRYPT);

$stmt->bindParam(':password', $hash);

if( $stmt->execute() ):
$message = '';
header("Location: login");
else:
$message = '';
endif;

endif;
?>

<!DOCTYPE html>
<html lang="en">
<head>
<title>Login Test</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="../css/register.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans">
</head>
<body>
<nav class="navigation">
<div class="navigation-logo">Website</div>
<ul>
<li><a href="../index" class="navigation-item">Home</a></li>
<li><a href="#" class="navigation-item">Deposit</a></li>
<li><a href="#" class="navigation-item">Withdraw</a></li>
<li><a href="#" class="navigation-item">Free Coins</a></li>
<li><a href="#" class="navigation-item">Support</a></li>
</ul>
<form id="button" action='login' method='POST'><button class="btn" name='login' type='submit'>Login</button></form>
</nav>
<form action="register" method="POST">
<input type="text" placeholder="Username" name="username">
<input type="password" placeholder="Password" name="password">
<input type="password" placeholder="Confirm Password" name="confirm_password">
<input type="submit" name="register" value="Register">
<span class="register-text">Already have an account? <a href="login">Login Here</a></span>
</form>
</body>
</html>

索引.css

body {
margin: 0px;
padding: 0px;
font-size: 16px;
font-family: 'Open Sans', sans-serif;
}

.navigation {
width: 100%;
height: 70px;
color: rgb(255, 255, 255);
background-color: rgb(40, 40, 40);
}

.navigation > .navigation-logo {
float: left;
height: 40px;
font-size: 28px;
line-height: 35px;
padding: 15px 30px;
}

.navigation > ul {
margin: 0px;
float: right;
padding: 0px;
margin-right: 190px;
list-style-type: none;
}

.navigation > ul > li {
float: left;
}

.navigation > ul > li > .navigation-item {
height: 40px;
margin-left:15px;
line-height: 40px;
padding: 15px 0px;
margin-right: 15px;
position: relative;
display: inline-block;
text-decoration: none;
color: rgb(255, 255, 255);
}

.navigation > ul > li > .navigation-item:before {
left: 0px;
content: "";
width: 100%;
height: 2px;
bottom: 20px;
position: absolute;
visibility: hidden;
background-color: rgb(215, 85, 80);
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s;
}

.navigation > ul > li > .navigation-item:hover:before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}

.navigation > ul > li > .navigation-item:hover {
color: rgb(215, 85, 80);
}

#button {
top: 0px;
right: 0px;
margin-right: 15px;
position: absolute;
}

.btn {
float: right;
outline: none;
cursor: pointer;
font-size: 22px;
margin-top:15px;
margin-left:20px;
margin-right:20px;
padding: 5px 35px;
border-radius: 5px;
position: relative;
display: inline-block;
text-decoration: none;
color: rgb(255, 255, 255);
transition: all 0.3s ease-in-out;
background-color: rgb(40, 40, 40);
border: 2px solid rgb(255, 255, 255);
}

.btn:hover {
color: rgb(40, 40, 40);
background-color: rgb(255, 255, 255);
}

.login-message {
color: rgb(0, 0, 0);
}

登录.css

body {
margin: 0px;
padding: 0px;
font-size: 16px;
font-family: 'Open Sans', sans-serif;
}

.navigation {
width: 100%;
height: 70px;
color: rgb(255, 255, 255);
background-color: rgb(40, 40, 40);
}

.navigation > .navigation-logo {
float: left;
height: 40px;
font-size: 28px;
line-height: 35px;
padding: 15px 30px;
}

.navigation > ul {
margin: 0px;
float: right;
padding: 0px;
margin-right: 190px;
list-style-type: none;
}

.navigation > ul > li {
float: left;
}

.navigation > ul > li > .navigation-item {
height: 40px;
margin-left:15px;
line-height: 40px;
padding: 15px 0px;
margin-right: 15px;
position: relative;
display: inline-block;
text-decoration: none;
color: rgb(255, 255, 255);
}

.navigation > ul > li > .navigation-item:before {
left: 0px;
content: "";
width: 100%;
height: 2px;
bottom: 20px;
position: absolute;
visibility: hidden;
background-color: rgb(215, 85, 80);
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s;
}

.navigation > ul > li > .navigation-item:hover:before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}

.navigation > ul > li > .navigation-item:hover {
color: rgb(215, 85, 80);
}

#button {
top: 0px;
right: 0px;
margin-right: 15px;
position: absolute;
}

.btn {
float: right;
outline: none;
cursor: pointer;
font-size: 22px;
margin-top:15px;
margin-left:20px;
margin-right:20px;
padding: 5px 35px;
border-radius: 5px;
position: relative;
display: inline-block;
text-decoration: none;
color: rgb(255, 255, 255);
transition: all 0.3s ease-in-out;
background-color: rgb(40, 40, 40);
border: 2px solid rgb(255, 255, 255);
}

.btn:hover {
color: rgb(40, 40, 40);
background-color: rgb(255, 255, 255);
}

form {
position: absolute;
right: 0px;
left: 0px;
top: 40%;
}

input[type="text"], input[type="password"] {
border: 2px solid rgb(40, 40, 40);
margin: 10px auto;
display: block;
outline: none;
padding: 10px;
width: 300px;
}

input[type="submit"] {
transition: 0.3s all ease-in-out;
outline: 2px solid rgb(40, 40, 40);
background: rgb(40, 40, 40);
color: rgb(255, 255, 255);
margin: 0px auto;
margin-top: 10px;
cursor: pointer;
display: block;
padding: 10px;
width: 320px;
border: 0px;
}

input[type="submit"]:hover {
outline: 2px solid rgb(40, 40, 40);
background: rgb(255, 255, 255);
color: rgb(40, 40, 40);
}

.register-text {
color: rgb(40, 40, 40);
text-align: center;
margin-top: 10px;
display: block;
}

.register-text a {
color: rgb(40, 40, 40);
}

注册.css

body {
margin: 0px;
padding: 0px;
font-size: 16px;
font-family: 'Open Sans', sans-serif;
}

.navigation {
width: 100%;
height: 70px;
color: rgb(255, 255, 255);
background-color: rgb(40, 40, 40);
}

.navigation > .navigation-logo {
float: left;
height: 40px;
font-size: 28px;
line-height: 35px;
padding: 15px 30px;
}

.navigation > ul {
margin: 0px;
float: right;
padding: 0px;
margin-right: 190px;
list-style-type: none;
}

.navigation > ul > li {
float: left;
}

.navigation > ul > li > .navigation-item {
height: 40px;
margin-left:15px;
line-height: 40px;
padding: 15px 0px;
margin-right: 15px;
position: relative;
display: inline-block;
text-decoration: none;
color: rgb(255, 255, 255);
}

.navigation > ul > li > .navigation-item:before {
left: 0px;
content: "";
width: 100%;
height: 2px;
bottom: 20px;
position: absolute;
visibility: hidden;
background-color: rgb(215, 85, 80);
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s;
}

.navigation > ul > li > .navigation-item:hover:before {
visibility: visible;
-webkit-transform: scaleX(1);
transform: scaleX(1);
}

.navigation > ul > li > .navigation-item:hover {
color: rgb(215, 85, 80);
}

#button {
top: 0px;
right: 0px;
margin-right: 15px;
position: absolute;
}

.btn {
float: right;
outline: none;
cursor: pointer;
font-size: 22px;
margin-top:15px;
margin-left:20px;
margin-right:20px;
padding: 5px 35px;
border-radius: 5px;
position: relative;
display: inline-block;
text-decoration: none;
color: rgb(255, 255, 255);
transition: all 0.3s ease-in-out;
background-color: rgb(40, 40, 40);
border: 2px solid rgb(255, 255, 255);
}
.btn:hover {
color: rgb(40, 40, 40);
background-color: rgb(255, 255, 255);
}

form {
position: absolute;
right: 0px;
left: 0px;
top: 40%;
}

input[type="text"], input[type="password"] {
border: 2px solid rgb(40, 40, 40);
margin: 10px auto;
display: block;
outline: none;
padding: 10px;
width: 300px;
}

input[type="submit"] {
transition: all 0.3s ease-in-out;
outline: 2px solid rgb(40, 40, 40);
background: rgb(40, 40, 40);
color: rgb(255, 255, 255);
margin: 0px auto;
margin-top: 10px;
cursor: pointer;
display: block;
padding: 10px;
width: 320px;
border: 0px;
}

input[type="submit"]:hover {
outline: 2px solid rgb(40, 40, 40);
background: rgb(255, 255, 255);
color: rgb(40, 40, 40);
}

.register-text {
color: rgb(40, 40, 40);
text-align: center;
margin-top: 10px;
display: block;
}

.register-text a {
color: rgb(40, 40, 40);
}

最佳答案

  1. 检查DOCTYPE,在注册时你有<!DOCTYPE html> , 在索引 <DOCTYPE html> .
  2. 引号可以互换,但最好使用一种类型。 "' ,而不是两者。
  3. 我已将 register.css 内容替换为 index.css 内容,并且导航栏再次正常工作。如我所见 – 问题出在 register.css 中:

    form {
    position: absolute;
    right: 0px;
    left: 0px;
    top: 40%;
    }

    这就是真正的问题所在。

使用 form例如,您正在更改两种(原文如此!)形式,而不是类。首先是你想要的,其次是 <nav class="navigation"> 中的那个!这样做时只需使用类,一切都会很好;)

例如register.css:

    .registerForm {
position: absolute;
right: 0px;
left: 0px;
top: 40%;
}

并注册html:

    <form class="registerForm" action="http://www.abyssallogin.hol.es/login/register" method="POST">
  1. 你应该那样做的一切。在 css 中使用 html 标签并不是一个好主意。使用 id、class,并保持简单。 index.css 和 register.css 几乎是一样的。您可以导入多个 css 文件——使用该功能!只有这样 css 才真正有意义 ;)

关于php - 导航项只能在元素下点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43815917/

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