html - 如何设置 google cse 样式

标签 html css google-custom-search

我从谷歌获得了这段代码,但我无法设置它的样式,我在我网站的 css 中添加了新规则,但它不听它并用谷歌的默认设置覆盖它,我能用它做什么让它看起来像我想要的那样,而不是谷歌如何计划它?

那是我的 css 被忽略了

.cse .gsc-control-cse, .gsc-control-cse {
  background-color: transparent;
  border: none;
  width: 280px;
}

这就是 google cse 代码

<script>
  (function() {
    var cx = '013795634587489910289:wcfxuut_dc8';
    var gcse = document.createElement('script');
    gcse.type = 'text/javascript';
    gcse.async = true;
    gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
        '//cse.google.com/cse.js?cx=' + cx;
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(gcse, s);
  })();
</script>
<gcse:search></gcse:search>

最佳答案

尝试添加您的样式表

.cse .gsc-control-cse, .gsc-control-cse {
  background-color: transparent;
  border: none;
  width: 280px;
}

样式是 google 的 css。

例如你的 html 可能看起来像这样:

<link rel="stylesheet" href="https://cloud.google.com/compute/style.css" type="text/css">
<link rel="stylesheet" href="style/page.css" type="text/css">

其中 https://cloud.google.com/compute/ 包含 google gcs 的样式,而 style/page.css 包含 。 cse .gsc-control-cse, .gsc-control-cse { ... } 样式。

作为最后的尝试,仅在必须时使用:

(感谢@MrUpsidown 指出这个方法是 inherently bad )
在每个 CSS 规则后添加 !important:

.cse .gsc-control-cse, .gsc-control-cse {
  background-color: transparent !important;
  border: none !important;
  width: 280px !important;
}

!important css 声明用于覆盖应用于同一元素的另一种样式。 更多信息在这里:http://www.webcredible.com/blog-reports/web-dev/css-important.shtml

关于html - 如何设置 google cse 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30547490/

相关文章:

html - 如何将三个 div 合并为一个以共享背景?

html - 如何阻止容器 div 允许内容溢出?

jquery - 单击时显示/隐藏按钮上方的内容

css - 选择菜单未正确显示

search - 如何将集成的 Google 搜索添加到我的网站?

r - 需要通过 R 访问 Google Custom search api

html - 居中子元素和工具提示,绝对定位,具有流体宽度,相对于较小尺寸的父元素

php - 如果用户点击浏览器按钮如何显示消息?

html - 列表中的有效列表 - ul 中的 ul

javascript - 如何将 'clear results' 按钮移动到 Google 的 CSE 中的结果?