As I embark on the journey of creating a logo and a menu icon for my header, I am encountering an issue where they always exceed the specified height of the header. This unexpected overflow is causing me some frustration.
I am aware that using the overflow:hidden;
property can conceal the overflowing elements, but it does not always provide an optimal solution.
For instance, I attempted to design a hamburger icon, only to be thwarted by this overflow problem. The menu lines behaved as though the entire element was visible, prompting me to hide the overflow in order to make it fit within the confines of the header.
Below is the code snippet -
<header>
<div class="logo">
Elvis
</div>
<div class="menu">
Hamburger Menu
</div>
</header>
The corresponding CSS code -
*{
padding:0px;
margin:0px;
}
header{
height: 60px;
display: flex;
justify-content: space-between;
align-items: center;
border: 2px solid red;
}
.logo {
font-size: 33px;
text-decoration: none;
padding: 20px 30px;
background-color: green;
color: white;
}
.menu {
height: 100px;
width: 100px;
background-color: #bd4439;
}
You can view the complete example on CodePen - https://codepen.io/raghav-sharma333/pen/eYeZYGO
An image showcasing the issue can be found here - Overflowing content
My main inquiries are:
- What is causing this overflow?
&
- How can we prevent or address this issue effectively?