1

I have a website that displays a list of user accounts on the left side going down in a list that are clickable (hyperlinks) that take you to the user's profile page. Also, I have a search field (form) in the middle of the page where users can just search for someone. However, because of that search field, the usernames displayed on the left side that are aligned with this field are broken, you cannot click on them anymore. The hyperlinks that are not aligned with the search field and are under the alignment of it work. After troubleshooting, I found out that this field in my CSS code was the cause of it: position: absolute;

Taking that field out of the CSS code breaks the position of my search field in the middle of the page and it gets placed at the bottom of the page.

I don't know how to fix this problem without breaking the positioning of my content on the page.

My code:

<?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: THIS IS THE CSS FOR THE SEARCH FIELD IN THE MIDDLE OF THE PAGE

.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: THIS IS THE CSS FOR THE LIST OF USERS ON THE LEFT SIDE OF THE PAGE

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

1 Answer 1

1

There isn't a whole lot of info supplied and its hard to visualize without an image but my guess would be a z-index issue.

Below you can see that the div goes from left to right(width 100%). I assume that this div is sitting on top of your userList div based on the supplied css. This means you probably cant click the hyperlinks below the 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%;
}

Try setting a z-index to the userlist div that is higher than the searchList so that you are able to click on the hyperlinks.

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

Absolute positioning is centering the searchList div in center without effecting other divs in the body. When you remove it, then the searchList div moves to the bottom because that is its location in the body.

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks for the help, really appreciate it! I'm a beginner with all this and I'm not 100% sure on how to set the a-z index to the userlist div, would you possibly help me on that? Also, here's a screenshot of how the web page looks: gyazo.com/51acddbdd6c2fa6f7de94c89bf24e720
Yep, in that second code snippet i added it in for youm. All u need is that last linem. U can copy andnpast that entire userlist class and replace it with thenkne younhave.
Unfortunately, I'm still getting the same issue :(
What u can do just to help test is color the backfroung of the search div. Frlm there it should be visually easier ehen you can see itm. Then you can work with thebz-index a little to get the userlist class on top.
ahhh the problem is visible now, would you know how to fix it? I have no clue lol, gyazo.com/247fb114e46af4e07ef10e058992e63b
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.