[英]CSS rules not being applied
當我們正在為一家餐館建立一個網頁時,我正在關注關於 udemy 的課程。 正如我所遵循的,有時我的 css 規則沒有得到正確應用。 我似乎無法覆蓋用戶代理樣式表的某些屬性。 本課程是 2015 年制作的,所以我想知道作者是否使用了一些過時的 css 規則? 例如,我無法使用頁面按鈕上的下划線和藍色文本。 這是我的 css:
* {
margin:0;
padding: 0;
box-sizing:border-box;
/*set margin,padding,and border for whole page*/
}
html {
/*set background color, also sent font properties for html tag*/
background-color:#fff;
color:#555;
font-family: 'Lato','Arial','sans-serif';
font-weight: 300;
font-size:20px;
text-rendering: optimizeLegibility;
}
/*----------------------------*/
/*REUSABLE COMPONENTS */
/*----------------------------*/
.row {
max-width: 1140px;
margin:0 auto;
}
h1 {
margin:0;
color: #fff;
font-size: 200%;
font-weight: 300;
text-transform: uppercase;
letter-spacing: 1px;
word-spacing: 4px;
}
/*inline-block element*/
.btn:link,
.btn:visited {
display:inline-block;
padding:10px 30px;
font-weight:300;
text-decoration:none;
border-radius: 200px;
}
.btn-full:link,
.btn-full:visited{
background-color: #e67e22;
border: 1px solid #e67e22;
color: #fff;
}
.btn-ghost:link,
.btn-ghost:visited{
border: 1px solid #e67e22;
color: #e67e22;
}
.btn:hover,
.btn:active {
background-color: #cf6d17;
}
.btn-full:hover,
.btn-full:active {
border: 1px solid #cf6d17;
}
.btn-ghost:hover,
.btn-ghost:active {
border: 1px solid #cf6d17;
color: #fff;
}
/*------------------------------------*/
/*HEADER*/
/*------------------------------------*/
header {
/*background image and header properties
Linear gradient changes color of image to make text stand out more
*/
background-image: linear-gradient(rgba(0,0,0,0.7),rgba(0,0,0,0.7)),url("img/hero.jpg");
/*Let background cover entire page*/
background-size: cover;
/*center background position*/
background-position: center;
/*have height of img cover 100% viewport*/
height: 100vh;
}
.hero-text-box {
position: absolute;
width: 1140px;
/*completely center hero text*/
top:50%;
left: 50%;
transform: translate(-50%,-50%);
}
.logo {
height: 100px;
width:auto;
float:left;
margin-top: 20px;
}
.main-nav {
float: right;
list-style: none;
margin-top: 55px;
}
.main-nav li {
display: inline-block;
margin-left: 40px;
}
.main-nav li a:link,
.main-nav li a:visited {
padding: 8px 0;
color: #fff;
text-decoration: none;
text-transform: uppercase;
font-size: 90%;
border-bottom: 2px solid transparent;
transition: border-bottom 0.2s;
}
.main-nav li a:hover,
.main-nav li a:active {
border-bottom: 2px solid #e67e22;
}
您是否嘗試過在 css 的末尾使用!important
.main-nav li a:link,
.main-nav li a:visited {
padding: 8px 0;
color: #fff !important;
text-decoration: none !important;
text-transform: uppercase;
font-size: 90%;
border-bottom: 2px solid transparent;
transition: border-bottom 0.2s;
}
要了解 CSS “覆蓋”,您需要了解CSS 的特殊性,它決定了選擇器之間的優先級。
以下是從低優先級到最高優先級的選擇器:
a {...}
或div {...}
.myClass{...}
或div.myClass{...}
#myId{...}
或div#myId{...}
除此之外,您還有!important
,它可以作為 CSS 屬性值的后綴,例如div{font-size: 16px;important;}
。 即使在其他地方應用了更具體的選擇器,它也會自動賦予此屬性聲明優先級。
請注意,過度使用!important
會使您的 CSS 文件的可讀性降低。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.