Karlis Pokkers
Karlis Pokkers

Reputation: 244

CSS hover isn't working (needed to show up underline)

I guess i have some mistake and my eyes cant find problem. So i am asking you to help me find my problem - underline dont show up on hover.

Fiddle you can find by fidle net slash t4fmuxbL (because of this stupid editor)

body, div, span, ul, li {
	margin:0;
	padding:0;
	font-family:"Agency FB";
}

li, a {
	list-style-type:none;
	text-decoration:none;
	color:white;
	font-size:14px;
}

li {
	display:inline-block;
	margin:28.5px 5px 5px 35px;
}

.underline-div {
	border-top:3px solid #FFB700;
	width:12px;
	float:left;
	margin-left:41px;
	margin-top:-3px;
	display:none;
}

#und-div2 {
	margin-left:56px;
	width:22px;
}

#und-div3 {
	margin-left:56px;
	width:18px;
}

#und-div4 {
	margin-left:55px;
	width:36px;
}

#news:hover #und-div1 {
	display:block;
}

#forums:hover #und-div2 {
	display:block;
}

#blogs:hover #und-div3 {
	display:block;
}

#statistics:hover #und-div4 {
	display:block;
}



.page, .header {
	padding:0;
}

.page {
	border:1px solid black;
	height:1200px;
	min-width:1265px;
	width:100%;
}

.header-bg {
	height:655px;
	border:1px solid black;
	background:url("http://pokkers.lv/photo-bg.jpg");
	background-size:cover;
}

nav {
	display:block;
	width:100%;
	height:75px;
	background-color:rgba(0,0,0,0.2);
}

.main-nav {
	width:380px;
	height:75px;
}

.left-nav{
	margin-left:200px;
	position:absolute;
	top:0;
}

.right-nav {
	margin-right:200px;
	float:right;
}

.side-div {
	border:1px solid white;
}
<body>
		<div class = "col-md-12 page">
			<header class = "col-md-12 header">
				<div class = "header-bg">
					<nav>
						<div class = "left-nav main-nav">
							<ul>
								<li id = "news"><a href = "#">NEWS</a></li>
								<li id = "forums"><a href = "#">FORUMS</a></li>
								<li id = "blogs"><a href = "#">BLOGS</a></li>
								<li id = "statistics"><a href = "#">STATISTICS</a></li>
							</ul>
							<div class = "underline-div" id = "und-div1">&nbsp;</div>
							<div class = "underline-div" id = "und-div2">&nbsp;</div>
							<div class = "underline-div" id = "und-div3">&nbsp;</div>
							<div class = "underline-div" id = "und-div4">&nbsp;</div>
						</div>
						<div class = "right-nav main-nav">
							<ul>
								<li><a href = "#">SERVERS</a></li>
								<li><a href = "#">BANLIST</a></li>
								<li><a href = "#">MARKET</a></li>
								<li><a href = "#">CONTACTS</a></li>
							</ul>
						</div>
					</nav>
				</div>
			</header>
		</div>
	</body>

Upvotes: 0

Views: 1479

Answers (3)

scottohara
scottohara

Reputation: 765

Here's an example of how you could accomplish this using :after pseudo elements, as the current HTML structure you have won't allow for you to hover on a link, and reveal a div (or any other element) that isn't a child of that <a>

CSS:

  .main-nav a {
    position: relative;
    text-decoration: none
  }

  .main-nav a:after {
    content: '';
    display: none;
    height: 2px;
    background: #f00;
    width: 100%;
    bottom: 0px;
    left: 0px;
    position: absolute;
  }

  .main-nav a:hover:after,
  .main-nav a:focus:after {
    display: block;
  }

Demo HTML

<ul class="main-nav">
  <li>
    <a href="#!">
      Link
    </a>
  </li>
</ul>

Upvotes: 0

Alireza
Alireza

Reputation: 59

You must add text-decoration: underline; to hover of items

Upvotes: 1

roberrrt-s
roberrrt-s

Reputation: 8210

I'm not quite sure why you're using new <div> elements as an underline, but to get to the point:

It is impossible to select those divs with a hover in your current HTML structure.

Why don't you add a simple text-decoration: underline to the initial <li> whenever you hover it? You can can then simply address the <a> tag, I've updated your code here:

body, div, span, ul, li {
	margin:0;
	padding:0;
	font-family:"Agency FB";
}

li, a {
	list-style-type:none;
	text-decoration:none;
	color:white;
	font-size:14px;
}

li {
	display:inline-block;
	margin:28.5px 5px 5px 35px;
}

li a:hover {
	border-bottom:3px solid #FFB700;
}

.page, .header {
	padding:0;
}

.page {
	border:1px solid black;
	height:1200px;
	min-width:1265px;
	width:100%;
}

.header-bg {
	height:655px;
	border:1px solid black;
	background:url("http://pokkers.lv/photo-bg.jpg");
	background-size:cover;
}

nav {
	display:block;
	width:100%;
	height:75px;
	background-color:rgba(0,0,0,0.2);
}

.main-nav {
	width:380px;
	height:75px;
}

.left-nav{
	margin-left:200px;
	position:absolute;
	top:0;
}

.right-nav {
	margin-right:200px;
	float:right;
}

.side-div {
	border:1px solid white;
}
<body>
	<div class = "col-md-12 page">
		<header class = "col-md-12 header">
			<div class = "header-bg">
				<nav>
					<div class = "left-nav main-nav">
						<ul>
							<li id = "news"><a href = "#">NEWS</a></li>
							<li id = "forums"><a href = "#">FORUMS</a></li>
							<li id = "blogs"><a href = "#">BLOGS</a></li>
							<li id = "statistics"><a href = "#">STATISTICS</a></li>
						</ul>
					</div>
					<div class = "right-nav main-nav">
						<ul>
							<li><a href = "#">SERVERS</a></li>
							<li><a href = "#">BANLIST</a></li>
							<li><a href = "#">MARKET</a></li>
							<li><a href = "#">CONTACTS</a></li>
						</ul>
					</div>
				</nav>
			</div>
		</header>
	</div>
</body>

Upvotes: 0

Related Questions