gpt4 book ai didi

jquery - 通过 jQuery 添加内联 CSS

转载 作者:技术小花猫 更新时间:2023-10-29 12:01:38 24 4
gpt4 key购买 nike

我不太了解 jQuery,所以我不知道如何添加内联 CSS。这是我的代码:

<div class="gm-style-iw" style="top: 9px; position: absolute; left: 15px; width: 23px;">
<div style="display: inline-block; overflow: hidden; max-height: 330px; max-width: 176px;">
<div style="overflow: auto">
<div id="iw-container">
</div>
</div>
</div>
</div>

我想更改第二个 div 的 max-width 并将 overflow: none 添加到 #iw-container 上面的 div。

我试过了,但没用:

var iwOuter = $('.gm-style-iw');
iwOuter.children().css({max-width:'250px !important'});
iwOuter.children().children().css({overflow:'none'});

编辑 我想自定义 infowindow Google,对我来说更改 max-width 和 overflow 的值很重要....我认为您的代码可能不错,但我不认为了解为什么不起作用...

最佳答案

在 jQuery 中你可以这样做:

$('.gm-style-iw > div').css('max-width', "250px !important");
$('#iw-container').parent().css('overflow', 'none');//css wasn't valid here

使用 > div 意味着它只获取第一个 div,如果你想让所有的 div 都有一个 max-width,使用:

$('.gm-style-iw').children().css('max-width', "250px !important");

使用.parent() 函数意味着它只获取所选元素的父元素。它更清晰、更易于阅读,而且编写起来更简短。

关于jquery - 通过 jQuery 添加内联 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29893578/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com