说明: 1.tools.py 保存成一个文件 2.tools.css 保存成为一个文件 tools.py根据python3的语法编写 tools.py --------------------------------------------------------------------------------------------------------------- import re # Python文件搜索替换 def string_switch(x): with open(x, "r", encoding="utf-8") as f: # readlines以列表的形式将文件读出 lines = f.readlines() with open(x, "w", encoding="utf-8") as f_w: #定义一个数字,用来记录在读取文件时在列表中的位置 n = 0 #默认选项,只替换第一次匹配到的行中的字符串 # 在行内查找长度数字 pattern = re.compile(r'\d+?\.?\d+rem|\d+rem') # 查找数字 for line in lines: # 在行内查找长度数字 y = pattern.findall(line) if len(y) > 0: if y[0] in line: # 长度除以3.5 y = y[0].replace('rem','') z = str(round((float(y) / 3.5), 2)) y1 = str(y)+'rem' z1 = str(z)+'rem' line = line.replace(y1, z1) f_w.write(line) string_switch('tools.css')
tools.css
----------------------------------------------------------------------------------------------------------------------------------------------------------------
.product { text-align: center } /**banner**/ .product_banner { height: 3.2rem; } .product_banner .banner > img { height: 3.2rem; width: 100% } .product_banner .telecom-text { position: absolute; top: 1.71rem; left: 1.14rem; color: white; line-height: 0.34rem; font-size: 0.17rem; text-align: left; } .product_banner .telecom-text p:first-child { font-size: 0.23rem; } /**简介**/ .pr_introduction { margin-top: -0.03rem; } .pr_introduction p { color: #aaa; line-height: 2em; font-size: 0.1rem; } .pr_introduction p:first-child { font-size: 0.14rem; font-weight: bold; color: #0b0b0b; margin-bottom: 0.14rem; } .pr_introduction > div { width: 7.43rem; margin: 0 auto; margin-top: 0.29rem; display: inline-block; } .pr_introduction > div > div { float: left; width: 31%; height: 1.29rem; box-shadow: 0 3px 10px rgba(0, 0, 0, .1); display: flex; justify-content: space-between; text-align: left; border-radius: 0.03rem; margin: 0.09rem; } .pr_introduction > div > div > div:first-child { margin: auto 0; text-align: center; margin-left: 0.09rem; } .pr_introduction > div > div span { margin: 0.09rem; display: block; line-height: 0.17rem; } .pr_introduction > div > div span:first-child { font-size: 0.1rem; font-weight: bold; margin-top: 0.14rem; } .pr_introduction > div > div:hover { transform: translateY(-0.06rem); transition: transform .3s, box-shadow .3s; box-shadow: 0 2px 10px rgba(0, 0, 0, .1); color: #FFFFFF; background-color: #5d8cfe; } .pr_introduction > div > div > img:hover { -webkit-filter: grayscale(0%); -moz-filter: grayscale(0%); -ms-filter: grayscale(0%); -o-filter: grayscale(0%); filter: grayscale(0%); filter:; } .pr_introduction { padding-bottom: 0.48rem; padding-top: 0.29rem; background-color: #f9f9f9; } /**第一屏幕**/ .pr_con1 { width: 100%; height: 3.43rem; /*background-color: #f9f9f9;*/ } .pr_con1 .pr_con1-content { width: 7.43rem; margin: 0 auto 0.41rem; display: inline-block; } .pr_con1 .pr_con1-content div { float: left; height: 2.86rem; display: inline-block; margin-top: 0.37rem; } .pr_con1 .pr_con1-content .pandect-left { width: 4.86rem; text-align: left; } .pr_con1 .pr_con1-content .pandect-left img { height: 100% } .pr_con1 .pr_con1-content .pandect-right { width: 2.57rem; text-align: left; font-size: 0.1rem; } .pr_con1 .pr_con1-content .pandect-right h3 { font-size: 0.14rem; margin: 0.24rem 0; letter-spacing: 1px; text-align: center; font-weight: 300 } .pr_con1 .pr_con1-content .pandect-right p { margin-top: 0.14rem } .pr_con1 .pr_con1-content .pandect-right p.suggest { color: #5789fe } .pr_con1 .pr_con1-content .pandect-right ul li { list-style-type: none; width: 100%; float: left; height: auto; line-height: 0.17rem; } .pr_con1 .pr_con1-content .pandect-right ul li.right_introduce_title { color: #5789fe; list-style-type: circle; margin-top: 0.09rem } /**第二屏幕**/ .pr_con2 { width: 100%; background-color: #f9f9f9; height: auto; } .pr_con2 > p { padding: 0.29rem 0rem 0.29rem 0rem; font-size: 0.11rem; font-weight: bold } .pr_con2 > ul { width: 6.86rem; margin: 0 auto; box-shadow: 0 3px 10px rgba(0, 0, 0, .1); } .pr_con2 div{ height: 0.57rem; } .pr_con2 > ul > li { max-height: 0.31rem; margin: auto 0; overflow: hidden; border-bottom: 1px solid #dce5fb; text-align: left; background-color: white; } .pr_con2 > ul > li .top { display: flex; justify-content: space-between; font-size: 0.11rem; height: 0.31rem; color: #5789fe; line-height: 0.31rem; } .pr_con2 .hauto .top { background-color: #5d8cfe; color: #ffffff; } .pr_con2 > ul > li .top p:first-child { margin: 0.04rem 0.5rem } .pr_con2 > ul > li .top p:first-child img { width: 80%; } .pr_con2 > ul > li .top p:nth-child(2) { text-align: left; width: 90%; } .pr_con2 > ul > li .top p:nth-child(3) { margin: auto 0; margin-right: 0.06rem } .pr_con2 > ul > li .con { text-align: left; background-color: #FFFFFF; padding: 0.14rem; line-height: 0.14rem; } .pr_con2 > ul > li .con div p:nth-child(1) { font-size: 0.11rem; color: #333; } .pr_con2 > ul > li .con div p:nth-child(1) ~ p { color: #666; } .pr_con2 > ul > li .con div p > strong { font-weight: bold; } .pr_con2 .hauto { max-height: 3.43rem; transition: max-height .3s; }