I am learning Flexbox and trying to implement by creating a demo portfolio.
I tried this answer to create a fixed sidebar. Then I tried to make sections of my portfolio same dimension using flex: 1, initially it didn't work then I found this answer but it didn't work either.
var myDate = new Date();
var hrs = myDate.getHours();
var greet;
if (hrs < 12)
greet = 'Good Morning';
else if (hrs >= 12 && hrs <= 17)
greet = 'Good Afternoon';
else if (hrs >= 17 && hrs <= 24)
greet = 'Good Evening';
document.getElementById('greet').innerHTML =
greet + ', visitor! <br><br> Welcome.';
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Comfortaa', sans-serif;
font-size: 1.4em;
}
.container {
display: flex;
flex-flow: row nowrap;
height: 100vh;
}
.sidebar {
flex-basis: 25%;
background-color: #bbbbeb;
display: flex;
flex-flow: column;
padding: 10px;
}
.logo {
text-align: center;
font-weight: bold;
}
.navbar {
margin: auto;
}
.content-container {
flex-basis: 75%;
display: flex;
flex-flow: column nowrap;
text-align: center;
overflow: auto;
height: 100vw;
}
section {
padding: 10px;
}
.home {
background-color: red;
flex: 1;
}
.about {
background-color: orange;
flex: 1;
}
.skills {
background-color: orangered;
flex: 1;
}
.contact {
background-color: crimson;
flex: 1;
}
li {
list-style: none;
margin: 10px 0;
text-align: center;
}
a {
color: black;
display: inline-block;
padding: 2px;
text-decoration: none;
}
a:hover {
transform: scale(1.2);
font-weight: bold;
border-bottom: 3px solid black;
text-shadow: 1px 1px 2px rgb(122, 71, 122);
}
<div class="container">
<section class="sidebar">
<div class="logo"><a href="#home"><logo></a></div>
<nav class="navbar">
<ul class="nav-links">
<li><a href="#home">home</a></li>
<li><a href="#about">about me</a></li>
<li><a href="#skills">skills</a></li>
<li><a href="#contact">contact</a></li>
</ul>
</nav>
</section>
<main class="content-container">
<section class="home" id="home">
<h2 id="greet"><span></h2>
</section>
<section class="about" id="about">
<h2>ABOUT</h2>
<h3>
<span>Name</span>
</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
</section>
<section class="skills" id="skills">
<h2>SKILLS</h2>
<h3>Lorem ipsum dolor sit amet.</h3>
<ul class=tech-skills>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
<h3>Lorem</h3>
<ul class="languages">
<li>1</li>
<li>2</li>
</ul>
<h3>Lorem, ipsum.</h3>
<ul class="learning-skills">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</section>
<section class="contact" id="contact">
<h2>CONTACT</h2>
<p>handle</p>
<p>phone</p>
<p>email</p>
</section>
</main>
</div>
As you can see in the CSS, .content-container
has a height of 100vw if I change it to 100vh then flex:1
inside .home
, .about
, .skills
and .contact
won't work but on using 100vw as height, flex:1
works but fixed sidebar doesn't stay fixed anymore.
Is it happening because of flex-flow: column nowrap
on the .content-container
?