spruceboy
spruceboy

Reputation: 1

Background-color does seemingly not work for this dropdown css menu?

I used this dropdown code and it works fine, but I need to be able to change the background color of the menu, as well as a change to color when hovering above it. I tried changing the background color of it, but it has no effect on it, but the outline command does work. Seemingly it has something to do with a "float" but I've tried fixing it but to no avail.

@charset "utf-8";
/* CSS Document */
* {
    background-color: black;
    padding: 0;
    margin: 0;
}
@font-face {
    font-family: Kiona Regular;
    src: url('Kiona-Regular.ttf');
} 
.junebug {
    font-family: Kiona Regular;
    font-size: 4.2em;
}

@font-face {
    font-family: Emphasis Light;
    src: url('LT Emphasis Light.ttf');
}

.item1 {
    grid-area: header;
    height: 8vh;
    background-color: black;
    font-family: Kiona Regular;
    text-align: center;
    color: white;
    align-self: center;
    vertical-align: middle;
    cursor:default;
    z-index: 2;
}

.title-text {
    text-shadow: 0 0 4px white;
    transition-property: text-shadow;
    transition-duration: 1s;
}

.title-text:hover {
    text-shadow: 0 0 11px white, 0 0 11px white;
}

.item2 {
    grid-area: main;
    background-color: 0;
    height: 76.2vh;
    align-content: center;
    align-self: center;
    vertical-align: middle;
    z-index: -1;
}
.item3 {
    grid-area: footer;
    height: 3vh;
    background-color: black;
    z-index: 2;
    color: white;
    font-family: Gotham, "Helvetica Neue", Helvetica, Arial, "sans-serif";
}

.grid-container {
  display: grid;
  grid-template-areas:
    'header header header header header'
    'main main main main main'
    'main main main main main'
    'footer footer footer footer footer';
  grid-gap: 2px;
  background-color: black;
}

.grid-container > div {
  text-align: center;
  padding: 20px 0;
  font-size: 30px;
}

table, th {
    background-color: black;
    height: 8vh;
}

table {
    table-layout: fixed;
    width: 100%;
    vertical-align: middle;
    margin: 0 auto;
    position: absolute;
    top: 40px;
}

.has-dropdown {
    position: relative;
}

.has-dropdown:hover > .dropdown {
    display: block;
}

.dropdown {
    width: 240px;
    position: absolute;
    margin: auto;
    left: 0;
    right: 0;
    bottom: -62px;
    overflow-y: auto;
    max-height: 200px;
    border: 1px solid white;
    display: none;
    text-align: left;
    background-color: white;
    font-family: Emphasis Light;
    overflow: hidden;
}
.dropdown a {
    color: white;
}
.dropdown a:hover {
    background-color: #444444;
}

#BackgroundVideo {
    position: fixed;
    right: 0;
    left: 0;
    bottom: 0;
    min-width: 100%;
    max-width: 100%;
    z-index: 0;
}
.logo {
  width:20%;
  display:block;
  position:absolute;
  left:0;
  right:0;
  top:0;
  margin:auto;
  z-index: 3;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>TheBigProject</title>
<link href="TheBigProject2.css" rel="stylesheet" type="text/css">
<link href="TheBigProject2.js" type="text/javascript">
</head>
<body>
<video autoplay="" loop="" muted="" id="BackgroundVideo">
      <source src="Animatic15.mp4" type="video/mp4">
        </video>
<img class="logo" src="Pragerio Logo.svg" height="211px">
<div class="grid-container">
  <div class="item1">
     <table readonly>
    <tr>
    <th class="has-dropdown">
        <span class="title-text">FERA</span>
        <div class="dropdown">
            <div>About</div>
            <div>Compare</div>
        </div>
        </th>
    <th class="title-text">SENSAÇÃO</th>
    <th>&nbsp;</th>
    <th class="title-text">PRESS</th>
    <th class="title-text">ABOUT</th>
  </tr>
      </table>
         </div>
  <div class="item2">
    </div>  
  <div class="item3">
    <span>Copyright notice!</span>
    </div>
</div>

</body>
</html>

Upvotes: 0

Views: 533

Answers (2)

Learning
Learning

Reputation: 20001

I am not sure if this is what you want.

.has-dropdown .dropdown >div:hover{background-color:red;}

I am not sure what you are using tables for this when you can get this done using list element also?

@charset "utf-8";
/* CSS Document */
* {
    background-color: black;
    padding: 0;
    margin: 0;
}
@font-face {
    font-family: Kiona Regular;
    src: url('Kiona-Regular.ttf');
} 
.junebug {
    font-family: Kiona Regular;
    font-size: 4.2em;
}

@font-face {
    font-family: Emphasis Light;
    src: url('LT Emphasis Light.ttf');
}

.item1 {
    grid-area: header;
    height: 8vh;
    background-color: black;
    font-family: Kiona Regular;
    text-align: center;
    color: white;
    align-self: center;
    vertical-align: middle;
    cursor:default;
    z-index: 2;
}

.title-text {
    text-shadow: 0 0 4px white;
    transition-property: text-shadow;
    transition-duration: 1s;
}

.title-text:hover {
    text-shadow: 0 0 11px white, 0 0 11px white;
}

.item2 {
    grid-area: main;
    background-color: 0;
    height: 76.2vh;
    align-content: center;
    align-self: center;
    vertical-align: middle;
    z-index: -1;
}
.item3 {
    grid-area: footer;
    height: 3vh;
    background-color: black;
    z-index: 2;
    color: white;
    font-family: Gotham, "Helvetica Neue", Helvetica, Arial, "sans-serif";
}

.grid-container {
  display: grid;
  grid-template-areas:
    'header header header header header'
    'main main main main main'
    'main main main main main'
    'footer footer footer footer footer';
  grid-gap: 2px;
  background-color: black;
}

.grid-container > div {
  text-align: center;
  padding: 20px 0;
  font-size: 30px;
}

table, th {
    background-color: black;
    height: 8vh;
}

table {
    table-layout: fixed;
    width: 100%;
    vertical-align: middle;
    margin: 0 auto;
    position: absolute;
    top: 40px;
}

.has-dropdown {
    position: relative;
}

.has-dropdown:hover > .dropdown {
    display: block;
}

.dropdown {
    width: 240px;
    position: absolute;
    margin: auto;
    left: 0;
    right: 0;
    bottom: -62px;
    overflow-y: auto;
    max-height: 200px;
    border: 1px solid white;
    display: none;
    text-align: left;
    background-color: white;
    font-family: Emphasis Light;
    overflow: hidden;
}
.dropdown a {
    color: white;
}
.dropdown a:hover {
    background-color: #444444;
}

#BackgroundVideo {
    position: fixed;
    right: 0;
    left: 0;
    bottom: 0;
    min-width: 100%;
    max-width: 100%;
    z-index: 0;
}
.logo {
  width:20%;
  display:block;
  position:absolute;
  left:0;
  right:0;
  top:0;
  margin:auto;
  z-index: 3;
}
.has-dropdown  .dropdown >div:hover{background-color:red;}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>TheBigProject</title>
<link href="TheBigProject2.css" rel="stylesheet" type="text/css">
<link href="TheBigProject2.js" type="text/javascript">
</head>
<body>
<video autoplay="" loop="" muted="" id="BackgroundVideo">
      <source src="Animatic15.mp4" type="video/mp4">
        </video>
<img class="logo" src="Pragerio Logo.svg" height="211px">
<div class="grid-container">
  <div class="item1">
     <table readonly>
    <tr>
    <th class="has-dropdown">
        <span class="title-text">FERA</span>
        <div class="dropdown">
            <div>About</div>
            <div>Compare</div>
        </div>
        </th>
    <th class="title-text">SENSAÇÃO</th>
    <th>&nbsp;</th>
    <th class="title-text">PRESS</th>
    <th class="title-text">ABOUT</th>
  </tr>
      </table>
         </div>
  <div class="item2">
    </div>  
  <div class="item3">
    <span>Copyright notice!</span>
    </div>
</div>

</body>
</html>

Upvotes: 0

Vahid
Vahid

Reputation: 7551

The problem is that you're applying a black background color to all of the elements:

* {
    background-color: black;
}

This makes the items inside of the .dropdown, black so the background of the .dropdown is not visible. If you apply a padding: 5px to .dropdown you'll see that it has a white background. Remove this line and you're good.

I also recommend you check your CSS with a linter like CSSLint. There're some other problems in your code.

Upvotes: 1

Related Questions