I have tried using flexbox to center a couple buttons and a p but I'm having some troubles.
I have this code
.container {
background: rgb(255, 126, 50, 0.15);
padding: 0 2rem;
border-radius: 0.375rem;
margin: 3.625rem 1.25rem 2rem 1.25rem;
background: black;
}
.layout {
height: calc(100vh - 4.5rem);
background: balck;
}
.loginSection {
width: 50vh;
margin: 0 auto;
border: 1px solid #ffffff;
}
.loginSection p {
display: flex;
align-items: center;
margin: 16px 0;
text-align: center;
width: 12rem;
border: 1px solid #ffffff;
}
.btn-login {
height: 1.25rem;
display: flex;
color: rgba(255, 255, 255, 0.54);
text-decoration: none;
align-items: center;
width: 12rem;
margin: 0 auto;
border: 1px solid #ffffff;
padding: 1rem 1.25rem;
line-height: 1rem;
border-radius: 0.375rem;
font-size: 1rem;
}
.btn-login img {
margin-right: 1rem;
}
.btn-continue {
height: 1.25rem;
display: flex;
color: rgba(255, 255, 255, 0.54);
text-decoration: none;
align-items: center;
width: 12rem;
margin: 0 auto;
border: 1px solid #ffffff;
padding: 1rem 1.25rem;
line-height: 1rem;
border-radius: 0.375rem;
font-size: 1rem;
}
<div class="layout">
<div class="container">
<div class="loginSection">
<button class="btn-login" href="/login">
Log-In
</button>
<p>Enter your email</p>
<button class="btn-continue" href="/home">Continue</button>
</div>
</div>
</div>
But I can center the p
| | Log-In | |
|Enter your email |
| | Continue | |
.container {
background: rgb(255, 126, 50, 0.15);
padding: 0 2rem;
border-radius: 0.375rem;
margin: 3.625rem 1.25rem 2rem 1.25rem;
background: black;
}
.layout {
height: calc(100vh - 4.5rem);
background: balck;
}
.loginSection {
width: 50vh;
margin: 0 auto;
border: 1px solid #ffffff;
}
.layout p {
text-align: center;
width: 12rem;
border: 1px solid #ffffff;
color: white;
margin: auto;
}
.btn-login {
height: 1.25rem;
display: flex;
color: rgba(255, 255, 255, 0.54);
text-decoration: none;
align-items: center;
width: 12rem;
margin: 0 auto;
border: 1px solid #ffffff;
padding: 1rem 1.25rem;
line-height: 1rem;
border-radius: 0.375rem;
font-size: 1rem;
}
.btn-login img {
margin-right: 1rem;
}
.btn-continue {
height: 1.25rem;
display: flex;
color: rgba(255, 255, 255, 0.54);
text-decoration: none;
align-items: center;
width: 12rem;
margin: 0 auto;
border: 1px solid #ffffff;
padding: 1rem 1.25rem;
line-height: 1rem;
border-radius: 0.375rem;
font-size: 1rem;
}
<div class="layout">
<div class="container">
<div class="loginSection">
<button class="btn-login" href="/login">
Log-In
</button>
<p>Enter your email</p>
<button class="btn-continue" href="/home">Continue</button>
</div>
</div>
</div>
Flexbox is typically used by setting flex properties on the parent container to affect the layout of the children inside of that container.
It looks like you're adding display: flex and align-items: center on the .loginSection p element, when flex properties should be set on the parent .loginSection.
If your intention is to center all the elements inside of the .loginSection horizontally, then you can get rid of the flex properties on the children, and add the following rules:
.loginSection {
display: flex;
flex-direction: column;
justify-content: center;
// ... other styles here
}
You'll want to add display:flex with flex-direction: column and align-items:center to the .loginSection container.
Typically when using flex, you flex the container and then the children become "flex-items" rather than flexing the items themselves.
.loginSection {
margin: 0 auto;
display: flex;
flex-direction: column;
align-items:center;
}
.loginSection p { text-align:center; }
<div class="layout">
<div class="container">
<div class="loginSection">
<button class="btn-login" href="/login">
Log-In
</button>
<p>Enter your email</p>
<button class="btn-continue" href="/home">Continue</button>
</div>
</div>
</div>
Or if you want them to all be stretched out use align-items:stretch
.loginSection {
margin: 0 auto;
padding: 1rem; /* optional if you don't want it to stretch the whole width */
display: flex;
flex-direction: column;
align-items:stretch;
}
.loginSection p { text-align:center; }
<div class="layout">
<div class="container">
<div class="loginSection">
<button class="btn-login" href="/login">
Log-In
</button>
<p>Enter your email</p>
<button class="btn-continue" href="/home">Continue</button>
</div>
</div>
</div>
Related
This question already has answers here:
Make container shrink-to-fit child elements as they wrap
(4 answers)
Closed last year.
I am using flex for styling and having an issue with the width of children elements. In my JS Fiddle example, if you look at "Flexible Cancellation" pill badge ... there is a lot of empty space on the right side. How can I update the flex styles so that the width of the pill-badge does not have this extra blank space? It seems that the width of this child element is extending to the entire width of its parent...
JS Fiddle: https://jsfiddle.net/a76bdLvp/1/
Code Areas of Focus (from JS Fiddle):
.left-column {
padding: 12px 12px 12px 16px;
display: flex;
align-items: flex-start;
flex-direction: column;
-webkit-box-flex: 1;
flex: 1 1 0px;
}
.pill-badge {
margin-bottom: 4px;
display: flex;
align-items: flex-start;
flex-direction: column;
}
Current Result
Desired Result
I reviewed this example, which seems very similar ... but applying this solution (or inline-flex to child) did not work. I'd really appreciate your help!
Make flex items take content width, not width of parent container
Add max-width: fit-content; to pill-badge-btn
.main-wrapper {
width: 375px;
}
.flex-container {
display: flex;
flex-wrap: wrap;
border-top: 1px solid rgb(192, 202, 213);
background-color: rgb(255, 255, 255);
border: 1px solid rgb(192, 202, 213);
border-radius: 6px;
box-shadow: rgb(0 0 0 / 8%) 0px 0px 2px 0px, rgb(0 0 0 / 16%) 0px 1px 4px 0px;
cursor: pointer;
margin: 16px 0px;
}
.flex-wrapper {
display: flex;
flex-direction: row;
flex: 1 1 auto;
}
.left-column {
padding: 12px 12px 12px 16px;
display: flex;
align-items: flex-start;
flex-direction: column;
-webkit-box-flex: 1;
flex: 1 1 0px;
}
.right-column {
padding: 8px 8px 8px 12px;
display: flex;
-webkit-box-align: center;
align-items: center;
-webkit-box-pack: end;
justify-content: flex-end;
flex-direction: column;
-webkit-box-flex: 1.25;
flex: 1.25 1 0px;
}
.pill-badge {
margin-bottom: 4px;
display: flex;
align-items: flex-start;
flex-direction: column;
}
.pill-badge-btn {
display: inline-block;
font-weight: 700;
letter-spacing: 0.025em;
text-transform: uppercase;
line-height: 1.4;
padding: 4px 8px;
background-color: rgb(232, 242, 255);
border-radius: 10px;
color: rgb(0, 68, 153);
font-size: 10px;
text-align: left;
max-width: fit-content;
}
button {
-webkit-font-smoothing: antialiased;
display: inline-block;
vertical-align: middle;
text-align: center;
text-decoration: none;
font-family: inherit;
font-weight: 700;
line-height: 1.5;
cursor: pointer;
border-radius: 2px;
border-width: 0px;
border-style: solid;
font-size: 12px;
padding: 7px 12px;
background-color: rgb(0, 170, 0);
color: rgb(255, 255, 255);
width: 100%;
margin-top: 0px;
position: relative;
}
<div class="main-wrapper">
<div class="flex-container">
<div class="flex-wrapper">
<div class="left-column">
<div class="pill-badge">
<div class="pill-badge-btn">
Text
</div>
<div class="pill-badge-btn">
Flexible Cancellation
</div>
</div>
</div>
<div class="right-column">
<button>
Choose Me
</button>
</div>
</div>
</div>
</div>
I am trying to display a div of sections inside of a grid layout but unfortunately the sections only display as block. I am hoping someone will be able to tell me how to display the second portion of the data flexed, currently when I try to select the div inside of Class locationInfo as display flex it does nothing at all.
I want it to look like
but currently it looks like the following
here is my component
<template>
<div id="mainDiv">
<div id="locationInfo">
<!-- left detail section -->
<div>
<section>
<p><b>NYC</b></p>
<small>7:35</small>
</section>
<section>
<img src='../assets/svg/flight.svg' height="40px" width="40px"/>
<small>10/12/20</small>
</section>
<section>
<p><b>SYD</b></p>
<small>10:45</small>
</section>
<div id="AirlinesDetails">
<img src="../assets/svg/home/logo-2.svg" height="40px" width="40px" />
<section>
<b><p>Turkish Airlines</p></b>
<small>cx511 | Airbus 333</small>
</section>
<section>
<p>2 Stop</p>
<small>3h 58min</small>
</section>
</div>
</div>
<!-- second row-->
<div>
<section>
<h4>NYC</h4>
<small>7:35</small>
</section>
<section>
<img src='../assets/svg/flight.svg' height="40px" width="40px"/>
<small>10/19/20</small>
</section>
<section>
<h4>SYD</h4>
<small>10:35</small>
</section>
<div id="AirlinesDetails">
<img src="../assets/svg/home/logo-2.svg" height="40px" width="40px" />
<section>
<b><p>Turkish Airlines</p></b>
<small>cx511 | Airbus 333</small>
</section>
<section>
<p>2 Stop</p>
<small>3h 58min</small>
</section>
</div>
</div>
</div>
</div>
</div>
</template>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
#modal-1{
border: none;
color: black;
}
#modal-1 div{
border: none;
padding-right: 1em;
}
#modalInputdiv1{
margin-top: 1em;
display: flex;
justify-content: left;
}
#modalInputdiv1 div{
border: 1px solid rgba(128, 128, 128, 0.349);
border-radius: 5px;
}
#modalInputdiv1 input{
width: 40%;
height: 2.5em;
border-radius: 5px;
margin-right: 1em;
margin-top: .5em;
border: 1px solid rgba(128, 128, 128, 0.349);
}
#modalInputdiv1 input::placeholder{
padding-left: .5em;
color: black;
}
#modalInputdiv2{
display: flex;
justify-content: left;
margin-top: 1em;
margin-bottom: 1em;
padding-left: .5em;
padding-bottom: .5em;
}
#modalInputdiv2 input::placeholder{
padding-left: .5em;
color: black;
}
#modalInputdiv2 div{
border-radius: 5px;
padding-left: .5em;
border: 1px solid rgba(128, 128, 128, 0.349);
}
#modalInputdiv3{
display: flex;
justify-content: left;
border: 1px solid rgba(128, 128, 128, 0.349);
padding-left: .5em;
}
#modalInputdiv3 div{
width: 50%;
border-radius: 5px;
padding:.5em;
margin-right: 1em;
border: 1px solid rgba(128, 128, 128, 0.349);
}
#modalSaveDiv{
margin-top: 3em;
display: flex;
justify-content: center;
width: 100%;
}
#modalsaveBtn{
background-color:#2E9CFF;
color: white;
border: none;
border-radius: 10px;
height: 40px;
width: 90%;
}
#dob{
border: 1px solid rgba(128, 128, 128, 0.349);
width: 50%;
}
.modalImg{
height: 15px;
width: 15px;
}
#modalInputdiv2 input{
width: 30%;
border-radius: 5px;
margin-right: 1em;
margin-top: .5em;
border: 1px solid rgba(128, 128, 128, 0.349);
}
.modaldivs{
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
width: 40%;
height: 2.5em;
margin-top: .5em;
border: 1px solid rgba(128, 128, 128, 0.349);
border-radius: 5px;
}
#modalInputdiv2 p{
margin-top: .5em;
padding: 0 .5em 0 .5em;
}
#modalInputdiv2 img{
margin-top: .5em;
}
.blocked{
display: block;
}
.blockedflex *{
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
}
.flexed{
display: flex;
}
.toggleSectionActive{
color: #288EF9;
border-bottom: 1px solid #51D79D;
}
#toggleSections{
background-color: white;
}
#sideBarDiv{
justify-content: center;
padding:.5em;
display: block;
background-image: linear-gradient(#0a78f5, #59B0FF);
border-radius: 5px;
box-shadow: 0 1px 2px #88888877;
}
#flyexlogo {
margin-right:1em;
}
#sideBarDiv div{
justify-content: center;
width: 100%;
}
.sideBarDivicons{
display: block;
margin: 0 auto;
margin-top: 2em;
}
#mainDiv{
font-family: 'Noto Sans JP', sans-serif;
color: rgb(73, 79, 90);
width: 100%;
justify-content: center;
margin: 0 auto;
background-color:#F8F8FF;
border-radius: 10px;
}
#bodyGrid{
margin: 1em;
display: grid;
grid-template-columns: 4% 60% 30%;
}
#middleCol div{
margin: .5em;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
}
#middleCol section{
text-align: left;
margin: 1em 1.5em 1em 1.5em;
}
#middleCol section small{
font-weight: 600;
color: #BCC0C7;
}
#middleCol section h5:hover{
color: #288EF9;
}
#detailsDiv{
padding-bottom: 1em;
border-bottom: 1px solid rgba(128, 128, 128, 0.158);
}
#detailsDiv div{
background-color: white;
border-bottom: 1px solid rgba(128, 128, 128, 0.384);
}
.detailsDivHeaderSection{
display: flex;
justify-content: space-between;
margin-left:3em;
}
.detailsDivHeaderSection p{
margin-left:1em;
margin-right:2em;
}
#leftTripDetails{
display: flex;
justify-content: space-between;
}
#change{
color: #288EF9;
}
#locationInfo{
display: grid;
grid-template-columns: 30% 30%;
grid-template-rows: 50% 50%;
background-color: white;
}
#locationInfo div{
width: 45%;
display: flex;
}
#locationInfo div img{
height: 40px;
width: 40px;
display: block;
}
#locationInfo small{
color:rgb(54, 54, 54);
}
#AirlinesDetails{
width: 100%;
border-bottom: 1px solid rgba(128, 128, 128, 0.158);
background-color: white;
}
#AirlinesDetails img{
margin-left: 1em;
width: 35px;
height: 35px;
}
#departureandreturnDiv{
padding: .5em 0 0 .5em;
border-bottom: 1px solid rgba(128, 128, 128, 0.158);
background-color: white;
}
#departureandreturnDiv p{
padding-right: 2.5em;
margin-right: 2em;
color: #BCC0C7;
font-weight: 500;
}
#departureandreturnDiv p:hover{
color: #288EF9;
border-bottom: 2px solid #51D79D;
}
</style>
Have a look at this possible solution with flex and see if it helps.
<div class="flight-container">
<section class="flight">
<div class="flight-info">
<div>
<h4>NYC</h4>
<p><small>7:35</small><p>
</div>
<div>
<img src='../assets/svg/flight.svg' height="40px" width="40px"/>
<p><small>10/19/20</small></p>
</div>
<div>
<h4>SYD</h4>
<p><small>10:35</small></p>
</div>
</div>
<div class="flight-info">
<div>
<div class="row">
<div>
<img src="../assets/svg/home/logo-2.svg" height="40px" width="40px" />
</div>
<div>
<strong>Turkish Airlines</strong></b>
<p><small>cx511 | Airbus 333</small><p>
</div>
</div>
</div>
<div>
<h4>2 Stop</h4>
<p><small>3h 58min</small></p>
</div>
</div>
</section>
<section class="flight">.....</section>
</div>
CSS
.flight-container{
display: flex;
}
.flight{
width: 50%;
}
.flight-info{
display: flex;
justify-content: space-between;
}
.row{
display:flex;
}
Please see code below:
.menu-notif-f {
position: absolute;
top: 50px;
right: 12px;
background-color: #ffffff;
width: 320px;
height: 480px;
overflow: hidden;
border-radius: 8px;
box-shadow: 0 3px 22px 0px rgb(0 0 0 / 15%);
animation: ani_desk_menuuserf .16s ease;
}
.menu-notif-t._title {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px;
color: #555555;
border-bottom: 1px solid #d5fff8;
}
.menu-notif-l._notif-title {
font-size: 16px;
font-weight: 600;
letter-spacing: .04px;
color: #555555;
}
.meni-notif-r._notif-see-all {
font-size: 14px;
font-weight: 500;
letter-spacing: .04px;
color: #01d2af;
}
._profile-c {
background: url(../media/icons/_overview/profile.png);
background-size: 66%;
}
.menu-notif-img {
width: 66px;
height: 66px;
/*height: 9vw;
max-width: 45px;
max-height: 45px;
min-width: 45px;
min-height: 45px;*/
background-color: #ffffff;
border-radius: 50px;
box-shadow: 0 1px 4px rgb(0 0 0 / 12%);
background-repeat: no-repeat;
background-position: center;
padding: 5px;
}
.menu-notif-c._notif-c {
display: flex;
justify-content: space-between;
align-items: center;
padding: 5px;
margin: 5px 5px;
}
.menu-notif-cl {
flex: 0 0 30%;
}
.menu-notif-cr {
flex: 0 0 70%;
}
.menu-notif-dt {
display: flex;
justify-content: space-between;
margin-bottom: 3px;
align-items: center;
}
.menu-notif-name {
font-size: 14px;
font-weight: 600;
color: #01d2af;
}
.menu-notif-time {
font-size: 13px;
font-weight: 600;
color: #657688;
}
.menu-notif-desc {
font-size: 13px;
color: #657688;
display: -webkit-box;
max-width: 100%;
/*height: 30px;*/
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}
.menu-notif-cc::-webkit-scrollbar {
display: none;
}
.menu-notif-cc {
overflow: auto;
height: 420px;
position: absolute;
left: 10px;
right: 10px;
bottom: 10px;
top: 50px;
}
.hdr-noah-c a {
color: #ffffff;
text-decoration: none;
}
<div class="menu-notif-f">
<div class="menu-notif-t _title">
<div class="menu-notif-l _notif-title">Notification</div>
<div class="meni-notif-r _notif-see-all">See All</div>
</div>
<div class="menu-notif-cc">
<div class="menu-notif-c _notif-c">
<div class="menu-notif-cl">
<div class="menu-notif-img _profile-c"></div>
</div>
<div class="menu-notif-cr">
<div class="menu-notif-dt">
<div class="menu-notif-name">Test Name</div>
<div class="menu-notif-time">03:53</div>
</div>
<div class="menu-notif-desc">
Login details need to be update
</div>
</div>
</div>
<div class="menu-notif-c _notif-c">
<div class="menu-notif-cl">
<div class="menu-notif-img _profile-c"></div>
</div>
<div class="menu-notif-cr">
<div class="menu-notif-dt">
<div class="menu-notif-name">Test Name</div>
<div class="menu-notif-time">03:53</div>
</div>
<div class="menu-notif-desc">
Login details need to be update
</div>
</div>
</div>
<!-- This will shown if there is no notification available. Hide if there is an exsiting notification. -->
<div class="message-notif">
<div class="currently-para">There's nothing to be shown as of now</div>
</div>
</div>
</div>
Can anyone help me with this? My goal is if there's a record the .message-notif class will hide and if there is no record The .message-notif class will show. using jQuery? Currently, I don't have any jQuery code that is why the .message-notif is showing, But now there 2 records so meaning the .message-notif should be hidden by now. Please help me with how can I accomplish that transition. Thanks in advance
Usually, for empty-list or things, there is how I manage it without JS : I never remove the item nor hide it. I just say that, if it's the last item in the list, I'll show it.
Let's say that you have a notice list in a div with class .notice-list. Put your 'empty' message in the notice list. Then :
.notice-list > .no-notice-to-show{
display: none;
}
.notice-list > >.no-notice-to-show:last-child{
display: block;
}
When you have a notice, just append your ntoice in the list. The notice will become the last child in your list, causing your 'empty' message to desapear.
Indeed, it doesn't work if you need your empty message to be displayed elsewhere tha tin the empty list. But it's rarely the case.
Used a for loop because you have no #id on the no message div tag, but something like this should work:
var notifications = document.querySelectorAll(".menu-notif-c");
var noNotif = document.querySelectorAll(".message-notif");
if (notifications.length > 0) {
for (let i = 0; i < noNotif.length; i++) {
noNotif[i].style.display = "block";
}
} else {
for (let i = 0; i < noNotif.length; i++) {
noNotif[i].style.display = "none";
}
}
If the <div class="menu-notif-c _notif-c"> wouldn't render if empty, I have a better solution for you.
Just use
.message-notif {display: none;}
.menu-notif-cc > .message-notif:nth-of-type(1) {
display: block;
}
This will hide and display the notification based on the presence of notification messages.
Full code snippet here:
.menu-notif-f {
position: absolute;
top: 50px;
right: 12px;
background-color: #ffffff;
width: 320px;
height: 480px;
overflow: hidden;
border-radius: 8px;
box-shadow: 0 3px 22px 0px rgb(0 0 0 / 15%);
animation: ani_desk_menuuserf .16s ease;
}
.menu-notif-t._title {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px;
color: #555555;
border-bottom: 1px solid #d5fff8;
}
.menu-notif-l._notif-title {
font-size: 16px;
font-weight: 600;
letter-spacing: .04px;
color: #555555;
}
.meni-notif-r._notif-see-all {
font-size: 14px;
font-weight: 500;
letter-spacing: .04px;
color: #01d2af;
}
._profile-c {
background: url(../media/icons/_overview/profile.png);
background-size: 66%;
}
.menu-notif-img {
width: 66px;
height: 66px;
/*height: 9vw;
max-width: 45px;
max-height: 45px;
min-width: 45px;
min-height: 45px;*/
background-color: #ffffff;
border-radius: 50px;
box-shadow: 0 1px 4px rgb(0 0 0 / 12%);
background-repeat: no-repeat;
background-position: center;
padding: 5px;
}
.menu-notif-c._notif-c {
display: flex;
justify-content: space-between;
align-items: center;
padding: 5px;
margin: 5px 5px;
}
.menu-notif-cl {
flex: 0 0 30%;
}
.menu-notif-cr {
flex: 0 0 70%;
}
.menu-notif-dt {
display: flex;
justify-content: space-between;
margin-bottom: 3px;
align-items: center;
}
.menu-notif-name {
font-size: 14px;
font-weight: 600;
color: #01d2af;
}
.menu-notif-time {
font-size: 13px;
font-weight: 600;
color: #657688;
}
.menu-notif-desc {
font-size: 13px;
color: #657688;
display: -webkit-box;
max-width: 100%;
/*height: 30px;*/
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}
.menu-notif-cc::-webkit-scrollbar {
display: none;
}
.menu-notif-cc {
overflow: auto;
height: 420px;
position: absolute;
left: 10px;
right: 10px;
bottom: 10px;
top: 50px;
}
.hdr-noah-c a {
color: #ffffff;
text-decoration: none;
}
.message-notif {display: none;}
.menu-notif-cc > .message-notif:nth-of-type(1) {
display: block;
}
<div class="menu-notif-f">
<div class="menu-notif-t _title">
<div class="menu-notif-l _notif-title">Notification</div>
<div class="meni-notif-r _notif-see-all">See All</div>
</div>
<div class="menu-notif-cc">
<div class="menu-notif-c _notif-c">
<div class="menu-notif-cl">
<div class="menu-notif-img _profile-c"></div>
</div>
<div class="menu-notif-cr">
<div class="menu-notif-dt">
<div class="menu-notif-name">Test Name</div>
<div class="menu-notif-time">03:53</div>
</div>
<div class="menu-notif-desc">
Login details need to be update
</div>
</div>
</div>
<div class="menu-notif-c _notif-c">
<div class="menu-notif-cl">
<div class="menu-notif-img _profile-c"></div>
</div>
<div class="menu-notif-cr">
<div class="menu-notif-dt">
<div class="menu-notif-name">Test Name</div>
<div class="menu-notif-time">03:53</div>
</div>
<div class="menu-notif-desc">
Login details need to be update
</div>
</div>
</div>
<!-- This will shown if there is no notification available. Hide if there is an exsiting notification. -->
<div class="message-notif">
<div class="currently-para">There's nothing to be shown as of now</div>
</div>
</div>
</div>
Same code without the <div class="menu-notif-c _notif-c"> inside the parent <div class="menu-notif-cc">
.menu-notif-f {
position: absolute;
top: 50px;
right: 12px;
background-color: #ffffff;
width: 320px;
height: 480px;
overflow: hidden;
border-radius: 8px;
box-shadow: 0 3px 22px 0px rgb(0 0 0 / 15%);
animation: ani_desk_menuuserf .16s ease;
}
.menu-notif-t._title {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px;
color: #555555;
border-bottom: 1px solid #d5fff8;
}
.menu-notif-l._notif-title {
font-size: 16px;
font-weight: 600;
letter-spacing: .04px;
color: #555555;
}
.meni-notif-r._notif-see-all {
font-size: 14px;
font-weight: 500;
letter-spacing: .04px;
color: #01d2af;
}
._profile-c {
background: url(../media/icons/_overview/profile.png);
background-size: 66%;
}
.menu-notif-img {
width: 66px;
height: 66px;
/*height: 9vw;
max-width: 45px;
max-height: 45px;
min-width: 45px;
min-height: 45px;*/
background-color: #ffffff;
border-radius: 50px;
box-shadow: 0 1px 4px rgb(0 0 0 / 12%);
background-repeat: no-repeat;
background-position: center;
padding: 5px;
}
.menu-notif-c._notif-c {
display: flex;
justify-content: space-between;
align-items: center;
padding: 5px;
margin: 5px 5px;
}
.menu-notif-cl {
flex: 0 0 30%;
}
.menu-notif-cr {
flex: 0 0 70%;
}
.menu-notif-dt {
display: flex;
justify-content: space-between;
margin-bottom: 3px;
align-items: center;
}
.menu-notif-name {
font-size: 14px;
font-weight: 600;
color: #01d2af;
}
.menu-notif-time {
font-size: 13px;
font-weight: 600;
color: #657688;
}
.menu-notif-desc {
font-size: 13px;
color: #657688;
display: -webkit-box;
max-width: 100%;
/*height: 30px;*/
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}
.menu-notif-cc::-webkit-scrollbar {
display: none;
}
.menu-notif-cc {
overflow: auto;
height: 420px;
position: absolute;
left: 10px;
right: 10px;
bottom: 10px;
top: 50px;
}
.hdr-noah-c a {
color: #ffffff;
text-decoration: none;
}
.message-notif {display: none;}
.menu-notif-cc > .message-notif:nth-of-type(1) {
display: block;
}
<div class="menu-notif-f">
<div class="menu-notif-t _title">
<div class="menu-notif-l _notif-title">Notification</div>
<div class="meni-notif-r _notif-see-all">See All</div>
</div>
<div class="menu-notif-cc">
<!-- This will shown if there is no notification available. Hide if there is an exsiting notification. -->
<div class="message-notif">
<div class="currently-para">There's nothing to be shown as of now</div>
</div>
</div>
</div>
My #main element ignores it's wrapper padding. I set position:absolute on children, but when I try to change it from position:static,to position:relative it just ignores parent's height. Any workarounds?
body, html {
height: 100%;
margin: 0;
padding: 0;
}
#wrapper-body {
height: 100%;
display: flex;
flex-direction: column;
}
#wrapper-header {
width: 100%;
flex: 0 1 50px;
background: url("header.png");
display: flex;
align-items: center;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
z-index: 5;
}
#wrapper-main {
flex: 1 1 auto;
display: flex;
align-items: center;
justify-content: center;
position: relative;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
padding: 25px;
}
#wrapper-footer {
width: 100%;
flex: 0 1 auto;
background-color: #212121;
}
#menu {
display: flex;
flex-direction: row;
list-style-type: none;
right: 0;
position: absolute;
}
.menu-button {
background-color: #3B3B3B;
width: 100px;
height: 22px;
margin-right: 15px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
color: #F7F7F7;
border-radius: 2px;
font-family: "codropsicons", verdana;
font-weight: 700;
text-transform: uppercase;
font-size: 14px;
transition: 0.5s;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
text-shadow: 2px 1px 2px rgba(0, 0, 0, 0.3);
}
.active-button, .menu-button:hover {
background-color: #E0962D;
}
#main {
background-color: green;
height: 100%;
width: 100%;
position: absolute;
}
#copyright {
height: 20px;
width: auto;
display: flex;
align-items: center;
font-family: "codropsicons", verdana;
font-weight: 700;
text-transform: uppercase;
font-size: 10px;
color: #F7F7F7;
margin-left: 15px;
opacity: 0.1;
}
<div id="wrapper-body">
<div id="wrapper-header">
<nav id="menu">
<a class="menu-button active-button">O nas</a>
<a class="menu-button">Oferta</a>
<a class="menu-button">Galeria</a>
<a class="menu-button">Kontakt</a>
</nav>
</div>
<div id="wrapper-main">
<main id="main">
Test
<br> Test
<br>
</main>
</div>
<div id="wrapper-footer">
<div id="copyright">Koyot © 2017 All rights reserved</div>
</div>
</div>
https://jsfiddle.net/Ldmmxw9m/3/
It doesn't ignore the parents height when using position: relative, it simply keeps the padding of the parent, but apart from that it fills the parent - see my snippet. Of course the parent's height has to be set when you use a percentage value for the child's height...
#wrapper-main{
flex:1 1 auto;
display:flex;
align-items:center;
justify-content:center;
position:relative;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
padding:25px;
background-color:yellow;
height: 200px;
}
#main{
background-color:green;
height:100%;
width:100%;
position:relative;
}
<div id="wrapper-main">
<main id="main">
some content
</main>
</div>
As Santi said, you can remove position: absolute on #main, since that will place the element relative to it's nearest positioned ancestor, ignoring the ancestor's padding.
Or if that's not an option, you could use top/left/right/bottom values that match the padding amount, and remove the padding on the parent if that's no longer needed.
/* TAGS */
body,
html {
height: 100%;
margin: 0;
padding: 0;
}
/* END OF TAGS */
/* WRAPPERS */
#wrapper-body {
height: 100%;
display: flex;
flex-direction: column;
}
#wrapper-header {
width: 100%;
flex: 0 1 50px;
background: url("header.png");
display: flex;
align-items: center;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
z-index: 5;
}
#wrapper-main {
flex: 1 1 auto;
display: flex;
align-items: center;
justify-content: center;
position: relative;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}
#wrapper-footer {
width: 100%;
flex: 0 1 auto;
background-color: #212121;
}
/* END OF WRAPPERS */
/* CONTENT */
#menu {
display: flex;
flex-direction: row;
list-style-type: none;
right: 0;
position: absolute;
}
.menu-button {
background-color: #3B3B3B;
width: 100px;
height: 22px;
margin-right: 15px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
color: #F7F7F7;
border-radius: 2px;
font-family: "codropsicons", verdana;
font-weight: 700;
text-transform: uppercase;
font-size: 14px;
transition: 0.5s;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
text-shadow: 2px 1px 2px rgba(0, 0, 0, 0.3);
}
.active-button,
.menu-button:hover {
background-color: #E0962D;
}
#main {
background-color: green;
top: 25px;
left: 25px;
right: 25px;
bottom: 25px;
position: absolute;
}
#copyright {
height: 20px;
width: auto;
display: flex;
align-items: center;
font-family: "codropsicons", verdana;
font-weight: 700;
text-transform: uppercase;
font-size: 10px;
color: #F7F7F7;
margin-left: 15px;
opacity: 0.1;
}
<body>
<div id="wrapper-body">
<div id="wrapper-header">
<nav id="menu">
<a class="menu-button active-button">O nas</a>
<a class="menu-button">Oferta</a>
<a class="menu-button">Galeria</a>
<a class="menu-button">Kontakt</a>
</nav>
</div>
<div id="wrapper-main">
<main id="main">
Test
<br> Test
<br>
</main>
</div>
<div id="wrapper-footer">
<div id="copyright">Koyot © 2017 All rights reserved</div>
</div>
</div>
</body>
1. Remove position: absolute; from #main.
Absolutely positioned items are "out of the flow". Setting the parent to relative will modify the absolute child element's bounding box to it's own height and width, but padding is not taken into account.
2. Change the wrapper's align-items: center; to align-items: stretch;
It seems to me that you don't want the child to be vertically-aligned in the middle, but rather to take up the entire height of the wrapper. align-items: stretch will apply this behavior.
Updated Fiddle
/* TAGS */
body,
html {
height: 100%;
margin: 0;
padding: 0;
}
/* END OF TAGS */
/* WRAPPERS */
#wrapper-body {
height: 100%;
display: flex;
flex-direction: column;
}
#wrapper-header {
width: 100%;
flex: 0 1 50px;
background: url("header.png");
display: flex;
align-items: center;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
z-index: 5;
}
#wrapper-main {
flex: 1 1 auto;
display: flex;
align-items: stretch;
justify-content: center;
position: relative;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
padding: 25px;
}
#wrapper-footer {
width: 100%;
flex: 0 1 auto;
background-color: #212121;
}
/* END OF WRAPPERS */
/* CONTENT */
#menu {
display: flex;
flex-direction: row;
list-style-type: none;
right: 0;
position: absolute;
}
.menu-button {
background-color: #3B3B3B;
width: 100px;
height: 22px;
margin-right: 15px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
color: #F7F7F7;
border-radius: 2px;
font-family: "codropsicons", verdana;
font-weight: 700;
text-transform: uppercase;
font-size: 14px;
transition: 0.5s;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
text-shadow: 2px 1px 2px rgba(0, 0, 0, 0.3);
}
.active-button,
.menu-button:hover {
background-color: #E0962D;
}
#main {
background-color: green;
width: 100%;
}
#copyright {
height: 20px;
width: auto;
display: flex;
align-items: center;
font-family: "codropsicons", verdana;
font-weight: 700;
text-transform: uppercase;
font-size: 10px;
color: #F7F7F7;
margin-left: 15px;
opacity: 0.1;
}
<body>
<div id="wrapper-body">
<div id="wrapper-header">
<nav id="menu">
<a class="menu-button active-button">O nas</a>
<a class="menu-button">Oferta</a>
<a class="menu-button">Galeria</a>
<a class="menu-button">Kontakt</a>
</nav>
</div>
<div id="wrapper-main">
<main id="main">
Test<br> Test
<br>
</main>
</div>
<div id="wrapper-footer">
<div id="copyright">Koyot © 2017 All rights reserved</div>
</div>
</div>
</body>
Try adding this to the parent element:
box-sizing:border-box;
This changes how the width and height is calculated by the browser so it includes padding and borders. With flex, using border-box on the parent has corrected spacing issues.
I have three flexbox containers (header, .content__description and footer) and two of them (header and .content__description) don't fit the children's height in Chrome, but only in Firefox. Therefore, the first container is covered by the second one. Why does it occur?
/* util.css */
.break {
width: 100%;
}
/* An issue
html,
body {
height: 100%;
}
*/
/* The solution I found */
html {
height: 100%;
}
body {
min-height: 100%;
}
/* Other styles */
body {
display: flex;
flex-direction: column;
justify-content: space-between;
color: rgb(255, 255, 255);
background-color: rgb(20, 142, 210);
}
header {
display: flex;
flex-direction: row;
justify-content: center;
flex-wrap: wrap;
margin-top: 3em;
margin-bottom: 3em;
}
.header__logo {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
padding-bottom: 1em;
}
.header__logo img {
width: 3em;
height: 3.3em;
margin-right: 0.6em;
}
.header__logo span {
font-size: 5em;
font-weight: 400;
}
.header__slogan {
font-size: 1.5em;
font-weight: 400;
text-align: center;
}
.content {
margin-left: auto;
margin-right: auto;
}
.content__description {
display: flex;
flex-direction: column;
padding-top: 3em;
padding-bottom: 3em;
background-color: rgb(0, 114, 174);
position: relative;
}
.content__description__signin {
position: absolute;
text-decoration: none;
text-align: center;
color: black;
background-color: rgb(254, 190, 0);
box-sizing: border-box;
font-size: 2em;
border: 0.2em rgb(255, 255, 255) solid;
line-height: 1em;
width: 6em;
padding: 0.2em;
top: calc(100% - 0.9em);
left: calc(50% - 3em);
}
.content__description__signin:hover {
background-color: rgb(241, 177, 0);
}
.content__description__strep {
width: 13em;
text-align: center;
font-size: 2em;
box-sizing: border-box;
}
.content__description__strep img {
width: 5em;
height: 5em;
border: 0.2em rgb(255, 255, 255) solid;
border-radius: 50%;
box-shadow: 0.2em 0.5em 1em rgba(0, 0, 0, 0.3);
box-sizing: border-box;
margin-bottom: 1em;
}
.content__description__strep figcaption {
background-color: rgb(2, 98, 148);
padding: 1em;
margin-left: -1em;
margin-right: -1em;
}
footer {
flex-grow: 1;
background-color: rgb(255, 255, 255);
color: rgb(0, 0, 0);
min-height: 1.8em;
}
<body>
<header>
<div class="header__logo">
<img src="images/logo.svg" alt="logo">
<span>Sailing</span>
</div>
<span class="break"></span>
<h1 class="header__slogan">You can!</h1>
</header>
<div class="content">
<div class="content__description">
<figure class="content__description__strep">
<img src="images/meeting.jpg" alt="meeting">
<figcaption>Talking</figcaption>
</figure>
<figure class="content__description__strep">
<img src="images/sailing.jpg" alt="sailing">
<figcaption>Sailing</figcaption>
</figure>
<figure class="content__description__strep">
<img src="images/cinema.jpg" alt="cinema">
<figcaption>Watching</figcaption>
</figure>
Sign in
</div>
</div>
<footer> </footer>
</body>
EDIT #1
The display style of .content__description is changed to "flex" (misprint).
EDIT #2
I've found the solution - switched body {height: 100%} to body {min-height: 100%}. It works perfectly for me.