Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why the div with class name "topnav" is not being displayed in palegreen color?

.topnav{
 background-color: palegreen;
}
.topnav a{
 float: left;
 }
<div class="topnav">
        <a href="">Home</a>
        <a href="">News</a>
        <a href="">Contact</a>
        <a href="">About</a>
 </div>

Using above code I am trying to create a navbar but I am not able to give background colour to the topnav div?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

When you have floated child element, the parent div height gets collapsed.
to avoid this you need to clear floats, so that parent can gain height

.topnav::after{
 content:"";
 clear:both;
 display:block;
}
<style>
.topnav{
background-color:palegreen;
}
.topnav a{
float:left;
}

.topnav::after{
content:"";
clear:both;
display:block;
}
</style>

<div class="topnav">
<a href="">home</a>
<a href="">home</a><a href="">home</a><a href="">home</a>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading