jquery - 谷歌翻译小部件移动溢出

标签 jquery css google-translate

我的网站上的谷歌翻译插件遇到了一些问题。它在桌面模式下看起来很好,但当我向下移动到移动设备时,下拉列表的宽度超过了浏览器宽度。 enter image description here

有什么办法可以防止这种情况发生吗?

最诚挚的问候

最佳答案

由于您无法将 css 添加到不存在的元素,因此您必须在单击翻译下拉 CTA 后添加它。这个 jquery 对我有用。

$('body').click('#google_translate_element', function () {
    if (($goog = $('.goog-te-menu-frame').contents().find('body')).length) {
        var stylesHtml = '<link rel="stylesheet" href="/css/google-translate.css">';
        $goog.prepend(stylesHtml);
    }
});

有了这个CSS。

.goog-te-menu2 {
    width: 300px!important;
    height: 300px!important;
    overflow: auto!important;
}
.goog-te-menu2 table,
.goog-te-menu2 table tbody,
.goog-te-menu2 table tbody tr {
    width: 100%!important;
    height: 100%!important;
}
.goog-te-menu2 table tbody tr td {
    width: 100%!important;
    display: block!important;
}
.goog-te-menu2 table tbody tr td .goog-te-menu2-colpad {
    visibility: none!important;
}

关于jquery - 谷歌翻译小部件移动溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38182485/

相关文章:

css - 如何在 GWT 中设置 Anchor 的样式?

c# - 反序列化 jSON Google AJAX 翻译 API

javascript - Fancybox 没有导航按钮,但有画廊作品

javascript - 确保某个脚本在另一个脚本之前加载

css - 如何让元素拉伸(stretch)到填充宽度?

javascript - 检索具有特定类的 <li> 元素的 id

python - 为什么 "Googletrans.Translator"突然停止工作?

java - 缺少有关 Google Translation API 客户端问题的有效 API key ?

javascript - 如何提交表单然后让浏览器返回到页面上的同一位置?

javascript - 获取存储在DOM中的多张图片的宽度