[英]Changing CSS from HTML that's in PHP
I made HTML Elements in php by echoing it;我通过回显在 php 中制作了 HTML 元素; I wanted to change the css of that html, but it didn't work.
我想更改该 html 的 css,但是没有用。 I was wondering if you could do this?
我想知道你能不能做到这一点?
} 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>';
}
.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;
}
First of all, you have a syntax error in your HTML:首先,您的 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:您的 CSS 工作正常,但它什么也没做,因为:
For .dropdown-content
you use display:none
.对于
.dropdown-content
您使用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.但是 dropdown-content 不是 dropdown-toggle 的子项,所以这什么都不做。 Fix it by changing it to this (also, see this jsfiddle ):
通过将其更改为此来修复它(另请参阅此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.
请参阅此jsfiddle以了解其实际效果。
The only other CSS that is not about .dropdown-content
is .dropdown-toggle:hover .dropbtn
, but there is no element with class dropbtn..唯一与
.dropdown-content
.dropdown-toggle:hover .dropbtn
CSS 是.dropdown-toggle:hover .dropbtn
,但没有类 dropbtn. 的元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.