在网上找到一个灰常好看的html模版,很可惜它自带了很多css样式,为了防止冲突,你需要一行一行的去改css样式,给它添加上父亲节点,并且改动css的选择器。工作量太大有木有啊。 这个代码可以给css添加上父亲节点。有效的防止了css冲突。
注意2点:
1. css文件中需要手动去掉注释,该功能没有写了。有兴趣的可以将代码补全
2. 最好在每个选择器的 ”{“ 换行,该代码没有写,有兴趣可以自己补全
比如:
#div1{ color : red; } 改成 #div1{ color:red; }
package test.css; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import org.junit.Test; /** * 给所有的css样式加上父节点 * * @author Van * @time 20150312 */ public class ChangeCss { private static String tagName = "#footOuter "; private static String inPath = "D:\\workspaceluna\\GGBlog\\src\\main\\webapp\\resources\\plugins\\footer\\style.css"; private static String outPath = "D:\\workspaceluna\\GGBlog\\src\\main\\webapp\\resources\\plugins\\footer\\style1.css"; @Test public void cssTest() throws Exception{ //输入 BufferedReader in = new BufferedReader(new FileReader(inPath)); //删除旧文件 File file = new File(outPath); file.delete(); //创建输出流 FileWriter fw = new FileWriter(outPath); int lineTotal = 0; String temp; while( (temp = in.readLine()) != null ){ lineTotal++; StringBuilder sbder; //跳过空行 if(isEmpty(temp)){ continue; } //跳过@开头的行 if(temp.contains("@")){ fw.write(temp+"\r\n"); continue; } //对有逗号和没有分号的行加标签 if(temp.contains(",") && !temp.contains(";")){ sbder = new StringBuilder(); String _temp[] = temp.split(","); for(String _eveString : _temp){ //加上父节点 sbder.append( tagName + _eveString); if(_eveString.contains("{") || _eveString.contains("}")) continue; sbder.append(","); } fw.write(sbder+"\r\n"); continue; } //对有花括号和逗号的行进行处理 if(temp.contains("\\{")){ if(temp.contains(",")){ sbder = new StringBuilder(); temp = temp.split("\\{")[0]; String _temp[] = temp.split(","); for(int i=0;i<_temp.length;i++){ //加上父节点 sbder.append( tagName + _temp[i]); if(i==_temp.length-1) break; sbder.append(","); } sbder.append(temp.split("\\{")[1]); fw.write(sbder+"\r\n"); continue; } } //对有花括号的行进行处理 if(temp.contains("{")){ sbder = new StringBuilder(); sbder.append(tagName + temp); fw.write(sbder+"\r\n"); continue; } fw.write(temp+"\r\n"); } System.out.println(lineTotal); in.close(); fw.close(); } private boolean isEmpty(String value){ if(value.isEmpty()) return true; if(value.matches("^\\s+$")) return true; return false; } }
以上是如何给css样式加上父节点?的详细内容。更多信息请关注PHP中文网其他相关文章!
声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

前几天我得到了这个问题。我的第一个想法是:奇怪的问题!特异性是关于选择者的,而在符号不是选择器,那么...无关紧要?

在这篇文章中,我们将使用我构建和部署的电子商务商店演示来进行Netlify,以展示如何为传入数据制作动态路线。这是一个公平的


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章
刺客信条阴影:贝壳谜语解决方案
3 周前ByDDD
Windows 11 KB5054979中的新功能以及如何解决更新问题
2 周前ByDDD
在哪里可以找到原子中的起重机控制钥匙卡
3 周前ByDDD
节省R.E.P.O.解释(并保存文件)
1 个月前By尊渡假赌尊渡假赌尊渡假赌
刺客信条阴影 - 如何找到铁匠,解锁武器和装甲定制
4 周前ByDDD

热工具

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

SublimeText3汉化版
中文版,非常好用

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具