I’m a beginner and I wanted to replicate this site as a personal project: https://olhauzhykova.com/
I want the header section to remain the same size while the title changes. Also could anyone suggest how I can animate a top-down flip everytime the title changes?
HTML:
<html>
<head>
<link rel="stylesheet" type="text/css" href="webcss.css">
<script src="webjs.js"></script>
</head>
<body>
<div class="header">
<div class="logo"><img src="C:UsersengarDesktopWebsite 2logo.png"></div>
<h1 class="title">Data Analyst</h1>
<h1 class="title hidden">Mentor</h1>
<h1 class="title hidden">Musician</h1>
<h1 class="title hidden">Tech Enthusiast</h1>
</div>
</body>
</html>
CSS:
.header {
background-color: #f1f1f1;
padding: 10px 40px; /* Change the padding value to adjust the width */
border-radius: 20px; /* Round all corners */
position: fixed;
top: 2vh;
left: 2vw;
z-index: 999;
transition: all 0.3s ease-in-out;
display: flex;
align-items: center;
}
.logo {
display: inline-block;
margin-right: 10px;
border: 2px solid #333;
border-radius: 50%;
height: 50px;
width: 50px;
transition: all 0.3s ease-in-out;
}
img {
max-width: 100%;
max-height: 150%;
}
.title {
display: inline-block;
font-size: 24px;
margin: 0;
font-weight: bold;
white-space: nowrap;
transition: all 0.3s ease-in-out;
}
.title.hidden {
display: none; /* hide hidden titles */
}
.header:hover {
transform: scale(1.05);
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
}
.header:hover .logo {
transform: rotate(360deg);
}
.header:hover .title {
margin-left: 10px;
}
.title.hidden {
display: none;
}
JAVASCRIPT
.header {
background-color: #f1f1f1;
padding: 10px 40px; /* Change the padding value to adjust the width */
border-radius: 20px; /* Round all corners */
position: fixed;
top: 2vh;
left: 2vw;
z-index: 999;
transition: all 0.3s ease-in-out;
display: flex;
align-items: center;
}
.logo {
display: inline-block;
margin-right: 10px;
border: 2px solid #333;
border-radius: 50%;
height: 50px;
width: 50px;
transition: all 0.3s ease-in-out;
}
img {
max-width: 100%;
max-height: 150%;
}
.title {
display: inline-block;
font-size: 24px;
margin: 0;
font-weight: bold;
white-space: nowrap;
transition: all 0.3s ease-in-out;
}
.title.hidden {
display: none; /* hide hidden titles */
}
.header:hover {
transform: scale(1.05);
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
}
.header:hover .logo {
transform: rotate(360deg);
}
.header:hover .title {
margin-left: 10px;
}
.title.hidden {
display: none;
}
It would be great if you could suggest tutorials too!
2
Answers
Here is a good source for CSS related topics, this post is related to transitions is a great site for reference.
Welcome to Stack Overflow. This sounds like an ambitious project.
The reason the width of your header is changing is because you’re using
display: none
for the hidden class. This takes it out of the layout, so the container resizes. (https://developer.mozilla.org/en-US/docs/Web/CSS/display)Instead, what you probably want is
visibility: hidden
oropacity: 0
, which leaves the element in the layout. (https://developer.mozilla.org/en-US/docs/Web/CSS/visibility)Since you’ll be working with transitions to create the effect from Olya’s website, I’d recommend going with
opacity
so that you can transition the fade in/out.As for the animation to do the title effect, look into transforms and keyframes. I’d recommend getting familiar with your browser’s Dev Tools so you can investigate for yourself (Ctrl+Shift+I should pull up the inspector). This is taken from Olya’s source code (although, this is unlikely done by hand and probably uses a library of some sort like Framer Motion):