CSS rules not being applied

46 Views Asked by At

I am following along with a course on udemy as we are building a webpage for a restaurant. As I am following along sometimes my css rules do not get applied properly. I cant seem to override some properties of the user agent stylesheet. This course was made in 2015 so I am wondering if the author is using some outdated css rules? For example I cant get ride of the underline and blue text on the buttons on my page. Here is my 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;
}
2

There are 2 best solutions below

0
Evren On

Have you tried using !important in the end of your css like

.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;
}
0
SeeoX On

To understand CSS "overwrite" you need to understand CSS specificity which determines the priority between selectors.

Here is the selectors from less priority to the most :

  • HTML elements, like a {...} or div {...}
  • classes, like .myClass{...} or div.myClass{...}
  • ids, like #myId{...} or div#myId{...}

In addition of that, you have !important, that can suffix the value of a CSS property, like div{font-size: 16px !important;}. It will automatically give this property declaration priority, even if a more specific selector is apply elsewhere.

Be aware that the overuse of !important, can give you a less readable CSS files.