我在html文件中进行了标头设计,并且一切正常,但是当我将其放在.php文件中时,它们变得像闲置状态,因此无法单击或将它们悬停。 PHP代码:
<?php
session_start();
require_once "stuff.php";
if (isset($_SESSION['encnick'])){
header("Location: my.php");
return;
}
//On form submit
if (isset($_POST['register'])){
if (!isset($_POST['nick'])){
$_SESSION['error'] = "Nickname is required";
header("Location: register.php");
return;
}
if (!isset($_POST['password'])){
$_SESSION['error'] = "Password is required";
header("Location: register.php");
return;
}
if (!isset($_POST['cpassword'])){
$_SESSION['error'] = "Password is required";
header("Location: register.php");
return;
}
if ($_POST['password'] !== $_POST['cpassword']){
$_SESSION['error'] = "Passwords don't match";
header("Location: register.php");
return;
}
else{
$statement = $pdo->prepare("SELECT * FROM users WHERE nick = :nick");
$statement->execute(array(':nick' => $_POST['nick']));
$row = $statement->fetch(PDO::FETCH_ASSOC);
if ($row['nick'] === $_POST['nick']){
$_SESSION['error'] = "This nickname is already taken";
header("Location: register.php");
return;
}
$statement = $pdo->prepare("INSERT INTO users (nick, password, company, encodednick, user_group) VALUES (:nick, :password, :company, :encodednick, :user_group)");
$statement->execute(array(
':nick' => htmlentities($_POST['nick']),
':password' => password_hash($_POST['password'], PASSWORD_BCRYPT),
':company' => htmlentities($_POST['company']),
':encodednick' => md5($_POST['nick']),
':user_group' => "user"
));
$_SESSION['encnick'] = md5($_POST['nick']);
$encnick = $_SESSION['encnick'];
header("Location: my.php?id=$encnick");
return;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>ReactSynchro</title>
<link rel="stylesheet" href="css/register.css">
<link rel="stylesheet" href="css/fonts.css">
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<?php printheader() ?>
<div id="formdiv">
<form method="post">
<label for="nick">Nickname</label>
<input type="text" name="nick" id="nick" placeholder="Enter unique nickname" minlength="6" maxlength="30" required>
<label for="password">Password</label>
<input type="password" name="password" id="password" placeholder="Enter password" minlength="8" maxlength="60" required>
<label for="cpassword">Confirm Password</label>
<input type="password" name="cpassword" id="cpassword" placeholder="Confirm password" minlength="8" maxlength="50" required>
<label for="company">Company</label>
<input type="text" name="company" id="company" placeholder="Enter your company" minlength="3" maxlength="50">
<input type="submit" value="Register" name="register" id="regbtn">
</form>
</div>
<?php
if (isset($_SESSION['error'])){
echo "<h2 id='errormessage'>".$_SESSION['error']."</h2>";
unset($_SESSION['error']);
}
?>
</body>
</html>
main.css代码:
body{
background-color: #333;
margin: 0;
}
#header{
width: 100%;
position: fixed;
top: 0;
left: 0;
right: 0;
background-color: #444;
height: 110px;
}
#header img{
height: 100px;
position: relative;
left: 5px;
top: 5px;
bottom: 5px;
}
#header a{
color: white;
text-decoration: none;
display: block;
position: relative;
float: left;
text-align: center;
margin: 5px;
padding: 5px;
border: 0.5px solid white;
font-family: 'Ubuntu';
font-size: 20px;
-webkit-transition: background-color 200ms linear;
-ms-transition: background-color 200ms linear;
transition: background-color 200ms linear;
-moz-transition: background-color 200ms linear;
-o-transition: background-color 200ms linear;
}
#hlinks1{
position: relative;
left: 120px;
top: -71px;
}
#hlinks2{
position: absolute;
right: 5px;
top: 50%;
transform: translateY(-50%);
}
#hlinks2 a{
background-color: rgba(255, 140, 0, 0.9);
}
#hlinks1 a:hover{
background-color: rgba(255, 255, 255, 0.1);
}
#hlinks2 a:hover{
background-color: rgba(255, 140, 0, 1);
}
#errormessage{
color: red;
text-align: center;
font-family: 'Ubuntu';
}
@media all and (max-width: 537px){
#hsupbtn{
visibility: hidden;
}
}
@media all and (max-width: 440px){
#hregbtn{
visibility: hidden;
}
}
register.css代码:
#formdiv{
width: 50%;
height: 350px;
position: absolute;
left: 0;
right: 0;
margin: auto;
top: 50%;
transform: translateY(-50%);
border: 0.5px solid white;
max-width: 500px;
min-width: 250px;
}
#formdiv label{
text-align: center;
font-family: 'Ubuntu';
color: white;
width: 100%;
display: block;
font-size: 24px;
line-height: 50px;
}
#formdiv input{
width: 90%;
position: relative;
margin: auto;
display: block;
font-family: 'Ubuntu';
line-height: 20px;
}
#regbtn{
width: 50% !important;
top: 20px;
background-color: rgba(255, 140, 0, 0.9);
color: white;
-webkit-transition: background-color 200ms linear;
-ms-transition: background-color 200ms linear;
transition: background-color 200ms linear;
-moz-transition: background-color 200ms linear;
-o-transition: background-color 200ms linear;
}
#regbtn:hover{
background-color: rgba(255, 140, 0, 1);
}
#formdiv input:empty{
border: 0.5px solid white;
}
#formdiv input:valid{
border: 0.5px solid green;
}
stuff.php文件中的菜单打印功能:
function printheader(){
echo "<div id='header'>
<img src='images/logo.png'>
<div id='hlinks1'>
<a href='../index.php'>Home</a>
<a href='../about.html'>About</a>
<a href='../support.php' id='hsupbtn'>Support</a>
</div>
<div id='hlinks2'>
<a href='../register.php' id='hregbtn'>Register</a>
<a href='../login.php'>Login</a>
</div>
</div>
<div style='height: 110px; position: relative;'></div>";
}
所以我的意思是,当我悬停或单击链接时,它们什么都没有发生,就像图片一样闲置,但是如果我断开main.css文件的连接,它们将开始正常工作。
答案 0 :(得分:1)
您的打印头功能
<div style='height: 110px; position: relative;'></div>
删除以下内容:-
position: relative