简体   繁体   English

如何重新加载css样式表

[英]How to reload the css stylesheet

Probably the answer to my question is simple, but I have not found the answer. 可能我的问题的答案很简单,但我没有找到答案。 I would like to know whether I can call a "className".css file in a mouseover(mouseout) function. 我想知道我是否可以在mouseover(mouseout)函数中调用“className”.css文件。 For example: 例如:

<div id="thing" class="classes" onmouseover="????call the .css file???">My Name</div>

I dont want to write: onmouseover = "style.color:'blue'" ... 我不想写: onmouseover = "style.color:'blue'" ......

Let me explain why I want this. 让我解释为什么我想要这个。 Lets say I have a NAME.css file. 假设我有一个NAME.css文件。 This css will make the word "My name" turn into red color. 这个CSS会使“我的名字”这个词变成红色。

I have this html /// 我有这个HTML ///

<div id="thing" class="classes" onmouseover="this.style.color='blue'">My Name</div><br>

/// ///

I thought that once the mouse is out, the word "My Name" will be red again(this because of the css file), but it is not. 我以为一旦鼠标出来,“我的名字”这个词将再次变红(这是因为css文件),但事实并非如此。 Is it possible to write something like this?: 是否可以写这样的东西?:

My Name 我的名字

I dont want to write this: 我不想写这个:

 <div id="thing" class="classes" onmouseover="this.style.color='blue'" onmouseout = "this.style.color='red'">My Name</div> 

Hope it is clear and understandable. 希望它清楚易懂。 Any help will be appreciated. 任何帮助将不胜感激。

Thanks Joel 谢谢乔尔

Use the :hover pseudo class instead in CSS. 在CSS中使用:hover伪类。

.classes:hover {
    color: blue;
}

All you need is a css property in css 你需要的只是css中的css属性

div#thing{
    color: red;
}
div#thing:hover{
    color: blue;
}

Yeah it is possible, use the :hover pseudoselector: 是的,有可能,使用:hover pseudoselector:

#thing { color: red; }
#thing:hover { color: blue; }

JSFiddle Demo JSFiddle演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM