繁体   English   中英

CSS样式不适用于html页面

[英]CSS style not applying to the html page

所以我有下面的代码。

我期待.container {background-color: red !important;}将颜色应用于 HTML 页面。 但由于某种原因,它没有发生。

 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title></title> <link href="https://fonts.googleapis.com/css2?family=Varela+Round|Alex+Brush|Plus+Jakarta+Sans" rel="stylesheet" /> <style type="stylesheet"> .container { background-color: red !important; } </style> </head> <body> <div class="container" style=" background: #ffffff url('assets/image.jpg') no-repeat center center; height: 230px; "></div> </body> </html>

这是因为您错误地在<style>元素中包含了type="stylesheet"属性; 删除它可以解决问题:

 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title></title> <link href="https://fonts.googleapis.com/css2?family=Varela+Round|Alex+Brush|Plus+Jakarta+Sans" rel="stylesheet" /> <style> .container { background-color: red !important; } </style> </head> <body> <div class="container" style=" background: #ffffff url('assets/image.jpg') no-repeat center center; height: 230px; " ></div> </body> </html>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM