更改博主和相同标签帖子中搜索结果背景的颜色

如何解决更改博主和相同标签帖子中搜索结果背景的颜色

各位晚安! 我正在博客上创建一个博客,我想根据标签放置背景颜色。 例如:当我搜索一个标签例如:Books 时,所有包含此标签的帖子都会出现,而包含此标签的帖子将以蓝色背景显示。当我打开带有 Books 标签的帖子时,该帖子也必须具有蓝色博客背景。 我试图在英文的 stackoverflow 中找到一个类似的问题,但代码在这里不起作用是链接 Change color by Blogger Tag

但是当我将此代码放在博客上并使用具有适当颜色的标签时,它始终保留最后一组颜色,而不是我想要的每个标签的颜色... 当没有标签时,他会以与没有 if 相同的方式放置颜色。

博主应该保持在侧面每个导航按钮的颜色之上。

enter image description here

当我放置代码时,主页是只有当所有帖子都包含我正在寻找的标签时才应该使用的颜色。

这是主页面

enter image description here

更新: 菜单代码如下:

<!-- https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_sidenav_dropdown -->



<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/fontawesome.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/solid.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/brands.min.css"/>











<!doctype html>


<style>
#mySidenav a {
  position: fixed;
  left: -230px;
  transition: 0.3s;
  padding: 15px;
  width: 270px;
  text-decoration: none;
  font-size: 20px;
  color: white;
  border-radius: 0 5px 5px 0;
}

#mySidenav a:hover {
  left: 0;
}


#search {
  top: 40px;
  background-color: #FFBA99;
}

#home {
  top: 100px;
  background-color: #BA2D26;
}
#about {
  top: 160px;
  background-color: #0055A5;
}

#blog {
  top: 220px;
  background-color: #5F6BB0;
}

#projects {
  top: 280px;
  background-color: #158DA9;
}

#contact {
  top: 340px;
  background-color: #8F2054;
}
#matematica{
  top:400px;
  background-color:#B1BB36;
}



#sheatsheet{
  top:460px;
  background-color:#B80c00;
}

#postsPolulares{
  top:520px;
  background-color:#420085;
}

#arquivos{
  top:580px;
  background-color:#963c00;
}

#contato{
  top:640px;
  background-color:#8a0a83;
}

#sobre{
  top:700px;
  background-color:#006b54;
}
#repositorio{
    top:760px;
  background-color:#000000;
}
#calendario{
    top:820px;
  background-color:#0F89BA;
}

#media{
    top:880px;
  background-color:#EC7650;
}

#books{
    top:940px;
  background-color:#49497F;
}




#rss{
  top:1000px;
  background-color:#D38094;
}


a{
text-align: right;
}


/* Novo estilo*/
*{box-sizing: border-box}

/* Set height of body and the document to 100% */
body,html {
  height: 100%;
  margin: 0;
  font-family: Arial;
}

/* Style tab links */
.tablink {
  background-color: #555;
  color: white;
  float: left;
  border: none;
  outline: none;
  cursor: pointer;
  padding: 14px 16px;
  font-size: 17px;
  width: 25%;
}

.tablink:hover {
  background-color: #777;
}

/* Style the tab content (and add height:100% for full page content) */
.tabcontent {
  color: white;
  display: none;
  padding: 100px 20px;
  height: 100%;
}

#Search {background-color: #FFBA99;}
#Home {background-color: #BA2D26;}
#About {background-color: #0055A5;}
#Blog {background-color: #5F6BB0;}
#Projects {background-color: #158DA9;}
#Contact {background-color: #8F2054;}
#Matematica {background-color:#B1BB36;}
#Sheatsheet  {background-color:#B80c00;}
#PostsPolulares {background-color:#420085;}
#Arquivos {background-color:#963c00;}
#Contato {background-color:#8a0a83;}
#Sobre {background-color:#006b54;}
#Repositorio {background-color:#000000;}
#Calendario {background-color:#0F89BA;}
#Media {background-color:#EC7650;}
#Books {background-color:#49497F;}
#Rss {background-color:#D38094;}
/*#News {background-color: green;}
#Contact {background-color: blue;}
#About {background-color: orange;}*/


/*FIm DO NOVO ESTILO*/


</style>




<div id="mySidenav" class="sidenav">
  <a href="https://www.steamizando.com/p/busca.html" id="search" class="tablink" onclick="openPage('Search',this,'#FFBA99')">Pesquisar <i class="fas fa-search"></i></a>
  <a href="https://www.steamizando.com/p/home.html" id="home" class="tablink" onclick="openPage('Home','#BA2D26')">Home <i class="fas fa-home"></i></a>
  <a href="https://www.steamizando.com/p/ciencia.html" id="about" class="tablink" onclick="openPage('About','#0055A5')"> Ciência <i class="fas fa-microscope"></i> </a>
  <a href="https://www.steamizando.com/p/tecnologia.html" id="blog" class="tablink" onclick="openPage('Blog','#5F6BB0')"> Tecnologia  <i class="fas fa-laptop-code"></i></a>
  <a href="https://www.steamizando.com/p/engenharia.html" id="projects" class="tablink" onclick="openPage('Projects','#158DA9')"> Engenharia <i class="fas fa-tools"></i></a>
  <a href="https://www.steamizando.com/p/artes.html" id="contact" class="tablink" onclick="openPage('Contact','#8F2054')"> Artes  <i class="fas fa-palette"></i></a>
  <a href="https://www.steamizando.com/search/label/Matematica" id="matematica" class="tablink" onclick="openPage('Matematica','#B1BB36')"> Matematica <i class="fas fa-square-root-alt"></i></a>
  <a href="https://www.steamizando.com/p/cheatsheet.html" id="sheatsheet" class="tablink" onclick="openPage('Sheatsheet','#b80c00')" >Sheatsheet <i class="fas fa-table"></i></a>
  <a href="https://www.steamizando.com/p/populares.html" id="postsPolulares" class="tablink" onclick="openPage('PostsPolulares','#420085')" > Polulares <i class="fas fa-fire"></i></a>
  <a href="https://www.steamizando.com/p/arquivos.html" id="arquivos" class="tablink" onclick="openPage('Arquivos','#963c00')" >Arquivos <i class="fas fa-folder"></i></a>
  <a href="https://www.steamizando.com/p/contato.html" id="contato" class="tablink" onclick="openPage('Contato','#8a0a83')" >Contato <i class="fas fa-at"></i></a>
  <a href="https://www.steamizando.com/p/sobre.html" id="sobre" class="tablink" onclick="openPage('Sobre','#006b54')" >Sobre <i class="fas fa-address-card"></i></a>
  <a href="https://www.steamizando.com/p/repositorio.html" id="repositorio" class="tablink" onclick="openPage('Repositorio','#000000')" >Repositorio <i class="fab fa-github-alt"></i></a>
  <a href="https://www.steamizando.com/p/calendario.html" id="calendario" class="tablink" onclick="openPage('Calendario','#0F89BA')" >Calendario <i class="fas fa-calendar-alt"></i></a>
  <a href="https://www.steamizando.com/p/media.html" id="media" class="tablink" onclick="openPage('Media','#EC7650')">Media <i class="fas fa-photo-video"></i></a>
  <a href="https://www.steamizando.com/p/livros.html" id="books" class="tablink" onclick="openPage('Books','#49497F')"> Books <i class="fas fa-book"></i></a>
  <a href="https://www.steamizando.com/p/rss.html#" id="rss" class="tablink" onclick="openPage('Rss','#D38094')" >Rss  <i class="fas fa-rss"></i></a>
</div>

<!-- <button class="tablink" onclick="openPage('About','#0055A5')">Home</button> -->
<div id="Search" class="tabcontent">
  <h3>Home</h3>
  <p>Home is where the heart is..</p>
</div>
<div id="Home" class="tabcontent">
  <h3>Home</h3>
  <p>Home is where the heart is..</p>
</div>

<div id="About" class="tabcontent">
  <h3>Home</h3>
  <p>Home is where the heart is..</p>
</div>

<div id="Blog" class="tabcontent">
  <h3>Home</h3>
  <p>Home is where the heart is..</p>
</div>

<div id="Projects" class="tabcontent">
  <h3>Home</h3>
  <p>Home is where the heart is..</p>
</div>

<div id="Contact" class="tabcontent">
  <h3>Home</h3>
  <p>Home is where the heart is..</p>
</div>

<div id="Matematica" class="tabcontent">
  <h3>Home</h3>
  <p>Home is where the heart is..</p>
</div>



<div id="Sheatsheet" class="tabcontent">
  <h3>Home</h3>
  <p>Home is where the heart is..</p>
</div>


<div id="PostsPolulares" class="tabcontent">
  <h3>Home</h3>
  <p>Home is where the heart is..</p>
</div>

<div id="Sheatsheet" class="tabcontent">
  <h3>Home</h3>
  <p>Home is where the heart is..</p>
</div>

<div id="Arquivos" class="tabcontent">
  <h3>Home</h3>
  <p>Home is where the heart is..</p>
</div>

<div id="Contato" class="tabcontent">
  <h3>Home</h3>
  <p>Home is where the heart is..</p>
</div>

<div id="Repositorio" class="tabcontent">
  <h3>Home</h3>
  <p>Home is where the heart is..</p>
</div>

<div id="Sobre" class="tabcontent">
  <h3>Home</h3>
  <p>Home is where the heart is..</p>
</div>

<div id="Media" class="tabcontent">
  <h3>Home</h3>
  <p>Home is where the heart is..</p>
</div>

<div id="Calendario" class="tabcontent">
  <h3>Home</h3>
  <p>Home is where the heart is..</p>
</div>

<div id="Books" class="tabcontent">
  <h3>Home</h3>
  <p>Home is where the heart is..</p>
</div>
<div id="Rss" class="tabcontent">
  <h3>Home</h3>
  <p>Home is where the heart is..</p>
</div>




<script>
function openPage(pageName,elmnt,color) {
  var i,tabcontent,tablinks;
  tabcontent = document.getElementsByClassName("tabcontent");
  for (i = 0; i < tabcontent.length; i++) {
    tabcontent[i].style.display = "none";
  }
  tablinks = document.getElementsByClassName("tablink");
  for (i = 0; i < tablinks.length; i++) {
    tablinks[i].style.backgroundColor = color;
  }
  document.getElementById(pageName).style.display = "block";
  elmnt.style.backgroundColor = color;
}

// Get the element with id="defaultOpen" and click on it
document.getElementById("defaultOpen").click();
</script>


</!doctype>

我已将其放入博客的脚本小工具中。但是当我打开小工具进行编辑时,上面的部分代码不再出现在那里。 但我面临的问题如下,对于每个 Tab 将是一个指向 enter link description here 等标签的搜索链接。所以我想点击标签,所有带有 matematica 标签的帖子都将出现在与标签颜色相同的背景中。同样的事情也会发生在所有其他标签上。但是当主页面有所有帖子的时候,也就是集合帖子的时候(标签上面的union操作)背景应该是白色的。

更改背景的代码如下:

<script>
function openPage(pageName,tablinks;
  tabcontent = document.getElementsByClassName("tabcontent");
  for (i = 0; i < tabcontent.length; i++) {
    tabcontent[i].style.display = "none";
  }
  tablinks = document.getElementsByClassName("tablink");
  for (i = 0; i < tablinks.length; i++) {
    tablinks[i].style.backgroundColor = color;
  }
  document.getElementById(pageName).style.display = "block";
  elmnt.style.backgroundColor = color;
}

// Get the element with id="defaultOpen" and click on it
document.getElementById("defaultOpen").click();
</script>


我在 Change color by Blogger Tag 中找到的那个

我认为问题出在这部分代码:

  tablinks = document.getElementsByClassName("tablink");
  for (i = 0; i < tablinks.length; i++) {
    tablinks[i].style.backgroundColor = color;
  }
  document.getElementById(pageName).style.display = "block";
  elmnt.style.backgroundColor = color;

再次感谢您的帮助:)

解决方法

我已经解决了部分问题,将 tablinks[i].style.backgroundColor = color; 替换为 document.body.style.backgroundColor = color; 但它只是在点击的那一刻改变了颜色。 我希望背景可以保持颜色,直到我点击另一个选项卡。 如果有人知道怎么做:) 非常感谢

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-