Customizing Google Translator drop down

我们两清 提交于 2019-12-19 02:28:50

问题


I have a website and in this website am adding google translator so that people can see website in different languages

The code that i have added is

<div id="google_translate_element"></div>
<div id="language"></div>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({
    pageLanguage: 'en', includedLanguages: 'bn,en,kn', layout: google.translate.TranslateElement.InlineLayout.SIMPLE
}, 'google_translate_element');
}
</script>
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

Now i want to customize the drop down like background color , text color, text size and width how can i do this

Please Help Me

I tried of giving the drop-down opacity 0 and placing my drop down on the same place so that it acts same but its not working....


回答1:


I know this is an old post, but I'm sharing my solution here for others who, like me, had/will have the same problem.

The drop down is inside an iframe, so specifying its CSS on your page alone will not help. Here's how I styled my Google Translator drop down menu with jQuery:

$('document').ready(function () {
    $('#google_translate_element').on("click", function () {

        // Change font family and color
        $("iframe").contents().find(".goog-te-menu2-item div, .goog-te-menu2-item:link div, .goog-te-menu2-item:visited div, .goog-te-menu2-item:active div, .goog-te-menu2 *")
            .css({
                'color': '#544F4B',
                'font-family': 'tahoma'
            });

        // Change hover effects
        $("iframe").contents().find(".goog-te-menu2-item div").hover(function () {
            $(this).css('background-color', '#F38256').find('span.text').css('color', 'white');
        }, function () {
            $(this).css('background-color', 'white').find('span.text').css('color', '#544F4B');
        });

        // Change Google's default blue border
        $("iframe").contents().find('.goog-te-menu2').css('border', '1px solid #F38256');

        // Change the iframe's box shadow
        $(".goog-te-menu-frame").css({
            '-moz-box-shadow': '0 3px 8px 2px #666666',
            '-webkit-box-shadow': '0 3px 8px 2px #666',
            'box-shadow': '0 3px 8px 2px #666'
        });
    });
});



回答2:


FOR DROPDOWN language LINK COLOR :

simply add this script into head ..

<script>
var $jt = jQuery.noConflict();
$jt('document').ready(function () {

    $jt('#google_translate_element').on("click", function () {

var $frame = $jt('.goog-te-menu-frame:first');
$frame.contents().find(".goog-te-menu2-item div")
            .css({
                'color': '#544F4B',
                'font-family': 'tahoma',

  }).hover(function(){
   $jt(this).css("background","#eeeeee");
  },function(){
   $jt(this).css("background","");
  }); 
   });
});
</script>


来源:https://stackoverflow.com/questions/11881361/customizing-google-translator-drop-down

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!