Why my child container is over lapping on main container [duplicate] - html

This question already has answers here:
How to make an element width: 100% minus padding?
(15 answers)
Closed 12 months ago.
Can anyone tell me how to solve this problem, As you can see my .tab
class is set to 100% width and it's overlapping on the
.main-container class? I also use overflow on my main container
however it began having a scroll can any tell me what is the correct
way to solve this problem? Thank you
.main-container {
border: 1px solid #D8D8D8;
border-radius: 2px;
width: 99%;
margin: 0 auto;
min-height: 10px;
/* overflow: auto; */
margin-top: 3px;
background: blue;
padding: 10px;
}
.tabs {
position: relative;
padding: 10px;
display: inline-block;
background-color: #f2f7fd;
border-radius: 6px;
width: 100%;
border: 1px solid transparent;
color: #333333;
}
.tabs-title {
margin-bottom: 6px;
font-size: 18px;
font-weight: 600;
color: #000000;
line-height: 22px;
padding: 0 2px;
}
.tabs-subtitle {
margin-bottom: 15px;
position: relative;
padding: 0 4px;
line-height: 18px;
}
.tabs-subtitle+hr {
height: 1px;
border: none;
background-color: #7a8a9a;
display: block;
margin-bottom: 15px;
}
.tabs-content {
position: relative;
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
.tabs-rdb {
display: none;
order: 1;
}
.tabs-lbl {
position: relative;
top: 0;
padding: 8px 14px;
padding-bottom: 10px;
cursor: pointer;
background-color: transparent;
display: inline-block;
border-radius: 6px 6px 0 0;
font-size: 13px;
order: 2;
font-weight: normal;
user-select: none;
color: #000000;
}
.tabs.tabs-lbl-bold .tabs-lbl {
font-weight: bold;
}
.tabs-rdb+.tabs-lbl:before {
content: '';
position: absolute;
width: 0;
height: 1px;
border: 6px;
background-color: #2575c4;
bottom: 2px;
left: 50%;
transform: translateX(-50%);
transition: .32s ease width;
opacity: 0;
}
.tabs.tabs-lbl-bold .tabs-rdb+.tabs-lbl:before {
height: 2px;
}
.tabs-lbl:hover {
color: #2575c4;
}
.tabs-lbl:first-of-type {
margin-left: 16px;
}
.tabs-lbl:last-of-type {
margin-right: 16px;
}
.tabs-rdb:checked+.tabs-lbl {
background-color: #ffffff;
color: #2575c4;
box-shadow: 0 1px 3px rgba(0, 0, 0, .14);
}
.tabs-rdb:checked+.tabs-lbl+.tabs-text {
display: block;
}
.tabs-rdb:checked+.tabs-lbl:before {
width: 32%;
opacity: 1;
}
.tabs-text {
display: none;
top: 0;
order: 999;
padding: 10px;
background-color: #ffffff;
border-radius: 6px;
line-height: 18px;
box-shadow: 0 0px 8px -4px rgba(0, 0, 0, .24);
width: 100%;
z-index: 1;
min-height: 38px;
}
<div class="main-container">
<div class="tabs tabs-lbl-bold">
<div class="tabs-title">Main Title (Optional)</div>
<div class="tabs-subtitle">Subtitle Lorem ipsum dolor at met (Optional).</div>
<hr>
<div class="tabs-content">
<input id="nkTabs_a_1" type="radio" class="tabs-rdb" checked name="tabs-a">
<label for="nkTabs_a_1" class="tabs-lbl">Home</label>
<div class="tabs-text">This area is for Home tab.</div>
<!-- -->
<input id="nkTabs_a_2" type="radio" class="tabs-rdb" name="tabs-a">
<label for="nkTabs_a_2" class="tabs-lbl">About</label>
<div class="tabs-text">
This area is for About tab. This area is for About tab. This area is for About tab. This area is for About tab. This area is for About tab.
</div>
<!-- -->
<input id="nkTabs_a_3" type="radio" class="tabs-rdb" name="tabs-a">
<label for="nkTabs_a_3" class="tabs-lbl">Help</label>
<div class="tabs-text">This area is for Help tab. This area is for Help tab.</div>
</div>
</div>
</div>

This overflow is caused by the box-sizing. Just add .tabs { box-sizing: border-box; } and the issue should be fixed.
The default value of box-sizing: content-box does not include the paddings and border. As such 100% width of the parent + paddings and border will always overflow! As such you have an overflow by 22px without border-box
PS: To stop the horizontal overflow of the viewport you should use width: auto instead of width: 99% on the wrapping parent element.
.tabs {
box-sizing: border-box;
}
/* original CSS */
.main-container {
border: 1px solid #D8D8D8;
border-radius: 2px;
width: 99%;
margin: 0 auto;
min-height: 10px;
/* overflow: auto; */
margin-top: 3px;
background: blue;
padding: 10px;
}
.tabs {
position: relative;
padding: 10px;
display: inline-block;
background-color: #f2f7fd;
border-radius: 6px;
width: 100%;
border: 1px solid transparent;
color: #333333;
}
.tabs-title {
margin-bottom: 6px;
font-size: 18px;
font-weight: 600;
color: #000000;
line-height: 22px;
padding: 0 2px;
}
.tabs-subtitle {
margin-bottom: 15px;
position: relative;
padding: 0 4px;
line-height: 18px;
}
.tabs-subtitle+hr {
height: 1px;
border: none;
background-color: #7a8a9a;
display: block;
margin-bottom: 15px;
}
.tabs-content {
position: relative;
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
.tabs-rdb {
display: none;
order: 1;
}
.tabs-lbl {
position: relative;
top: 0;
padding: 8px 14px;
padding-bottom: 10px;
cursor: pointer;
background-color: transparent;
display: inline-block;
border-radius: 6px 6px 0 0;
font-size: 13px;
order: 2;
font-weight: normal;
user-select: none;
color: #000000;
}
.tabs.tabs-lbl-bold .tabs-lbl {
font-weight: bold;
}
.tabs-rdb+.tabs-lbl:before {
content: '';
position: absolute;
width: 0;
height: 1px;
border: 6px;
background-color: #2575c4;
bottom: 2px;
left: 50%;
transform: translateX(-50%);
transition: .32s ease width;
opacity: 0;
}
.tabs.tabs-lbl-bold .tabs-rdb+.tabs-lbl:before {
height: 2px;
}
.tabs-lbl:hover {
color: #2575c4;
}
.tabs-lbl:first-of-type {
margin-left: 16px;
}
.tabs-lbl:last-of-type {
margin-right: 16px;
}
.tabs-rdb:checked+.tabs-lbl {
background-color: #ffffff;
color: #2575c4;
box-shadow: 0 1px 3px rgba(0, 0, 0, .14);
}
.tabs-rdb:checked+.tabs-lbl+.tabs-text {
display: block;
}
.tabs-rdb:checked+.tabs-lbl:before {
width: 32%;
opacity: 1;
}
.tabs-text {
display: none;
top: 0;
order: 999;
padding: 10px;
background-color: #ffffff;
border-radius: 6px;
line-height: 18px;
box-shadow: 0 0px 8px -4px rgba(0, 0, 0, .24);
width: 100%;
z-index: 1;
min-height: 38px;
}
<div class="main-container">
<div class="tabs tabs-lbl-bold">
<div class="tabs-title">Main Title (Optional)</div>
<div class="tabs-subtitle">Subtitle Lorem ipsum dolor at met (Optional).</div>
<hr>
<div class="tabs-content">
<input id="nkTabs_a_1" type="radio" class="tabs-rdb" checked name="tabs-a">
<label for="nkTabs_a_1" class="tabs-lbl">Home</label>
<div class="tabs-text">This area is for Home tab.</div>
<!-- -->
<input id="nkTabs_a_2" type="radio" class="tabs-rdb" name="tabs-a">
<label for="nkTabs_a_2" class="tabs-lbl">About</label>
<div class="tabs-text">
This area is for About tab. This area is for About tab. This area is for About tab. This area is for About tab. This area is for About tab.
</div>
<!-- -->
<input id="nkTabs_a_3" type="radio" class="tabs-rdb" name="tabs-a">
<label for="nkTabs_a_3" class="tabs-lbl">Help</label>
<div class="tabs-text">This area is for Help tab. This area is for Help tab.</div>
</div>
</div>
</div>

Related

Why won't the scrolling container display in my popup window, but works outside of it?

I have a popup window (within the same page) which I'm attempting to put a container which scrolls horizontally into, yet it distorts the popup window and does not display anything other than the scrollbar. I'm honestly at a loss, can anyone help me here? I've looked around for solutions but I can't find anything that I can see applies to my problem.
If anyone can help, or point me in the right direction, I'd be really grateful. The scrollbar works perfectly fine when isolated, but inside the window shows like this:
Standalone:
My HTML (popup window with scrollbar inside)
<div id="formula-popup" class="popup-window">
<div>
<a onclick="closeFormulaWindow()" title="Close" class="close">X</a>
<span id="ftitle" class="title1"></span>
<form method="post" id="formulaform" name="edit">
<span>Current Formula</span>
<p id="current-formula" class="formula">Existing formula</p>
<input id="id-passer" type="hidden" name="formula-id" value="">
<!--sort out horizontal scrollbar from bookmarks here later-->
<input onclick="refreshWindow()" name="edit-formula" type="submit" value="Confirm">
</form>
<div class="h-scrollbar">
<section class="h-scrollbar-container">
<div class="outer-wrapper">
<div class="inner-wrapper">
<div class="pseudo-item"></div>
<div class="pseudo-item"></div>
<div class="pseudo-item"></div>
<div class="pseudo-item"></div>
<div class="pseudo-item"></div>
<div class="pseudo-item"></div>
</div>
</div>
<div class="pseudo-track"></div>
</section>
</div>
</div>
My CSS:
.scrollbar-container {
display: flex;
flex-direction: row;
}
.h-scrollbar {
display: flex;
max-width: 30vw;
padding: 0px 10px;
height: 20vh;
align-items: center;
justify-content: center;
overflow: hidden;
flex-shrink: 0;
}
.h-scrollbar-container {
width: 100%;
}
.outer-wrapper {
max-width: 100vw;
overflow-x: scroll;
position: relative;
scrollbar-color: #d5ac68 #f1db9d;
scrollbar-width: thin;
-ms-overflow-style: none;
}
.pseudo-track {
background-color: #f1db9d;
height: 2px;
width: 100%;
position: relative;
top: -3px;
z-index: -10;
}
.outer-wrapper::-webkit-scrollbar {
height: 5px;
}
.outer-wrapper::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 0px rgba(0, 0, 0, 0);
}
.outer-wrapper::-webkit-scrollbar-thumb {
height: 5px;
background-color: #d5ac68;
}
.outer-wrapper::-webkit-scrollbar-thumb:hover {
background-color: #f1db9d;
}
.outer-wrapper::-webkit-scrollbar:vertical {
display: none;
}
.inner-wrapper {
display: flex;
padding-bottom: 10px;
}
.pseudo-item {
height: 30px;
width: 80px;
margin-right: 15px;
flex-shrink: 0;
background-color: gray;
}
.pseudo-item:nth-of-type(2n) {
background-color: lightgray;
}
.popup-window {
position: fixed;
font-family: Arial, sans-serif;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0, 0, 0, 0.8);
z-index: 9999;
display: none;
}
.popup-window div {
width: 40vw;
height: 30vw;
position: relative;
margin: 10% auto 30%;
border-radius: 10px;
background: #213B54;
padding-top: 2vh;
padding-left: 1vw;
padding-right: 1vw;
padding-bottom: 2vh;
display: flex;
flex-direction: column;
}
.close {
font: Arial, sans-serif;
background: #067A9F;
color: #B5E5E7;
line-height: 25px;
position: absolute;
right: -12px;
text-align: center;
top: -10px;
width: 24px;
text-decoration: none;
font-weight: bold;
border-radius: 12px;
box-shadow: 1px 1px 3px #000;
cursor: pointer;
}
.popup-window div .title1 {
font-family: Arial, sans-serif;
font-weight: normal;
font-size: 36px;
color: #EE6802;
align-self: center;
}
.popup-window form input[type=submit]:hover {
opacity: 0.8;
}
.popup-window form span {
color: #EE6802;
font-size: 22px;
}
.popup-window form {
display: flex;
flex-direction: column;
font-family: Arial, sans-serif;
}
.popup-window form span, input {
width: 100%;
}
.popup-window form input[type=submit] {
width: 20%;
background-color: #067A9F;
color: #213B54;
padding: 14px 0;
cursor: pointer;
border: none;
}
I found the solution, it was that I forgot to select an element inside the window properly and instead it was selecting all divs and so overriding the CSS properties.

CSS - IOS Keyboard shifts whole document up

I have a Text Messaging Mobile Site App that has the following divisions and CSS
.messageDisplay {
background-color: #ffffff;
position: absolute;
z-index: 99999;
height: 100%;
width: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
overflow-y: hidden;
overflow-x: hidden;
visibility: hidden;
display: flex;
flex-direction: column;
justify-content: space-between;
transform: translateY(100%);
}
.messageDisplayHeader {
display: flex;
padding-top: 0.5em;
padding-bottom: 0.5em;
padding-left: 1em;
padding-right: 1em;
align-items: center;
background-color: #ffffff;
position: relative;
box-shadow: rgba(0, 0, 0, 0.16) 0px 1px 4px;
}
.messageDisplayTextboxArea {
height: 3.5em;
position: relative;
box-shadow: rgb(0 0 0 / 16%) 0px -1px 4px;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding-left: 0.5em;
padding-right: 0.5em;
padding-top: 0.2em;
padding-bottom: 0.2em;
background-color: #000000;
}
.messageTextbox {
resize: none;
height: 2.5em;
width: calc(100% - 14%);
background-color: #fef3f1;
border: none;
border-radius: 100px;
padding-left: 1em;
padding-top: 0.5em;
padding-right: 1em;
color: #fc768a;
}
<div class="messageDisplay" id="messageDisplay">
<div class="messageDisplayHeader"></div>
<div class="messageDisplayBody" id="messageDisplayBody">
</div>
<div class="messageDisplayTextboxArea" id="messageDisplayTextboxArea">
<textarea id="messageTextbox" class="messageTextbox" maxlength="300" placeholder="Type a message"></textarea>
<div class="messageSendBtn" id="messageSendBtn">
<i data-feather="chevron-right"></i>
</div>
</div>
</div>
When using an IOS Device to focus in on the textarea the whole page shifts up.
When the textarea is focused out, the page stays shifted upwards.
I tried to solve this by doing the following:
var messageTextBoxEle = document.getElementById('messageTextbox');
messageTextBoxEle.onfocus = function(){
window.scrollTo(0, 0);
document.body.scrollTop = 0;
}
Right now it behaves as such
I also tried setting the page's margin-bottom:0; when the textarea is focused out but it doesnt seem to work.
Anyone have suggestions?

Hide the .message-notif class if there is a record else show if there is no record

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>

Flexbox child ignores parent's padding

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.

Vertically Align <a> text inside a div

I am having trouble vertically aligning the 's text inside a div.
This is what I have. I need to center "Next" inside the blue box:
#import url(http://fonts.googleapis.com/css?family=Muli);
/*Makes the little side arrow*/
.open {
position: fixed;
width: 100px;
height: 40px;
left: 50%;
top: -1000px;
margin-left: -80px;
margin-top: -30px;
border: 1px solid #ccc;
background-color: #fff;
border-radius: 6px;
padding: 10px 30px;
color: #444;
transition: all ease-out 0.6s;
}
.open:hover {
border: 1px solid #aaa;
box-shadow: 0 0 8px #ccc inset;
transition: all ease-out 0.6s;
}
.tutorial-box {
position: fixed;
width: 400px;
height: 238px;
top: 75px;
background-color: #F3F3F3;
border-radius: 6px;
box-shadow: 0px 0px 24px rgba(0, 0, 0, 0.4);
}
.slider-turn p, .tutorial-box h1{
margin-left: 10px;
}
.tutorial-box:before {
content: '';
position: absolute;
left: -14px;
top: 28px;
border-style: solid;
border-width: 10px 14px 10px 0;
border-color: rgba(0, 0, 0, 0) #f3f3f3 rgba(0, 0, 0, 0) rgba(0, 0, 0, 0);
}
.tutorial-box p {
width: 350px;
font-size: 16px;
color: #a8aab2;
font-weight: 400;
line-height: 28px;
float: left;
margin: 0;
}
.tutorial-box .bottom {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
width: 100%;
bottom: 0;
position: absolute;
}
.tutorial-box .bottom .btn-2 {
flex: 3;
-webkit-flex: 3;
-ms-flex: 3;
width: 100%;
height: 54px;
background-color: #373942;
border-bottom-left-radius: 6px;
display: flex;
}
.tutorial-box .bottom span {
flex: 1;
-webkit-flex: 1;
-ms-flex: 1;
line-height: 54px;
color: #fff;
margin-left: 25px;
font-size: 18px;
}
.next {
text-decoration: none;
display: inline-block;
vertical-align: middle;
text-align: center;
flex: 1;
background-color: #6cb5f3;
border: 0;
margin: 0;
padding: 0;
text-transform: uppercase;
color: #fff;
font-weight: bold;
border-bottom-right-radius: 6px;
cursor: pointer;
transition: all .3s;
}
.next:hover {
text-decoration: none;
background-color: #6BA5D6;
transition: all .3s;
}
.next:active {
text-decoration: none;
background-color: #5F8AAF;
}
.slider-tutorial-box {
width: 350px;
margin: 0 25px;
overflow: hidden;
}
.slider-turn {
width: 10000px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- TUTORIAL -->
<div class="tutorial-box">
<h1>Welcome</h1>
<span class="close"></span>
<div class="slider-container">
<div class="slider-turn">
<p>
Here, under the Company tab, is where you will do most of the company managment.<br>
</p>
</div>
</div>
<div class="bottom">
<div class="btn-2">
<span>Step 2/?</span>
</div>
Next
</div>
</div>
Please let me know how I can center the text vertically to the center of the div.
Thank you very much. Let me know if I wasn't clear enough.
Seems like you already did that for .tutorial-box .bottom span so, do the same thing for .next
.next{
line-height: 54px;
}
the simplest and possibly most easy way would be to add the 'center' and '/center' tag before and after the text you want, and after each letter use '/br' to move to the next line. this will add some bulk, but would be considerably easier than other methods.
<center>
'letter'</br>'next letter'</br>'next letter'</br>
</center>
repeating the letter and break for all letters
alternatively, you could also add "div" tags around the "a" tag. you would have to modify the 'height' and 'width' to make it vertical for you. I would use px for this and not '%' or 'em'. add this to them:
<div style="height: /* modify this */100px; width: /* and this*/20px;">
Next
</div>
this may not be AS compatible cross platform though.
Like this:
.next {
position: relative;
top: 50%;
transform: translateY(-50%);
}
A nice trick that works both vertically and horizontally.