class - 将鼠标悬停在其他 css 类上时更改类属性

标签 class css html

当悬停类“left1_sub”时,我试图给类“left2”的 div 一个边框半径。

我搜索了很多解决方案,但似乎没有一个适合我。

它的 html:http://web318.login-11.hoststar.at/ben/kleinraum/wp/menuimg/index.html 和完整的 CSS:http://web318.login-11.hoststar.at/ben/kleinraum/wp/menuimg/style.css

.left1_sub{
     padding-top:2%;
     padding-bottom:2%;
     width: 100%;
   float: left;
   background-color: #cccccc
 }



.left1_sub:hover ~ .left2 {border-radius: 10px;}

.left2{

   float: left;
   margin-right: 20px;
   margin-top: 20px;
   width: 500px;
   height:600px;
   background-color: #ccccff
}

只是 self 介绍 css3,如有错误,请见谅。

最佳答案

这可以用 jQuery 或类似的东西很容易地完成。

如果习惯使用 jQuery,这样的东西就可以了。

首先,在 CSS 中创建一个带有边框半径的类:

.rounded { border-radius: 5px; /* (or whatever) */ }

然后,在<script>标签:

jQuery(document).ready(function($) {
     var obj = $('.left1_sub'),
         target = $('.left2');

     obj.hover(
          //mouse in
         function(){
            target.addClass('rounded');
         //mouse out    
         },function(){
            target.removeClass('rounded');
     });

});

http://jsfiddle.net/wGzgB/11/

关于class - 将鼠标悬停在其他 css 类上时更改类属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13566389/

相关文章:

swift - 如何将字典变量放在单独的 swift 文件中?

C# 有没有办法使类中对象的属性在类本身之外不可编辑?

css - 使使用语义 UI 的页面上的所有文本变大

java - 修复 html 中未闭合的标签或使用 HTML 解析器解析以进行 XSLT 转换

html - 停止导致回发的文本框

php - 访问子类中的私有(private)变量

C++类成员

javascript - 尝试使用 javascript/jquery 查找 Canvas 的高度

html - <a> 按钮的位置不固定其位置

javascript - 隐藏和显示 div 不起作用