1

I made HTML Elements in php by echoing it; I wanted to change the css of that html, but it didn't work. I was wondering if you could do this?

The PHP

                }  else {

                    include("steamauth/SteamConfig.php");
                    include('steamauth/userInfo.php'); //To access the $steamprofile array
                    //Protected content
                    echo '<div class="dropdown">';
                    echo '<a class="dropdown-toggle" href="#">';
                    echo '<img src="'.$steamprofile['avatar'].'" height="30" style="border-radius: 100%;">';
                    echo '</a>';
                    echo '<div class="dropdown-content">';
                    echo '<a class="logout" href="'.$steamauth['logoutpage'].'"</a>';
                    echo '</div>';                  
                    echo '</div>';
                } 

The CSS

.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}

.dropdown-content a:hover {background-color: #f1f1f1}

.dropdown-toggle:hover .dropdown-content {
     display: block;
}

.dropdown-toggle:hover .dropbtn {
    background-color: #3e8e41;
}
1
  • remember that css+html is a browser/client-side thing. doesn't matter than the html is generated by php - the browser doesn't see ANY Of the php, just the html that php generated. if the css isn't working with the html, then you're generating incorrect html, or the css is incorrectly written. Commented Apr 19, 2016 at 16:57

1 Answer 1

1

First of all, you have a syntax error in your HTML:

echo '<a class="logout" href="'.$steamauth['logoutpage'].'"</a>';

Should be

echo '<a class="logout" href="'.$steamauth['logoutpage'].'">Logout</a>';

Your CSS is working fine, it just doesn't do anything because:

For .dropdown-content you use display:none. So the link is hidden.

Also, you are trying to display the dropdown-content by doing this:

.dropdown-toggle:hover .dropdown-content {
    display: block;
}

But dropdown-content is no child of dropdown-toggle so this does nothing. Fix it by changing it to this (also, see this jsfiddle):

.dropdown-toggle:hover ~ .dropdown-content {
    display: block;
}

However, with this approach you can't click to the link as you won't be hovering dropdown-toggle anymore. Best option is to place dropdown-content inside dropdown-toggle. See this jsfiddle to see that in action.

The only other CSS that is not about .dropdown-content is .dropdown-toggle:hover .dropbtn, but there is no element with class dropbtn..

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

2 Comments

Thanks for that :) but it dosen't work? it does not make a drop down and show the logout button?
Thanks :) but i cant indent the elements as its in php?

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.