css :悬停时的圆角 div

发布于 2024-07-11 17:09:47 字数 543 浏览 7 评论 0原文

我正在尝试完成一些看起来很简单的事情...

我有 3 个 div,其中包含一个单选按钮和一些内容:

     Content of DIV1,
[]   this can be as long or as tall
     as wanted

[]   Content of DIV2

[]   Content of DIV3

使用 其他帖子在这里。 然而,我无法仅针对悬停事件执行此操作,即我希望仅当鼠标悬停在 div 上时才看到 div 周围出现圆形框。 有没有人在某处看到过这样做的例子?

编辑:我已经在使用 Prototype 和 Scriptaculous。 我不能为此添加 jQuery。

I am trying to accomplish something that seemed quite simple...

I have 3 divs that contain a radiobutton and some content:

     Content of DIV1,
[]   this can be as long or as tall
     as wanted

[]   Content of DIV2

[]   Content of DIV3

It's easy to create rounded corners for each div using any techniques found on other posts here. Yet, I haven't been able to do that only for the hover event, ie I would like to see the rounded box appear around the div only when the mouse hovers over it. Has anyone seen an example of this being done somewhere?

Edit: I'm already using Prototype and Scriptaculous. I can't add jQuery just for this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦冥 2024-07-18 17:09:48

这会在 div 悬停时使用 jquery 更改 CSS

print("<div id="output" class="div"></div>



<script>

    jQuery(document).ready(function() {

    $("#output").hover(function() {
        $(this).css({ 'background-color': 'yellow', 'font-weight': 'bolder' });
    }, function() {

    $(this).css({ 'background-color': 'blue', 'font-weight': 'bolder' });
    });


    }
    );

");

this changes the CSS with jquery on the hover of a div

print("<div id="output" class="div"></div>



<script>

    jQuery(document).ready(function() {

    $("#output").hover(function() {
        $(this).css({ 'background-color': 'yellow', 'font-weight': 'bolder' });
    }, function() {

    $(this).css({ 'background-color': 'blue', 'font-weight': 'bolder' });
    });


    }
    );

");

微凉徒眸意 2024-07-18 17:09:48

您可能遇到的部分问题在于,在大多数 CSS 实现(以及该技术的浏览器实现)中,div 没有可以附加样式规则的 :hover 方法。

正如 Antony 提到的,jQuery 或许能够解决这个问题。

我将如何攻击它(因为我还没有探索过 jQuery)是将你的 a 标签(确实有一个悬停方法)设置为 display:block,并将所有伴随规则设置为如果它是一个 div,让它展开以填充包含的 div,然后当然,将圆角规则添加到悬停。

另一种方法是用 a 标签包围您的 div,但话又说回来,您仍然设置 display:block、背景和其他不属于 a 的规则。

这都是对语法的残酷滥用,因此在尝试我建议的任何操作之前请先备份您的工作。

祝你好运 - 始终在 div 上保持圆角可能会更容易,并考虑其他可以做的事情来调出悬停效果。

Part of the problem you might be having lies in the fact that in most implementations of CSS (and the browser's implementation of that technology), a div doesn't have a :hover method that you can attach style rules to.

As Antony mentioned, jQuery might be able to get around this.

How I would attack it (since I haven't explored jQuery) is to set your a tag (which does have a hover method) to display:block, with all of the attendant rules you would set as if it were a div, make it expand to fill the containing div, and then of course, add your rounded corner rules to the hover.

Another way is to surround your div with the a tag, but then again, you're still setting display:block, background and other rules that don't really belong in a.

This is all a brutal abuse of the syntax, so back up your work before trying anything I suggest.

Good luck - it would probably be easier to just keep it rounded on the div all the time, and think of something else you can do to call out a hover effect.

心不设防 2024-07-18 17:09:48

我相信你可以用 jquery 做到这一点。
http://docs.jquery.com/CSS

http://docs.jquery.com/Events/hover

I am sure you could do it with jquery.
http://docs.jquery.com/CSS

http://docs.jquery.com/Events/hover

猫腻 2024-07-18 17:09:48

CSS 定义了悬停伪选择器,您可以利用它来解决问题,或者使用 javascript 来模拟在 onMouseEnter onMouseOut 事件上向正确的 div 添加/删除 css 类的效果。

Css define the hover pseudo selector you can leverage on it for resolving you problem or use javascript to simulate that effect adding/removing a css class to the correct div on the events onMouseEnter onMouseOut.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文