Absolute div inside flexbox div behaving like fixed - html

I'm designing a responsive chat page view on react and i'm struggling with the following problem.
I have a div menu with absolute position which is displayed on top of all the elements when click the menu button as you can see here:
Everything seems ok, even when i resize the screen to phone dimentions it displays as i expect because i have a media query which modifies the left property to fit the div where i want. But on the phone view, when i scroll the page the div moves in its offset position along the screen and i couldn't fixing it:
As far i know this behavior corresponds to fixed position, i've got understood that if i apply an absolute position the div should stays on his place. But i don't know what is happening here. Maybe it may be messing up it because i'm working with flex (everything is positioned with flex using its direction property to arrange my elements).
This is my JSX code:
return (
<div id="chat-page-main-container" onClick={onMainContainerClick}>
<div id="chat-main-menu-select" style={{ display: displayMenu }}>
<ul className="list-group">
<li className="list-group-item">Profile</li>
<li className="list-group-item">Create new group</li>
<li className="list-group-item">Log out</li>
</ul>
</div>
<div id="chat-left-side-content">
<div id="chat-main-menu">
<img
src="https://upload.wikimedia.org/wikipedia/commons/e/e8/The_Joker_at_Wax_Museum_Plus.jpg"
alt="unavailable"
/>
<div id="chat-main-menu-options">
<div className="main-menu-options-icons">
<i id="chat-comment-icon" className="fa fa-comments"></i>
</div>
<div
className="main-menu-options-icons"
style={{ backgroundColor: selectedItem }}
>
<i
id="chat-menu-icon"
className="fa fa-bars"
onClick={onMenuIconClick}
></i>
</div>
</div>
</div>
<div id="search-conversation-bar">
<i className="fa fa-search"></i>
<input type="text" placeholder="Search for a conversation" />
</div>
<div id="chats-component-container">
{data.map((object, index) => (
<ChatCard key={index} data={object} />
))}
</div>
</div>
<div id="chat-right-side-content">
<div id="conversation-splash-screen">
<img src={conversationImage} alt="unavailable" />
<h3>Welcome to tellit chat page!</h3>
<p>
You can search for a contact or a conversation on the left menu.
</p>
</div>
</div>
</div>
);
And this is my SASS code:
::-webkit-scrollbar {
width: 8px
}
::-webkit-scrollbar-track {
background: whitesmoke;
}
::-webkit-scrollbar-thumb {
background: #bababa;
}
#chat-page-main-container {
display: flex;
flex-direction: row;
height: 100%;
overflow-x: auto;
white-space: nowrap;
#chat-main-menu-select {
position: absolute;
top: 4em;
left: 12em;
ul {
border-radius: 5px;
cursor: pointer;
}
li:hover {
background-color: #ededed;
}
}
#chat-left-side-content {
display: flex;
flex-direction: column;
min-width: 400px;
height: 100%;
border-right: solid 1px #bababa;
#chat-main-menu {
width: 100%;
height: 71px;
padding: 10px 25px;
border-bottom: solid 1px #bababa;
background-color: #EDEDED;
img {
width: 50px;
height: 50px;
border-radius: 50%;
float: left;
}
#chat-main-menu-options {
display: flex;
flex-direction: row;
float: right;
height: 100%;
padding-top: 5px;
.main-menu-options-icons {
font-size: 25px;
opacity: 0.5;
text-align: center;
width: 40px;
border-radius: 50%;
margin: 0 10px;
i {
cursor: pointer;
}
}
}
}
#search-conversation-bar {
display: flex;
flex-direction: row;
justify-content: center;
width: 100%;
background-color: #EDEDED;
padding: 10px 0;
border-bottom: solid 1px #bababa;
input {
border-radius: 30px;
border: none;
width: 85%;
height: 40px;
font-family: "Segoe UI";
font-size: 13px;
padding: 0 43px;
&:focus {
outline: none;
}
}
i {
font-size: 20px;
position: relative;
left: 30px;
top: 10px;
}
}
#chats-component-container {
overflow-y: auto;
overflow-x: hidden;
}
}
#chat-right-side-content {
display: flex;
flex-direction: row;
justify-content: center;
width: 100%;
height: 100%;
background-color: white;
#conversation-splash-screen {
display: flex;
flex-direction: column;
align-items: center;
padding-top: 5em;
img {
width: 30em;
height: 30em;
}
}
}
}
#media (max-width: 500px) {
#chat-left-side-content {
min-width: 300px !important;
}
#chat-right-side-content {
min-width: 600px !important;
#conversation-splash-screen {
padding-top: 3em !important;
}
}
#chat-main-menu-select {
left: 6em !important;
}
}
Another fact i want to add is that i also tried to change the absolute position to relative, but this last mess up the container div displaying a space blank or rearranging the elements inside.
Any suggestion or code correction is welcome. Thank you.

set position: relative for parent (#chat-page-main-container)

Related

Flexbox - Search result popup underneath searchbox

I want to learn how to build a textbox that is an auto-expanding sort of search box like you see on Google:
Desired Result
Before
After
High-Level Design
In this design below, I demonstrate that I want it to visually seem as if the textbox itself is expanding. The way I see it, there is an input box for the text, but the height of the underlying searchbox-container is auto expanding on the y-axis.
Attempt
nav {
font-family: "Inter", sans-serif;
display: flex;
border-bottom: 1px solid #b1aeae;
background-color: #f7f7f7;
height: 60px;
width: 100%;
}
.nav-container {
max-width: 925px;
width: 80%;
height: auto;
margin: 0 auto;
}
.search-container {
width: 50%;
display: flex;
align-items: center;
flex-direction: column;
position: relative;
}
.search-box {
border: 1px solid #b7b5b5;
height: 30px;
width: 100%;
background-color: white;
border-radius: 50px;
margin-top: 20px;
display: flex;
align-items: center;
}
.search-icon {
padding-left: 15px;
}
.search-box input[type="text"] {
border: none;
margin-left: 20px;
font-family: "Inter";
width: 70%;
}
.search-box input[type="text"]:focus {
outline-width: 0;
}
.search-results {
display: flex;
flex-direction: column;
width: 98%;
height: auto;
border-radius: 0px;
border-color: #b7b5b5;
border-style: solid;
background-color: white;
border-width: 0px 1px 1px 1px;
border-radius: 0px 0px 20px 20px;
-webkit-box-shadow: 10px 13px 0px 0px rgba(0, 0, 0, 0.07);
-moz-box-shadow: 10px 13px 0px 0px rgba(0, 0, 0, 0.07);
box-shadow: 10px 13px 0px 0px rgba(0, 0, 0, 0.07);
}
.search-result:last-child {
border-bottom: none;
}
.search-result:hover:last-child {
border-bottom: none;
border-radius: 0px 0px 20px 20px;
}
.search-result {
width: 100%;
border-bottom: 1px solid #b7b5b5;
padding-left: 20px;
padding-top: 10px;
padding-bottom: 10px;
}
.search-result:hover {
background-color: #f7f7f7;
}
.links-container {
width: 55%;
height: 100%;
}
<nav>
<div class="nav-container">
<div class="search-container">
<div class="search-box">
<ion-icon name="search-outline" class="search-icon"></ion-icon>
<input type="text" placeholder="Search articles & videos here" />
</div>
<div class="search-results">
<div class="search-result">Result 1</div>
<div class="search-result">Result 2</div>
<div class="search-result">Result 3</div>
</div>
</div>
<div class="links-container"></div>
</div>
</nav>
Current Outcome:
Clearly this is not looking good. I'm new to Flexbox so having some difficulty structuring this to achieve the previously mentioned goal.
This had a lot of stuff that needed to change, so I pretty much rewrote it. Hopefully, I've given you some ideas to build on.
Some points:
display: flex should only be set on a flex container, not on the cell elements.
Use flex-basis if you need to set the width of a flex cell (don't use width).
Don't use margins. Use flex-gap to space out your cells.
Don't set the height unless you have to. Let the flex display try to set it for you first. In this example, we have to set the height of the link elements to keep them from being the same height as the search elements. (Short of using a grid, there's no way around that that I can see.)
Prefer padding to size your elements. (Very much prefer it over height.)
If you want something with two dimensions, don't use flex at all. Use grid. A vertical flex within a horizontal flex is beginning to push the envelope for what flex is intended for (a one-dimensional arrangement of a set of related elements); you could just as well set this up as a grid with blank areas beneath the menu.
As for dynamically resizing the container div, you don't have to do anything special. If you programmatically add elements to the container, flex will take care of resizing it.
Here's some code:
* {
box-sizing: border-box;
}
nav {
min-width: 800px;
padding: 20px;
background-color: #f7f7f7;
width: 100%;
justify-content: center;
display: flex;
column-gap: 40px;
}
a {
text-decoration: none;
padding: 20px;
}
.search-container {
border: 2px solid darkgrey;
border-radius: 20px;
flex-basis: 40%;
display: flex;
flex-direction: column;
justify-content: center;
column-gap: 20px;
z-index: 1;
}
.search-container a, .search-container p {
border-bottom: 1px solid #b7b5b5;
background-color: white;
text-align: center;
}
.search-container p {
margin: 0;
padding: 30px 20px;
border-top-left-radius: 20px;
border-top-right-radius: 20px;
}
.search-container a:last-child {
border: none;
border-bottom-left-radius: 20px;
border-bottom-right-radius: 20px;
}
.links-container {
display: flex;
padding: 10px 0;
flex-basis: 40%;
z-index: 1;
}
.links-container a {
height: 60px;
padding: 20px 40px;
background-color: blue;
color: white;
}
.links-container a:hover {
background-color: green;
}
.header-overlay {
width: 100%;
min-width: 800px;
height: 120px;
background-color: lightgrey;
position: absolute;
}
<body>
<header>
<div class="header-overlay"></div>
<nav>
<div class="search-container">
<p>Search Results</p>
Result 1
Result 2
Result 3
Result 4
Result 5
</div>
<div class="links-container">
One
Two
Three
</div>
</nav>
</header>
</body>
As you can see, this code (especially the HTML) is simpler than yours. Basically, a flex is a container (with display: flex set) and a single set of nested elements. Any of those elements can be a container for another flex. That's what we have here: the nav is a flex with two elements, and each of those elements (search and links) is a flex container as well. A few observations:
Using box-sizing: border-box everywhere will make your life a lot easier. You probably have had the experience of setting up two divs, setting their width to 50%, and being mystified that they won't fit on one line. It's because by default, padding and borders get added onto the outside of the div at the specified width, so its width becomes more than 50%. What this setting does is put padding and borders inside the width instead of outside it.
Notice how to set border-radius for only some of the corners using border-top-left-radius, etc.
Your design appears to want to have your search results drop below the header. This is a bit difficult to do with any setting for the search results themselves. The easier way to do it is to simply "fake" it overlaying a div at the top. You'll see that I've set div.header-overlay to position: absolute. That positions it at the top of the screen. Then, setting the z-index to 1 for both the search and links elements brings them above the header overlay.
When you run the code here, the links take up more than 40% of the horizontal space; that's because the padding I used make it do that. I set the min-width to 800px so it wouldn't look too squashed, but that causes horizontal scrolling here, which isn't the best for an actual page. So, you'll want to play with flex-grow and flex-shrink, as well as media queries and different layouts for different screens, to make the layout more responsive.
That should give you some missing pieces for building flex displays. You can tinker with the markup and settings and learn more.
Hope this works for you!
nav {
display: flex;
border-bottom: 1px solid #b1aeae;
background-color: #f7f7f7;
height: 60px;
width: 100%;
}
.nav-container {
display: flex;
max-width: 925px;
width: 80%;
height: auto;
margin: 0 auto;
}
.search-container {
width: 50%;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
position: relative;
}
.search-box {
border: 1px solid #b7b5b5;
position: absolute;
height: 30px;
width: 100%;
background-color: white;
border-radius: 50px;
padding-left: 20px;
display: flex;
flex-direction: column;
}
.search-results {
width: 90%;
display: flex;
height: 200px;
border-radius: 0px;
border-color: #b7b5b5;
border-style: solid;
background-color: white;
border-width: 0px 1px 1px 1px;
}
.search-result {
width: 100%;
border-bottom: 1px solid blue;
height: 20px;
}
.links-container {
width: 55%;
height: 100%;
}
nav {
display: flex;
border-bottom: 1px solid #b1aeae;
background-color: #f7f7f7;
height: 60px;
width: 100%;
}
.nav-container {
display: flex;
max-width: 925px;
width: 80%;
height: auto;
margin: 0 auto;
}
.search-container {
width: 50%;
display: flex;
justify-content: center;
align-items: top;
flex-direction: row;
position: relative;
}
.search-box {
border: 1px solid #b7b5b5;
position: absolute;
height: 30px;
width: 100%;
background-color: white;
border-radius: 50px;
padding-left: 20px;
display: flex;
flex-direction: column;
}
.search-results {
width: 90%;
display: flex;
flex-direction:column;
align-items: center;
height: 200px;
border-radius: 0px;
border-color: #b7b5b5;
border-style: solid;
background-color: white;
border-width: 0px 1px 1px 1px;
}
.search-result {
position:relative;
text-align:center;
top: 40px;
width: 100%;
border-bottom: 1px solid blue;
height: 20px;
z-index: 9999;
}
.links-container {
width: 55%;
height: 100%;
}
<nav>
<div class="nav-container">
<div class="search-container">
<div class="search-box"></div>
<div class="search-results">
<div class="search-result">Result 1</div>
<div class="search-result">Result 2</div>
<div class="search-result">Result 3</div>
<div class="search-result">Result 4</div>
<div class="search-result">Result 5</div>
</div>
</div>
<div class="links-container"></div>
</div>
</nav>
Add this to align center of div
.search-container {
align-items: top;
flex-direction: row;
}
instead of
.search-container {
align-items: center;
flex-direction: column;
}
And add
.search-results {align-items: center;} to align center
then add to search-result,
.search-result {
position:relative;
text-align:center;
top: 40px;
z-index: 9999;
}
For search result add js
function myFunction() {
var input, filter, ul, li, a, i, txtValue;
input = document.getElementById("search-box");
filter = input.value.toUpperCase();
ul = document.getElementById("search-results");
li = ul.getElementsByTagName("div");
for (i = 0; i < li.length; i++) {
a = li[i];
txtValue = a.textContent || a.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
li[i].style.display = "";
} else {
li[i].style.display = "none";
}
}
}
Working demo
function searching(input) {
input.classList.add("active");
var input, filter, ul, li, a, i, txtValue;
filter = input.value.toUpperCase();
ul = document.getElementById("search-results");
li = ul.getElementsByTagName("div");
for (i = 0; i < li.length; i++) {
a = li[i];
txtValue = a.textContent || a.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
li[i].style.display = "";
} else {
li[i].style.display = "none";
}
}
}
function fun(obj){
obj.classList.add("active");
}
nav {
display: flex;
border-bottom: 1px solid #b1aeae;
background-color: #f7f7f7;
height: 60px;
width: 100%;
}
.nav-container {
display: flex;
max-width: 925px;
width: 80%;
height: auto;
margin: 0 auto;
}
.search-container {
width: 50%;
display: flex;
justify-content: center;
align-items: top;
flex-direction: row;
position: relative;
}
.search-box {
border: 1px solid #b7b5b5;
position: absolute;
height: 30px;
width: 100%;
background-color: white;
border-radius: 50px;
padding:0 30px;
display: flex;
top:18px;
flex-direction: column;
}
.search-box.active{
border:none;
border-bottom:1px solid #b7b5b5;
border-radius:0px;
background:transparent;
}
.search-box.active ~ .search-results{
visibility:visible;
}
.search-results {
width: 100%;
display: flex;
flex-direction:column;
align-items: center;
height: 180px;
background:#fff;
border-radius: 30px;
border: 1px solid #b7b5b5;
visibility:hidden;
margin-top:15px;
}
.search-result {
position:relative;
text-align:center;
top: 40px;
width: 100%;
border-bottom: 1px solid #ccc;
height: 20px;
z-index: 9999;
}
.links-container {
width: 55%;
height: 100%;
}
<nav>
<div class="nav-container">
<div class="search-container">
<input class="search-box" id="search-box" type="search" onkeyup="searching(this)" onfocus="fun(this)" placeholder="Please search fruits..">
<div class="search-results" id="search-results">
<div class="search-result">Apple</div>
<div class="search-result">Mango</div>
<div class="search-result">Orange</div>
<div class="search-result">Grape</div>
<div class="search-result">Watermelon</div>
</div>
</div>
<div class="links-container"></div>
</div>
</nav>

apply different background color to the RHS of the div

I have a div as shown in the below picture and in that picture, you can see a thin grey line from that part I need to cover the whole thing with a different colour. I mean left part will have default BG colour but the right side will have some BG colour. thanks in advance
.root_class {
display: flex;
justify-content: center;
align-items: center;
width: 75%;
margin: 0 auto;
}
.text {
font-size: 3rem;
// color: #bbb;
margin: 0;
margin-right: 10rem;
}
.percentile-card {
transition: 0.3s;
margin: 1rem;
padding: 5px;
border-left: 2px solid #ccc;
}
.percentile-card p {
margin: 0;
}
.percentile-card p:first-child {
color: #bbb;
}
#media (max-width: 768px) {
.root_class {
flex-direction: column;
}
.text {
font-size: 2rem;
margin-right: 0rem;
}
}
<div class="border root_class rhs-background">
<p class="text">Where Do i Stand Overall ?</p>
<div class="percentile-card text-center">
<h4>You did better Than</h4>
<i class="fa fa-users pull-left" style="margin-left: 40px;" aria- hidden="true"></i>
<h5><b>60%</b></h5>
</div>
</div>
I tried this
.rhs-background {
position: fixed;
top: 0px;
left: 0px;
width: 50%;
height: 100%;
background-color: pink;
z-index: 1;
}

Center text under image in flex container

I'm aware of This Question and many others like it. I have reviewed several edge cases similar to mine, and none of the fixes I've tried have worked.
I have an image and text. I want the text centered below the image. What I'm getting is the paragraph always aligned to the left edge of the image and growing to the right, rather than being centered on the image such as the image below. The image itself has even-width transparent borders on each edge, the size of which you can determine by knowing the left edge of the paragraph is aligned with the left edge of the image (it's very small).
body {
background: gray;
}
#myLinks {
margin: 0;
display: flex;
flex-direction: row;
width: 100%;
width: 100vw;
height: 10vh;
background: black;
justify-content: space-around;
}
.menu-card {
height: 15vh;
width: 5vw;
margin: 0;
margin-left: 16%;
border-radius: 45px;
border: none;
padding: 0;
}
.menu-icon-container {
width: 100%;
vertical-align: top;
display: inline-block;
}
.menu-icon {
max-height: 10vh;
max-width: 5vw;
}
.card-text {
position: relative;
margin: 0;
margin-top: 100%;
font-weight: bold;
font-size: 1.2vw;
text-align: center;
border-radius: 45px;
color: white;
display: block;
}
<div id="myLinks">
<div class="menu-card">
<div class="menu-icon-container">
<a href="#">
<img class="menu-icon" src="http://placehold.it/100x300" id="portfolio-icon">
<p class="card-text">Portfolio</p>
</a>
</div>
</div>
</div>
You can use margin:auto to get this fixed.
Add a class .center-items to the parent a tag of the image with the following properties :
.center-items > img,p {
display : block;
margin : auto ;
}
body {
background: gray;
}
#myLinks {
margin: 0;
display: flex;
flex-direction: row;
width: 100%;
width: 100vw;
height: 10vh;
background: black;
justify-content: space-around;
}
.menu-card {
height: 15vh;
width: 50px;
margin: 0;
margin-left: 16%;
border-radius: 45px;
border: none;
padding: 0;
}
.menu-icon-container {
width: 100%;
vertical-align: top;
display: inline-block;
}
.menu-icon {
max-height: 10vh;
max-width: 5vw;
}
.card-text {
position: relative;
margin: 0;
margin-top: 100%;
font-weight: bold;
font-size: 1.2vw;
text-align: center;
border-radius: 45px;
color: white;
display: block;
}
.center-items > img,p {
display : block;
margin : auto ;
}
<div id="myLinks">
<div class="menu-card">
<div class="menu-icon-container">
<a href="#" class="center-items">
<img class="menu-icon" src="http://placehold.it/100x300" id="portfolio-icon">
<p class="card-text">Portfolio</p>
</a>
</div>
</div>
</div>
it may work.. plz modify the css code..
css
*,
*:after,
*:before {
margin: 0;
padding: 0;
/* Removes padding behaviour on widths */
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.menu-card {
margin: 0px;
text-align: center;
}
Thanks to #TheVigilant for putting me on the right path:
.menu-icon-container a {
width: auto;
vertical-align: top;
display: inline-flex;
justify-content : center;
}
.menu-icon-container > img, p {
margin: auto;
display: block;
}

Text Centered and Button Right Justified

How do I make the text appear in the center and the button appear to the right of the box while still being able to nicely scale the screen? Meaning the space between the box and the text will grow when the screen zoomed out and space will shrink when the screen zoomed in.
Here is what I have...
https://imgur.com/a/MigatID
Here is what I want to get...
https://imgur.com/H2gCl0S
EDIT: Here is the JSFiddle...
https://jsfiddle.net/d697spr8/1/
<div id="outer">
<div class="topStuff">
<p>Games</p>
<div class="dropdownListPg">
<button class="dropbtn" style="height: 50px; width: 120px">Sort By
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdownListPg-content" style="color: black">
<button style="height: 50px; width: 120px">Alphabetical</button>
<button style="height: 50px; width: 120px">Date</button>
<button style="height: 50px; width: 120px">User Score</button>
</div>
</div>
</div>
</div>
#outer
{
min-width: 1200px;
}
.topStuff
{
display: flex;
justify-content: center;
margin: 0;
margin-top: 20px;
margin-left: 150px;
margin-right: 150px;
padding: 0;
background-color: #999999;
}
.dropdownListPg
{
display: inline;
}
.dropdownListPg .dropbtn
{
}
.dropdownListPg-content
{
display: none;
position: absolute;
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
width: fit-content;
height: fit-content;
overflow-x: hidden;
margin: 0;
padding: 0;
}
.dropdownListPg-content a
{
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
color: black !important;
margin: 0;
padding: 0;
}
.dropdownListPg-content a:hover
{
background-color: wheat !important;
}
.dropdownListPg:hover .dropdownListPg-content
{
display: block;
}
You can use flex positioning. Also i noticed that you nested <button></button> inside <a></a> it is considered a bad practise to nest interactive element into another interactive element.
Also there is another variant with position: absolute applied to dropdown, but in that case flex is better.
#outer {
min-width: 1200px;
}
.topStuff {
display: flex;
justify-content: center;
margin-top: 20px;
margin-left: 150px;
margin-right: 150px;
background-color: #999999;
}
.holder {
flex: 1 0 auto;
}
.holder--align--right {
display: flex;
justify-content: flex-end;
}
.dropdownListPg {
position: relative;
}
.dropdownListPg-content {
position: absolute;
top: 100%;
z-index: 1;
display: none;
width: 100%;
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}
.dropdownListPg-content a {
display: block;
color: black;
padding: 12px 16px;
text-decoration: none;
text-align: left;
}
.dropdownListPg-content a:hover {
background-color: wheat;
}
.dropdownListPg:hover .dropdownListPg-content {
display: block;
}
<div id="outer">
<div class="topStuff">
<div class="holder"></div>
<p>Games</p>
<div class="holder holder--align--right">
<div class="dropdownListPg">
<button class="dropbtn" style="height: 50px; width: 120px">Sort By
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdownListPg-content">
Alphabetical
Date
User Score
</div>
</div>
</div>
</div>
</div>

Child elements expanding outside parent element with flex

I have used CSS flex to display two divs side by side which are contained inside a wrapper and I have been trying so that inside #myClippetWrapper is where I set the height, so in the child elements of #myClippetWrapper I can just set height: 100%;.
But as you can see from running the snippet below all of the elements inside #myClippetWrapper go outside of the main section, they are all hanging out of the main content div?
I don't want to use overflow: auto because I do not want a scroll bar there, I just need the child elements of #myClippetWrapper to not be outside of the main section/ div.
main {
margin: 0 auto;
margin-top: 10px;
margin-bottom: 10px;
padding: 8px;
background-color: red;
width: 100%;
max-width: 50%;
height: auto;
}
#myClippetWrapper {
display: flex;
height: 700px;
}
#clippetNav {
padding: 10px;
width: 250px;
height: 100%;
background-color: #222222;
margin-right: 10px;
}
#codeAndNotesWrapper {
display: flex;
width: 100%;
}
#codeAndNotesWrapper>div {
flex-basis: 100%;
height: 100%;
}
#codeView {
padding: 10px;
/*flex: 0 0 40%;*/
height: 100%;
background-color: #222222;
margin-right: 10px;
}
#noteView {
padding: 10px;
/*flex: 1;*/
height: 100%;
background-color: #222222;
}
#codeNotesEditor {
height: 100%;
background-color: #EAEAEA;
}
<main>
<div id="myClippetWrapper">
<div id="clippetNav">
</div>
<div id="codeAndNotesWrapper">
<div id="codeView">
</div>
<div id="noteView">
<div id="codeNotesEditor">
</div>
</div>
</div>
</div>
</main>
In many cases, flexbox eliminates the need to use percentage heights.
An initial setting of a flex container is align-items: stretch. This means that in flex-direction: row (like in your code) flex items will automatically expand the full height of the container.
Alternatively, you can use flex-direction: column and then apply flex: 1 to the children, which can also make a flex item expand the full height of the parent.
main {
max-width: 50%;
margin: 10px auto;
padding: 8px;
background-color: red;
}
#myClippetWrapper {
display: flex;
height: 700px;
}
#clippetNav {
display: flex;
padding: 10px;
width: 250px;
margin-right: 10px;
background-color: #222222;
}
#codeAndNotesWrapper {
display: flex;
width: 100%;
}
#codeAndNotesWrapper>div {
display: flex;
flex-basis: 100%;
}
#codeView {
display: flex;
padding: 10px;
margin-right: 10px;
background-color: #222222;
}
#noteView {
display: flex;
flex-direction: column;
padding: 10px;
background-color: #222222;
}
#codeNotesEditor {
flex: 1;
background-color: #EAEAEA;
}
<main>
<div id="myClippetWrapper">
<div id="clippetNav"></div>
<div id="codeAndNotesWrapper">
<div id="codeView"></div>
<div id="noteView">
<div id="codeNotesEditor"></div>
</div>
</div>
</div>
</main>
jsFiddle
Add
box-sizing: border-box;
To your child elements. This will make the padding show on the inside of the box rather than the outside and will not increase the overall size.
Add the box-sizing property..
* {
box-sizing: border-box;
}
main {
margin: 0 auto;
margin-top: 10px;
margin-bottom: 10px;
padding: 8px;
background-color: red;
width: 100%;
max-width: 50%;
height: auto;
}
#myClippetWrapper {
display: flex;
height: 700px;
}
#clippetNav {
padding: 10px;
float: left;
width: 250px;
height: 100%;
background-color: #222222;
margin-right: 10px;
}
#codeAndNotesWrapper {
display: flex;
width: 100%;
}
#codeAndNotesWrapper>div {
flex-basis: 100%;
height: 100%;
}
#codeView {
padding: 10px;
/*flex: 0 0 40%;*/
height: 100%;
background-color: #222222;
margin-right: 10px;
}
#noteView {
padding: 10px;
/*flex: 1;*/
height: 100%;
background-color: #222222;
}
#codeNotesEditor {
height: 100%;
background-color: #EAEAEA;
}
<main>
<div id="myClippetWrapper">
<div id="clippetNav">
</div>
<div id="codeAndNotesWrapper">
<div id="codeView">
</div>
<div id="noteView">
<div id="codeNotesEditor">
</div>
</div>
</div>
</div>
</main>
A big factor with setting your
display: flex;
Is padding and height can make a nasty couple;
Take this example into account:
display: flex;
height: 100%;
padding-top: 1vh;
This would essentially make your element the pages height, plus 1% of the view height, and of course give you a child element thats taller than its parent element.
This isn't a direct answer to your question, instead one to people looking here for why their child elements may be acting up.