I'm playing around with CSS and observed some behavior that I could not understand.
Below are my CSS and HTML snippets:
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
body {
font-family: 'Poppins', sans-serif;
}
header {
display: flex;
flex-direction: row;
background-color: antiquewhite;
width: 90%;
margin: auto;
align-items: center;
height: 15vh;
}
.logo-container {
display: flex;
flex: 1;
background-color: rgb(4, 142, 142);
}
.logo {
font-weight: 400;
margin: 20px;
}
img {
/* margin:70px; */
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link href="https://fonts.googleapis.com/css?family=Poppins:400,500&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="./style.css" />
<title>Landing Page</title>
</head>
<body>
<header>
<div class="logo-container">
<img class="imageCont" src="./img/logo.svg" alt="logo">
<h4 class="logo">Three Dots</h4>
</div>
</header>
</body>
</html>
Here are the observations that I am confused about,
If I remove
align-items: center;in<header>, then the image will scale to the entire height of the header. It seems addingalign-items: center;will add a constraint to the height of the image. how does this exactly work?If I remove
align-items: center;and uncommentmargin:70px;then It seems that I can add a margin to the Image, although I have read that margins don't work for inline elements. Why am I seeing this behavior?While
align-items: center;is present, andmargin:70px;is removed fromimgthe margin added to classlogowill also get applied to theimg. However if I remove themargin: 20px;from classlogoand addmargin:70px;toimgthen that margin will not get applied to text with the classlogowhy is this ?