2

I am trying to add a hover effect from Youtube Video

I tried for an hour, changed my code two times; where my original code was this:

* {
  font-family: 'Montserrat', sans-serif;
  color: white;
  margin: 0;
  padding: 0;
}

.header {
  width: 100%;
  background-color: #2C2F33;
  border-bottom: 5px #FF9F00 solid;
  font-size: 15px;
  display: flex;
  align-items: center
}

#logo img {
  float: left;
  margin: 0;
  padding: 20px;
  width: 187.5px;
  height: 63.75px;
  background-color: #2C2F33;
}

.navbar {
  display: flex;
  justify-content: space-between;
  margin-left: auto;
}

li {
  display: inline;
  padding: 0 22.5px 0 22.5px;
}

.navbar,
li,
a {
  text-decoration: none;
  list-style-type: none;
  text-transform: uppercase;
  background-color: #2C2F33;
  position: relative;
}

.navbar,
li,
a:hover {
  color: #FF9F00;
  text-decoration: none;
  list-style-type: none;
}

#userbalance {
  background-color: #23272A;
  padding: 10px;
  border: 3px #FF9F00 solid;
}

#userbalance {
  background-color: #23272A;
}

#balance,
#dsh {
  color: #FF9F00;
}

#dosh {
  color: #FFFFFF;
}

.body {
  background-color: #23272A;
}

footer {
  background-color: #23272A;
  position: absolute;
  text-align: center;
  clear: both;
  width: 100%;
  bottom: 18px;
  font-size: 12.5px;
}
<!DOCTYPE html>

<html>

  <head>

    <meta charset="utf-8">
    <link href="./css/style.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Montserrat:300" rel="stylesheet">
    <meta name="viewport" content="width=device-width">
    <meta name="author" content="Arszilla">

    <title>Website</title>

  </head>

  <body>

    <div class="header">

      <div id="logo">

        <img src="./img/logo.png"></img>

      </div>

      <div class="navbar">

        <div id="leftnavbar">

          <ul>

            <li id="userbalance"><span id="balance">Balance:</span> <span id="dosh">1.00000000</span> <span id="dsh">DSH</span></li>

          </ul>

        </div>

        <div id="rightnavbar">

          <ul>

            <li><a href="index.html">Button 1</a></li>

            <li><a href="index.html">Button 2</a></li>

            <li><a href="index.html">Button 3</a></li>

            <li><a href="index.html">Button 4</a></li>

          </ul>

        </div>

      </div>

    </div>

  </body>

</html>

I removed the <div class="header"> etc and made it all <header> and such (Basically got rid of div)

I followed the video and until 14 minute mark it was okay, I understood what he was doing. After that stuff went downhill.

I added these to my code:

    .navbar,
li
{
  position: absolute;
  display: inline-block;
}

and

    .navbar,
li
a::before
{
  content: '';
  display: block;
  height: 5px;
  width: 100%;
  background-color: red;
  position: absolute;
}

and got this as a result:

Result

I am not sure how can I fix this as I am not that experienced. Would someone mind helping me? I am not sure if I should remake the site from scratch and just use <header>, <nav> etc instead of using divs and labeling 'similar' classes to them (class="header" etc)

Arszilla
  • 159
  • 1
  • 2
  • 12
  • when you add `li:hover {border-bottom:2px solid black;}` to CSS you have the effect. https://codepen.io/hansfranz/pen/MvbEpj check it out here. – hansTheFranz Aug 04 '17 at 11:16
  • @hansTheFranz Thats better thank you! But how can I make it like the video, at the top and get the line NOT to pass the length of the words. Like the black line goes over the text for the `ul li a` (Look here: http://imgur.com/a/xUEv) – Arszilla Aug 04 '17 at 11:20
  • `li:hover {padding-top:8px;border-top: 4px solid #ff0000;}` to make it to the top use this (or check the codepen I updated it) to be honest I have no idea how to limit the width, there is the `border-top-width` attribute in CSS but its for the thickness of the border. – hansTheFranz Aug 04 '17 at 11:33
  • @hansTheFranz Can you see the video please, I am trying to have it the way he did. Also: I dont want the border-tops to pass what the buttons have written (http://imgur.com/a/HhlTy) Imagine Button 2 having another name; Like About Us. I dont want the line to pass `About Us` Watch the first few minutes of the video or after the 14 min mark to see what I mean. – Arszilla Aug 04 '17 at 11:58
  • Yeah I got what you mean, but I really don't want to watch some videos and follow CSS tutorials, Im more into Data science/Python and I don't want to spend time on navbars.... Good luck hopefully someone comes around and finishes the project. Ask the guy who posted an answer for more help ;) – hansTheFranz Aug 04 '17 at 12:01
  • 1
    Still, thank you. Probably the closest thing I can get for now... Hoping for some web dev to drop and help :D. Thanks again @hansTheFranz – Arszilla Aug 04 '17 at 12:02
  • I suspect this question is too broad, because it seems to require readers to watch a video in order to grok the problem. – halfer Aug 17 '17 at 20:28

2 Answers2

1

* {
  font-family: 'Montserrat', sans-serif;
  color: white;
  margin: 0;
  padding: 0;
}

.header {
  width: 100%;
  background-color: #2C2F33;
  border-bottom: 5px #FF9F00 solid;
  font-size: 15px;
  display: flex;
  align-items: center
}

#logo img {
  float: left;
  margin: 0;
  padding: 20px;
  width: 187.5px;
  height: 63.75px;
  background-color: #2C2F33;
}

.navbar {
  display: flex;
  justify-content: space-between;
  margin-left: auto;
}

.navbar,
li,
a {
  text-decoration: none;
  list-style-type: none;
  text-transform: uppercase;
  background-color: #2C2F33;
  position: relative;
}
ul li { 
         padding: 9px 22.5px 11px 22.5px; 
         float:left; 
         border: 3px solid transparent 
       }
 ul li:hover {  
         border: 3px #FF9F00 solid;
       }

#userbalance {
  background-color: #23272A;
  padding: 10px;
  border: 3px #FF9F00 solid;
}

#userbalance {
  background-color: #23272A;
}

#balance,
#dsh {
  color: #FF9F00;
}

#dosh {
  color: #FFFFFF;
}

.body {
  background-color: #23272A;
}

footer {
  background-color: #23272A;
  position: absolute;
  text-align: center;
  clear: both;
  width: 100%;
  bottom: 18px;
  font-size: 12.5px;
}
<html>

  <head>

    <meta charset="utf-8">
    <link href="./css/style.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Montserrat:300" rel="stylesheet">
    <meta name="viewport" content="width=device-width">
    <meta name="author" content="Arszilla">

    <title>Website</title>

  </head>

  <body>

    <div class="header">

      <div id="logo">

        <img src="./img/logo.png">

      </div>

      <div class="navbar">

        <div id="leftnavbar">

          <ul>

            <li id="userbalance"><span id="balance">Balance:</span> <span id="dosh">1.00000000</span> <span id="dsh">DSH</span></li>

          </ul>

        </div>

        <div id="rightnavbar">

          <ul>

            <li><a href="index.html">Button 1</a></li>

            <li><a href="index.html">Button 2</a></li>

            <li><a href="index.html">Button 3</a></li>

            <li><a href="index.html">Button 4</a></li>

          </ul>

        </div>

      </div>

    </div>

  </body>

</html>
vicky patel
  • 699
  • 2
  • 8
  • 14
0

Use this CSS code and check your hover effect

 ul li { 
         padding: 9px 22.5px 11px 22.5px; 
         float:left; 
         border: 3px solid transparent 
       }
 ul li:hover {  
         border: 3px #FF9F00 solid;
       }
ono2012
  • 4,967
  • 2
  • 33
  • 42
Mitul Patel
  • 154
  • 1
  • 10
  • It just adds a box. http://imgur.com/a/Izzhi What I need is the one like the video. Like I asked Hans; watch the first few mins or after the 14 minute mark to see what I mean. I am trying to get that. – Arszilla Aug 04 '17 at 12:00