0

Is there a different way to reference an 'a class' within an SQL call for separate .css files? I can't get my CSS to style a link(3rd line from bottom in function) Edit: Seems like CSS being overruled error, 2nd picture

chrome tools

dev tools css

CSS;

.toggleFollow {
  color: blue;
  text-decoration: underline;
  cursor: pointer;
}

Function;

  function displayTweets($type) {

    global $link;

    if ($type == 'public'){
      $whereClause = "";
    }

    $query = "SELECT * FROM tweets ".$whereClause." ORDER BY 'datetime' DESC LIMIT 10";

    $result = mysqli_query($link, $query);

    if (mysqli_num_rows($result) == 0) {
      echo "No Tweets";
    } else {
      while ($row = mysqli_fetch_assoc($result)) {

        $userQuery = "SELECT * FROM users WHERE id = ".mysqli_real_escape_string($link, $row['userid'])." LIMIT 1";
        $userQueryResult = mysqli_query($link, $userQuery);
        $user = mysqli_fetch_assoc($userQueryResult);

        echo "<div class='tweet'><p><strong>".$user['email']." </strong><span class='time'> - ".time_since(time() - strtotime($row['datetime']))." ago</span></p>";

        echo "<p>".$row['tweet']."</p>";
        echo "<p><a class='toggleFollow' data-userid='".$row['userid']."'>Follow</a></p></div>";
      }
    }
1
  • you need to learn about mysql joins Commented Nov 29, 2017 at 21:54

2 Answers 2

3

The problem is that you're echoing <a class'toggleFollow'>, which is invalid markup.

In order for the CSS selector .toggleFollow to correctly target it, you need to add the equals sign after class:

<a class='toggleFollow'>

You can validate that you have valid markup with the W3C Validation Service (which supports direct input), which will actually warn you of missed equals signs for attribute values:

Have you forgotten the "equal" sign marking the separation between the attribute and its declared value? Typical syntax is attribute="value".

Assuming this does not resolve the issue, there are only four possible other causes of the problem. Here are the four possible problems, and their respective solutions:

  • The most likely culprit is that you have cached the old HTML markup. This can be resolved by holding CTRL and pressing F5, which will refresh the DOM. This will add the equals sign to the markup, and also update the link to the CSS file if it has been modified.

  • It's possible that the CSS itself got cached, before you added the valid .toggleFollow selector. You can refresh the CSS cache (which is separate to the browser cache!) by holding SHIFT while clicking on the refresh icon.

  • Another culprit could be one of specificity. Ensure that the .toggleFollow selector is not being overridden by a selector with higher specificity. You can check the specificity with the F12 Developer Tools. The lines with strikes through them are being overridden.

  • Least likely, it's possible that your CSS file isn't actually being referenced incorrectly. Ensure that you're actually loading it correctly by using the F12 Developer Tools to see if you are getting a 404 when attempting to load it.

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

5 Comments

Thanks for the link. I added the "=" but it didn't solve my problem?
^ It's possible that caching is an issue as well. I'll update my answer to cover this as well, bear with me.
I tried CTRL f5 on Chrome and tried Firefox too, I updated my question
^ That rules out the most likely culprit, though there are three other possible problems. I've updated my answer to cover each, and their respective solutions :)
It seems like the css is being out ruled? I updated question ty for everything so far
2
class'toggleFollow'

should be

class='toggleFollow'

Update - you need to look at CSS Specificity as @Obsidian mentioned

.tweet a.toggleFollow {
     color: blue;
}

You can also use !important

.tweet a.toggleFollow {
     color: blue!important;
 }

4 Comments

Have you used the developer tools to see if the CSS class is being pulled through? you might need to clear the browser cache. If you are using chrome hold Ctrl and press F5.
I tried both. I've updated my question with Chrome screenshot
Is the html source outputting the class name?
.tweet a.toggleFollow should do the trick, you need to target that specific element

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.