【问题标题】:CSS/HTML Hyperlinks Break From Form CSSCSS/HTML 超链接脱离表单 CSS
【发布时间】:2018-09-25 13:14:53
【问题描述】:

我有一个网站,它会在左侧显示用户帐户列表,这些用户帐户在可点击的列表(超链接)中向下显示,可将您带到用户的个人资料页面。此外,我在页面中间有一个搜索字段(表单),用户可以在其中搜索某人。但是,由于该搜索字段,左侧显示的与该字段对齐的用户名已损坏,您无法再单击它们。未与搜索字段对齐并在其对齐下​​的超链接有效。经过排查,我发现我的CSS代码中的这个字段是造成它的原因:position: absolute;

从 CSS 代码中取出该字段会破坏我的搜索字段在页面中间的位置,并将其放置在页面底部。

我不知道如何在不破坏我的内容在页面上的定位的情况下解决此问题。

我的代码:

<?php
include('init.inc.php');

$output = '';

if(isset($_POST['search'])){
    $searchq = $_POST['search'];
    $searchq = preg_replace("#[^0-9a-z]#i","",$searchq); //filter, can remove

    $query = mysql_query("SELECT * FROM users WHERE user_first LIKE '%$searchq%' OR user_last LIKE '%$searchq%' OR user_uid LIKE '%$searchq%'");
    $count = mysql_num_rows($query);

    if($count == 0){
        $output = 'There was no search found!';
    }else{
        while($row = mysql_fetch_array($query)){
            $uname = $row['user_uid'];
            $fname = $row['user_first'];
            $lname = $row['user_last'];
            $email = $row['user_email'];
            $id = $row['user_id'];

            $output .= '<div> '.$uname.' '.$fname.' '.$lname.' '.$email.'</div>';
        }
    }

}
?>

<!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns=""http://www.w3.org/1999/xhtml>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <link rel="stylesheet" href="./css/style.css">
  </head>
  <body>
  <section id="showcase1">
     <section id="newsletter">
      <div class="container">
        <h1>ProjectNet Members:</h1>
      </div>
      </section>
      <div class="container">
    <div class="userList">
        <?php
            foreach (fetch_users() as $user){
                ?>
                <p>
                    <button><a class="userList" href="profile.php?uid=<?php echo $user['id']; ?>"><?php echo $user['username']; ?></a></button>
                </p>
                <?php

            }
        ?>
    </div>
    </div>
            <div class="searchList">
        <h2>Search for members</h2>
        <form id="search" action="user_list.php" method="post">
            <input type="text" name="search" placeholder="Search for members..." />
            <input type="submit" value="Search" />
        </form>
        <?php print("$output");?>
    </div>
    </section>
  </body> 
</html>

CSS: 这是页面中间的搜索字段的 CSS

.searchList {
    color: #ffffff;
    text-decoration: none;
    font-weight: bold;
    font: 19px Arial, Helvetica,sans-serif;
    text-align: center;
    line-height: 35px;
    margin: auto;
    margin-top: -100px;
    position: absolute;
    top: 45%;
    width: 100%;

}


#search input[type="submit"] {
    cursor: pointer;

    border: none;
    background: #fafafa;
    color: #333;
    font-weight: bold;
    margin: 0 0 5px;
    padding: 3px;
    font-size: 15px;
    font: Arial, Helvetica,sans-serif;
}
#search input[type="text"] {
    width: 18%;
    border: 1px solid #CCC;
    background: #FFF;
    margin: 0 0 5px;
    padding: 4px;
}

#search input[type="submit"]:hover {
    background: #e8491d;
    color: #fafafa;
    -webkit-transition: background 0.3s ease-in-out;
    -moz-transition: background 0.3s ease-in-out;
    transition: background-color 0.3s ease-in-out;
}

CSS: 这是页面左侧用户列表的 CSS

.userList {
    color: #ffffff;
    text-decoration: none;
    font-weight: bold;
    font: 20px Arial, Helvetica,sans-serif;
    margin: auto;
}
.userList button {
    background: #333;
    width: 20%;
}

【问题讨论】:

    标签: php html css alignment


    【解决方案1】:

    提供的信息并不多,如果没有图像就很难可视化,但我猜可能是 z-index 问题。

    您可以在下面看到 div 从左到右(宽度 100%)。我假设这个 div 基于提供的 css 位于您的 userList div 之上。这意味着您可能无法单击 searchList div 下方的超链接。

    .searchList {
        color: #ffffff;
        text-decoration: none;
        font-weight: bold;
        font: 19px Arial, Helvetica,sans-serif;
        text-align: center;
        line-height: 35px;
        margin: auto;
        margin-top: -100px;
        position: absolute;
        top: 45%;
        width: 100%;
    }
    

    尝试将 z-index 设置为高于 searchList 的用户列表 div,以便您能够单击超链接。

    .userList {
        color: #ffffff;
        text-decoration: none;
        font-weight: bold;
        font: 20px Arial, Helvetica,sans-serif;
        margin: auto;
        z-index: 1000;
    }
    

    绝对定位是将searchList div居中而不影响body中的其他div。当您删除它时,searchList div 将移动到底部,因为那是它在正文中的位置。

    【讨论】:

    • 感谢您的帮助,非常感谢!我是所有这一切的初学者,我不确定如何将 a-z 索引设置为用户列表 div,你能帮我吗?另外,这是网页外观的屏幕截图:gyazo.com/51acddbdd6c2fa6f7de94c89bf24e720
    • 是的,在第二个代码 sn-p 中,我为你添加了它。你需要的只是最后一条线。你可以复制并粘贴整个用户列表类,然后用 thennkne younhave 替换它。
    • 不幸的是,我仍然遇到同样的问题:(
    • 你可以做的只是帮助测试是为搜索 div 的背景上色。在那里你可以看到它应该在视觉上更容易。然后,您可以稍微使用一下 bz-index 以将 userlist 类放在首位。
    • 啊,问题现在可见,您知道如何解决吗?我不知道大声笑,gyazo.com/247fb114e46af4e07ef10e058992e63b
    猜你喜欢
    • 2023-03-26
    • 2021-06-20
    • 2013-03-13
    • 2018-04-02
    • 2018-01-14
    • 2013-12-18
    • 2016-07-14
    • 2013-08-27
    • 1970-01-01
    相关资源
    最近更新 更多