使用:hover作为元素的内联样式(使用HTML / CSS / php) [英] Using :hover for an element's inline style (using HTML/CSS/php)

查看:622
本文介绍了使用:hover作为元素的内联样式(使用HTML / CSS / php)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能的重复项:



如何写入:hover in inline CSS?

我想动态更改元素的悬停颜色,但不使用外部CSS样式表,只是内联。这是代码(使用php生成元素)

I want to dynamically change the hover colour of an element, but not using external CSS stylesheets, only inline. This is the code (using php to generate the element)

echo '
<div class="container" style="color:#'.$color.'">
  '.$contents.'
</div>';

当用户将鼠标悬停在此容器元素上时,颜色样式将更改为 $ color (暂时没有悬停)。

When the user hovers over this container element, the color style will change to the value of $color (at the moment there is no hovering).

任何帮助都会感激。

推荐答案

这将帮助你,如果javascript是可感知的

This will help you if javascript is appreciable

<TD onMouseOver="this.bgColor='#00CC00'" onMouseOut="this.bgColor='#009900'" bgColor=#009900>
<A HREF="http://www.mysite.com">Click Here</A></TD>


b $ b Javascript变更超链接文字颜色Onmouseover

Javascript Change Hyperlink Text Color Onmouseover

<style type="text/css">

a {
font-weight:bold;
font-family:verdana;
text-decoration:none;
}

</style>

<script type="text/javascript" language="javascript">
function changeColor(idObj,colorObj)
{
    document.getElementById(idObj.id).style.color = colorObj;
}
</script>

<a href="#" style="color: #000000" onmouseover="this.style.color='#FF0000'" onmouseout="this.style.color='#000000'">
    Link 1</a>
<br />
<br />
<a href="#" style="color: #999999" onmouseover="this.style.color='#008000'" onmouseout="this.style.color='#999999'">
    Link 2</a>
<br />
<br />
<a href="#" style="color: #FF0000" onmouseover="this.style.color='blue'" onmouseout="this.style.color='#FF0000'">
    Link 3</a>
<br />
<br />
<a id="lnk1" href="#" style="color: #008000" onmouseover="changeColor(this,'#FF0000');"
    onmouseout="changeColor(this,'#008000');">Link Color change using javascript function</a>


这篇关于使用:hover作为元素的内联样式(使用HTML / CSS / php)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆