CSS: position: fixed and width 90% too wide - css

i'm using position: fixed and width 90% for a footer inside a overlay. The overlay and the footer are both 90% wider but the footer is wider. I guess it's because the footer ignores the scrollbar in chrome. Is there a way to solve this problem without JavaScript?
Here is quick example: https://jsfiddle.net/a15kpuL9/3/
The HTML:
<div class="modal hidden" data-modal-detail="5">
<div class="container">
<div class="body">
<div id="inner-5" class="career-detail-inner-wrap" >
<div class="stickyFooter">
</div>
</div>
</div>
</div>
</div>
The CSS:
.stickyFooter {
width: 90%;
text-align: center;
position: fixed;
bottom: 0;
height: 150px;
background-color: #F5F5F5;
}
.body {
text-align: left;
-webkit-box-shadow: -7px 0 31px 3px rgba(0, 0, 0, 0.16);
display: inline-block;
background-color: white;
border-radius: 10px;
margin-top: 150px;
width: 90%;
}
The Problem:

change the 90% to 90 vw instead. Here you go. :)
.stickyFooter {
width: 90vw;
text-align: center;
position: fixed;
bottom: 0;
height: 150px;
background-color: red;
}
.body {
text-align: left;
-webkit-box-shadow: -7px 0 31px 3px rgba(0, 0, 0, 0.16);
display: inline-block;
background-color: white;
border-radius: 10px;
margin-top: 150px;
width: 90vw;
}
.container {
text-align: center;
vertical-align: middle;
overflow-y: scroll;
height: 100%;
display: block;
width: 100%;
position: absolute;
right: 0;
left: 0;
margin: 0 !important;
max-width: 100%;
padding: 0;
}
.career-detail-inner-wrap {
background: green;
height: 800px
}
<div class="modal hidden" data-modal-detail="5">
<div class="container">
<div class="body">
<div id="inner-5" class="career-detail-inner-wrap">
Inner
<div class="stickyFooter">
Sticky
</div>
</div>
</div>
</div>
</div>

I see one less closing div , could that be the problem
<div class="modal hidden" data-modal-detail="5">
<div class="container">
<div class="body">
</div>
<div id="inner-5" class="career-detail-inner-wrap" >
<div class="stickyFoooterSecond">
</div>
</div>
</div>
</div>
or
<div class="modal hidden" data-modal-detail="5">
<div class="container">
<div class="body">
<div id="inner-5" class="career-detail-inner-wrap" >
<div class="stickyFoooterSecond">
</div>
</div>
</div>
</div>
</div>

Related

CSS puzzle: Children keep breaking into multiple rows

Maybe someone more experienced knows what to do here, as I'm not sure whether this is even possible with CSS or any other way. Currently I have a parent (100% width) and a couple of child elements. All these children need to stay in one row, so when the parent overflows it simply becomes horizontally scrollable. As for now, the child elements keep shifting into multiple rows when the parents width becomes too small. The snippet contains the exact CSS as it is right now, but I have also tried display: inline-block; instead of float: left;.
.container {
padding: 16px 24px;
width: 100%;
}
.parent {
padding: 24px 24px 16px 24px;
overflow-y: hidden;
overflow-x: scroll;
width: 100%;
}
.child {
box-shadow: 0 0 10px 0 rgba(0,0,0,0.10);
background-color: grey;
margin-bottom: 16px;
border-radius: 4px;
margin-right: 24px;
height: 255px;
width: 175px;
float: left;
padding: 0;
}
<div class="container">
<div class-"parent">
<div class="child">
</div>
<div class="child">
</div>
<div class="child">
</div>
<div class="child">
</div>
<div class="child">
</div>
</div>
</div>
This should work in CSS:
.parent {
white-space: nowrap;
overflow: auto;
}
.child {
display: inline-block;
}
Don't forget to remove float: left and overflow x/y.
.container {
padding: 16px 24px;
width: 100%;
white-space: nowrap;
}
.parent {
padding: 24px 24px 16px 24px;
width: 100%;
}
.child {
box-shadow: 0 0 10px 0 rgba(0,0,0,0.10);
background-color: grey;
margin-bottom: 16px;
border-radius: 4px;
margin-right: 24px;
height: 255px;
width: 175px;
padding: 0;
display: inline-block;
}
<div class="container">
<div class-"parent">
<div class="child">
</div>
<div class="child">
</div>
<div class="child">
</div>
<div class="child">
</div>
<div class="child">
</div>
</div>
</div>

Padding at bottom of modal messes up fixed header when scrolled to the bottom

I would like my modal to have a padding on the bottom of it, so that when you reach the bottom of the content when scrolling it looks like this:
instead of this:
The problem I'm having, and you can see it in these two pictures, is that when I try to implement this on my modal (by adding padding to the bottom of the modal), it basically scrolls past the sticky header I have.
Heres a picture of the modal before scrolling:
This is the gist of what code I have so far. I can't get it to look exactly right on here, but essentially if I add padding-bottom:5rem to .modal-content I get the first picture
.modal-background {
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
background-color: rgba(10, 10, 10, .86);
}
.modal-content, .modal-card {
margin: 0 auto;
overflow: auto;
position: relative;
margin-top: 5rem;
width: 60rem;
max-width: 100%;
max-height: calc(100% - 5rem);
}
.modal {
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
align-items: center;
display: block;
justify-content: center;
overflow: hidden;
position: fixed;
z-index: 20;
flex-direction: column;
}
.box{
background-color: white;
border-radius: 5px;
box-shadow: 0 2px 3px rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.1);
color: #4a4a4a;
display: block;
padding: 1.25rem;
}
<div class="modal">
<div class='modal-background' onclick="clearHash()"></div>
<div class="modal-content" style="margin-top:5rem;width: 60rem;max-width:100%;max-height:calc(100% - 5rem);">
<div class="box complete-article-content" id="modalContent" style="padding-bottom: .75rem;">
<div>
<h1 class="title is-4 header" >Modal Title</h1>
<h1 class="title is-5 header" >Modal Subtitle</h1>
<hr style="margin-bottom: 0rem;"/>
</div>
<div style="max-height: calc(100vh - 210px);overflow-y: auto;">
<div id="modalContents" style="margin-top: 1rem;">
<div style="padding-bottom:20rem">
<h1>Beginning of Modal Content</h1>
</div>
<div style="padding-bottom:20rem;padding-top:20rem">
<h1>Middle of Modal Content</h1>
</div>
<div style="padding-top:20rem">
<h1>Bottom of Modal Content</h1>
</div>
</div>
</div>
</div>
</div>
If you don't mind about the usage of flexbox, it could help you a lot to solve your issue without a lot of work:
<div class="modal">
<div class='modal-background' onclick="clearHash()"></div>
<div class="modal-content" style="margin-top:5rem;width: 60rem;max-width:100%;max-height:calc(100% - 5rem);">
<div class="box complete-article-content" id="modalContent" style="padding-bottom: .75rem;">
<div>
<h1 class="title is-4 header" >Modal Title</h1>
<h1 class="title is-5 header" >Modal Subtitle</h1>
<hr style="margin-bottom: 0rem;"/>
</div>
<div style="flex: 1; overflow-y: auto;">
<div id="modalContents" style="margin-top: 1rem;">
<div style="padding-bottom:20rem">
<h1>Beginning of Modal Content</h1>
</div>
<div style="padding-bottom:20rem;padding-top:20rem">
<h1>Middle of Modal Content</h1>
</div>
<div style="padding-top:20rem">
<h1>Bottom of Modal Content</h1>
</div>
</div>
</div>
</div>
</div>
And the CSS:
.modal-background {
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
background-color: rgba(10, 10, 10, .86);
}
.modal-content, .modal-card {
margin: 0 auto;
overflow: auto;
position: relative;
margin-top: 5rem;
width: 60rem;
max-width: 100%;
max-height: calc(100% - 5rem);
display: flex;
}
.modal {
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
align-items: center;
display: block;
justify-content: center;
overflow: hidden;
position: fixed;
z-index: 20;
flex-direction: column;
}
.box{
flex: 1;
box-sizing: border-box;
background-color: white;
border-radius: 5px;
box-shadow: 0 2px 3px rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.1);
color: #4a4a4a;
display: flex;
flex-direction: column;
padding: 1.25rem;
overflow: hidden;
}
To summarise: your problem is the sizing of the boxes which makes the inner box slightly bigger than you expect. That in combination with the overflow: auto; in the CSS class .modal-content causes your result.

Align vertical/horizontal image inside a div(which is inside a container) where the image sizes and ratio varies, and have pading

I want to align images vertical where the image ratio varies, the image can be bigger or not than the content and also have padding;
I tried solutions that I found here, but I didn't found something that covers everything; I need to work in IE9;10
.thumb {
border: 2px solid #4FA738;
border-radius: 0.1875rem;
cursor: pointer;
display: inline-block;
font: 0/0 a;
margin: 0 0.5rem 0 0;
transition: 0.2s;
text-align: center;
}
.thumb img {
max-height: 100%;
max-width: 100%;
width: auto;
height: auto;
display: block;
vertical-align:middle;
margin:auto;
padding: 2px;
}
<div class="thumbs">
<div class="thumb" style="width:70px;height:70px;">
<img src="http://via.placeholder.com/350x150">
</div>
<div class="thumb" style="width:70px;height:70px;">
<img src="http://via.placeholder.com/200x100">
</div>
<div class="thumb" style="width:70px;height:70px;">
<img src="http://via.placeholder.com/140x100">
</div>
<div class="thumb" style="width:70px;height:70px;">
<img src="http://via.placeholder.com/50x50">
</div>
<div class="thumb" style="width:70px;height:70px;">
<img src="http://via.placeholder.com/150x450">
</div>
</div>
The first pure CSS way to achieve the desired result is to do it with the background-image & co. properties:
.thumb {
border: 2px solid #4FA738;
box-shadow: inset 0 0 0 2px #fff; /* 2px margin/padding trick */
border-radius: 0.1875rem;
cursor: pointer;
display: inline-block;
font: 0/0 a;
margin: 0 0.5rem 0 0;
transition: 0.2s;
text-align: center;
width: 70px;
height: 70px;
}
.thumb {
background-repeat: no-repeat;
background-position: center;
background-size: contain; /* keeps / "contains" the ratio */
}
.thumb:first-child {background-image: url(http://via.placeholder.com/350x150)}
.thumb:nth-child(2) {background-image: url(http://via.placeholder.com/200x100)}
.thumb:nth-child(3) {background-image: url(http://via.placeholder.com/140x100)}
.thumb:nth-child(4) {background-image: url(http://via.placeholder.com/50x50)}
.thumb:last-child {background-image: url(http://via.placeholder.com/150x450)}
<div class="thumbs">
<div class="thumb"></div>
<div class="thumb"></div>
<div class="thumb"></div>
<div class="thumb"></div>
<div class="thumb"></div>
</div>
And the second one where you have to sacrifice the border-radius effect:
.thumb {
border: 2px solid #fff;
outline: 2px solid #4FA738;
border-radius: 0.1875rem;
cursor: pointer;
display: inline-block;
font: 0/0 a;
margin: 0 0.5rem 0 0;
transition: 0.2s;
text-align: center;
position: relative;
}
.thumb img {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
max-height: 100%;
max-width: 100%;
width: auto;
height: auto;
display: block;
}
<div class="thumbs">
<div class="thumb" style="width:70px;height:70px;">
<img src="http://via.placeholder.com/350x150">
</div>
<div class="thumb" style="width:70px;height:70px;">
<img src="http://via.placeholder.com/200x100">
</div>
<div class="thumb" style="width:70px;height:70px;">
<img src="http://via.placeholder.com/140x100">
</div>
<div class="thumb" style="width:70px;height:70px;">
<img src="http://via.placeholder.com/50x50">
</div>
<div class="thumb" style="width:70px;height:70px;">
<img src="http://via.placeholder.com/150x450">
</div>
</div>

Overlying Divs with position absolute

I have placed one <div> over another one with position absolute and with 10px padding to the left margin (this is because I want to show a shadow).
The problem is that the content of the base <div> is showed on the left of the header <div>, how to avoid this? If I use border-left instead of padding-left the shadow is not showed.
#container {
background-color: green;
display: flex;
}
.item {
background-color: white;
border: 1px solid black;
flex-grow: 0;
}
.bigContent{
height: 1000px;
width: 1000px;
}
.scroll{
overflow: auto;
height: 300px;
width: 500px;
}
.header{
height: 280px;
width: 200px;
position: absolute;
z-index: 1;
padding-left:10px;
overflow:hidden;
display: inline;
border: solid 1px;
}
.headerContent{
background: lightgrey;
height: 280px;
width: 200px;
box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
}
<div id="container">
<div id="header" class="header">
<div class="headerContent">
<div class="shadow">
<table width="500px">
<tr><td>Header</td></tr>
</table>
</div>
</div>
</div>
<div class="item scroll">
<div class="bigContent">
<table width="500px">
<tr><td>Some content</td><td>Some content</td><td>Some content</td><td>Some content</td><td>Some content</td><td>Some content</td></tr>
</table>
</div>
</div>
</div>
The problem is that the content of the base <div> is showed on the
left of the header <div>, how to avoid this?
You have correctly added padding-left on the header div to allow for the shadow, and the header div is indeed on top of the content. However, the header div has a transparent background by default.
So in order to hide the content below - you could simply add a white background to the header div.
.header {
...
background-color: white;
}
#container {
background-color: green;
display: flex;
}
.item {
background-color: white;
border: 1px solid black;
flex-grow: 0;
}
.bigContent{
height: 1000px;
width: 1000px;
}
.scroll{
overflow: auto;
height: 300px;
width: 500px;
}
.header{
height: 280px;
width: 200px;
position: absolute;
z-index: 1;
padding-left:10px;
overflow:hidden;
display: inline;
border: solid 1px;
background-color: white;
}
.headerContent{
background: lightgrey;
height: 280px;
width: 200px;
box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
}
<div id="container">
<div id="header" class="header">
<div class="headerContent">
<div class="shadow">
<table width="500px">
<tr><td>Header</td></tr>
</table>
</div>
</div>
</div>
<div class="item scroll">
<div class="bigContent">
<table width="500px">
<tr><td>Some content</td><td>Some content</td><td>Some content</td><td>Some content</td><td>Some content</td><td>Some content</td></tr>
</table>
</div>
</div>
</div>

responsive inline block enquiry

I need some advice on this issue i'm having. In the jsfiddle below, I'm trying to create a responsive grid layout. The issue with what i have is, i would like the text to be in the middle of each individual grid. I've tried bumping it using margin-top but instead of the images stacking onto each other while resizing, the images are overlapping each other. The end result desired will be to have the text aligned center onto the image and have no gaps on all sides of the grid when resizing according to various screen resolution.
Link: http://jsfiddle.net/kelvinchow/VaDS9/
<style type="text/css">
#wrapper {
display: block;
width: 100%;
height: auto;
background: green;
}
.box {
display: inline-block;
float: left;
width: 50%;
height: auto;
vertical-align: baseline;
background: red;
}
.box-img img {
width: 100% !important;
height: auto;
}
.box-title {
display: block;
background: grey;
height: 25px;
font-size: 20px;
font-family: helvetica, san serif;
color: blue;
text-align: center;
margin-top: -100px;
}
</style>
<div id="wrapper">
<div class="box">
<div class="box-img">
<img src="http://airinlee.com/wp-content/uploads/2013/06/thumbnail6.png">
</div>
<p class="box-title">howdy</p>
</div>
<div class="box">
<div class="box-img">
<img src="http://airinlee.com/wp-content/uploads/2013/06/thumbnail6.png">
</div>
<p class="box-title">howdy</p>
</div>
<div class="box">
<div class="box-img">
<img src="http://airinlee.com/wp-content/uploads/2013/06/thumbnail6.png">
</div>
<p class="box-title">howdy</p>
</div>
<div class="box">
<div class="box-img">
<img src="http://airinlee.com/wp-content/uploads/2013/06/thumbnail6.png">
</div>
<p class="box-title">howdy</p>
</div>
</div>
You'll get this:
Fiddle here: http://jsbin.com/osazav/1.
With this markup:
<body>
<div id="tl" class="box">
<p class="box-title">howdy</p>
</div>
<div id="tr" class="box">
<p class="box-title">howdy</p>
</div>
<div id="bl" class="box">
<p class="box-title">howdy</p>
</div>
<div id="br" class="box">
<p class="box-title">howdy</p>
</div>
</body>
And this css:
div.box {
background: url('http://airinlee.com/wp-content/uploads/2013/06/thumbnail6.png');
position: absolute;
height: 50%;
width: 50%;
background-size: cover;
background-position: center;
}
div.box p.box-title {
color: red;
background-color: black;
padding: 5px;
position: absolute;
margin: -10px -20px;
top: 50%;
left: 50%;
}
div.box#tl { top: 0%; left: 0%; }
div.box#tr { top: 0%; left: 50%; }
div.box#bl { top: 50%; left: 0%; }
div.box#br { top: 50%; left: 50%; }

Resources