P粉5365327812023-08-24 00:53:13
Here's an interesting solution that no one has mentioned.
fact:
You cannot modify the HTML of the page - No problem!
You can modify CSS files, but the developer may modify them again later and remove any changes you made - Don't worry.
You can't/don't want to use Javascript and JQuery - No problem for me.
You can add more files to the server - Great!
Let's do some .htacess hacking for fun and profit!
Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteRule ^(.*?)css3.css(.*?) hackedCSS3.php [L]
Result: hackedCSS3.php will be served silently every time it is requested, instead of css3.css.
Reference: http://httpd.apache.org/docs/2.2/howto/htaccess.html
<?php // 发送正确的头信息! header("Content-type: text/css; charset: UTF-8"); // 输出css3.css文件 echo file_get_contents("css3.css"); ?> // 在这里添加您的CSS,使用任何有趣的!important或覆盖技巧(即:特定性) div { ... }
Additional rewards:
You can extend this solution to all three .css
files in this one .php
file (but only css3.css, And use clever regex to remove/modify those developers' CSS without touching any files. The possibilities are exciting.
.htaccess file should be located in the document root directory of your website. This is where www.example.com/index.html loads index.html.
It can be located in any directory you specify in the .htaccess file. The document root works too. Change
RewriteRule ^(.*?)css3.css(.*?) hackedCSS3.php [L]
for
RewriteRule ^(.*?)css3.css(.*?) /folders/you/want/hackedCSS3.php [L]
unnecessary. Treat this part of the CSS code as a .css file. You don't need the <style>
tag.
P粉0221405762023-08-24 00:23:36
In addition to using the !important
suggested by most answers, this is a question about CSS specificity
can be represented by 4 columns of priorities:
/*演示目的*/ body {margin: 0;padding: 0} div,article {min-height: 200px;height: 100%;width: 100%} /*CSS特异性*/ /* 特异性:0/1/0/0 */ #id { background-color: green } /* 特异性:0/0/1/0 */ .class { background-color: yellow } /* 特异性:0/0/0/1 */ section { background-color: blue } /* ------------ 覆盖内联样式 ----------- */ /*要覆盖内联样式,我们现在使用!important*/ /* 特异性 0/0/1/0 */ .inline { background-color: purple !IMPORTANT /*将变为紫色-最终结果*/ }
<article> <div id="id"> <div class="class"> <section> <div class="inline" style="background-color:red"> <!--特异性 1/0/0/0 - 被"!important"覆盖--> </div> </section> </div> </div> </article>