How to allow scrolling with overflow visible - css

I've got a grid with many elements, having 3 per row. The idea is that you can scroll through them all till you reach the last element. For that I simply add overflow-y: scroll
At the same time, I've got an onhover effect which scales the hovered element by 1.01. As I've set overflow-y: scroll it cuts off the scaled element.
Here's a fiddle: https://jsfiddle.net/9a5j173x/23/
Notice the shadow is also cut, I'd like for that to be fully visible too.
.gridParent {
height: 300px;
width: 100%;
background-color: #abdbe3;
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 6px;
overflow-y: scroll;
}
.child {
height: 120px;
background-color: #063970;
color: white;
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 150ms;
}
.child:hover {
scale: 1.05;
}
<div class="gridParent">
<div class="child">1</div>
<div class="child">2</div>
<div class="child">3</div>
<div class="child">4</div>
<div class="child">5</div>
<div class="child">6</div>
<div class="child">7</div>
</div>

If you are allowed to have some padding you could use this solution
The trick is to have in .gridParent some padding to "allow content growth" and then use background-clip: content-box, padding-box; to not have colored background on the "padding pixels"
The padding though should be adjusted to your specific sizes, you could play around, 10px works great for fiddle and code snippet below, in real life you might want to calculate it more precisely.
If you are not allowed to have additional padding, then most likely you would need to go to javascript, you check out discussions here - Is it possible to have a popup div that 'breaks out' of an overflow:scroll or overflow:auto container?
.gridParent {
height: 300px;
width: 100%;
background-color: #abdbe3;
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 6px;
padding: 10px;
overflow-y: scroll;
background-clip: content-box, padding-box;
}
.child {
height: 120px;
background-color: #063970;
color: white;
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 150ms;
}
.child:hover {
scale: 1.05;
}
<div class="gridParent">
<div class="child">1</div>
<div class="child">2</div>
<div class="child">3</div>
<div class="child">4</div>
<div class="child">5</div>
<div class="child">6</div>
<div class="child">7</div>
</div>

Just add padding-bottom with a small value to the parent grid container and that works. I've also used the transform-origin with :child selectors so that the left and right elements don't get clipped and the top row moves down.
.gridParent {
height: 300px;
width: 100%;
background-color: #abdbe3;
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 6px;
overflow-y: scroll;
overflow-x: hidden;
padding-bottom: 1rem;
}
.child {
height: 120px;
background-color: #063970;
color: white;
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 150ms;
}
.child:hover {
scale: 1.05;
}
.child:nth-child(3n+1) {
transform-origin: left;
}
.child:nth-child(3n+3) {
transform-origin: right;
}
.child:first-child {
transform-origin: top left;
}
.child:nth-child(2) {
transform-origin: top;
}
.child:nth-child(3) {
transform-origin: top right;
}
<div class="gridParent">
<div class="child">1</div>
<div class="child">2</div>
<div class="child">3</div>
<div class="child">4</div>
<div class="child">5</div>
<div class="child">6</div>
<div class="child">7</div>
</div>

Related

css - common box-shadow for multiple divs without parent

Is there a way to style a row of divs with multiple box-shadows so they look like the box-shadow is on wrapping element?
Due to 3rd party lib limitation I cannot put a box-shadow on a parent element.
Here is the snippet - I cannot really get rid of the spaces between box-shadows.
.container {
/* THIS ELEMENT CANNOT HAVE BOX-SHADOW*/
display: flex;
flex-direction: row;
}
.child {
position: relative;
background-color: grey;
width: 160px;
height: 90px;
box-shadow: 0 -5px 5px -5px #333, 0 5px 5px -5px #333;
}
<div class="container">
<div class="child">1</div>
<div class="child">2</div>
<div class="child">3</div>
</div>
you could apply the shadow to container::before and keep the pseudoelement under the children.
.container {
/* THIS ELEMENT CANNOT HAVE BOX-SHADOW */
display: flex;
flex-direction: row;
position: relative;
width: max-content;
}
.container::before {
content: "";
position: absolute;
z-index: 0;
top: 0; left: 0; right: 0; bottom: 0;
box-shadow: 0 -5px 5px -5px #333, 0 5px 5px -5px #333;
}
.child {
position: relative;
background-color: grey;
width: 160px;
height: 90px;
}
<div class="container">
<div class="child">1</div>
<div class="child">2</div>
<div class="child">3</div>
</div>

How max-width: calc (62.5% - 3rem) must have been calculated to find the right value? Where x and y are integer values

I am working on some UI fix where I want to fix a design to work properly in IE web browser.
Given design has used calc css to define flex value:
.row {
display: flex;
flex-wrap: wrap;
margin-right: -1.5rem;
margin-left: -1.5rem;
}
.list-item {
margin-bottom: 18px;
border: solid 1px brown;
-webkit-box-shadow: 0px 0px 14px 3px rgba(247, 248, 252, 0.7);
box-shadow: 0px 0px 14px 3px rgba(247, 248, 252, 0.7);
background-color: pink;
padding: 16px 16px 12px 16px;
border: solid 1px #f7f8fc;
color: brown
}
.list-item-background {
position: relative;
background-color: black;
}
.personal {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
border-right: solid 1px #e3e7ec;
margin-right: 16px;
}
.col-md-5 {
flex: 0 0 calc( 62.5% - 3rem);
margin-left: 1.5rem;
max-width: calc( 62.5% - 3rem);
}
.data {
margin-left: 0rem;
margin-top: 11px;
}
.col-md-3 {
flex: 0 0 calc( 37.5% - 3rem);
margin-left: 1.5rem;
margin-right: 1.5rem;
max-width: calc( 37.5% - 3rem);
}
<div class="list">
<div class="list-item-background">
<div class="list-item">
<div class="row">
<div class="col-md-5 col-sm-8 col-xs-4 personal">
<div class="avatar">
My image and details
</div>
</div>
<div class="col-md-3 col-sm-8 col-xs-4 data">
<div class="Call">
call button
</div>
</div>
</div>
</div>
</div>
</div>
I have never used calc to define width so I am unable to understand howcome the previous developer has calculate this % and rem value and how I can fix this for IE?
Please find code sample at:
jsfiddle link
Thanks.

Keep row height on animated flex boxes

I'm using flex to display as set of divs and animating the images by setting their width to 95% on hover. This is my CSS:
.container {
display: flex;
flex-wrap: wrap;
align-content: center;
}
.box {
display: flex;
flex-direction: column;
justify-content: center;
margin-top: 1.5%;
align-items: center;
flex: 0 1 48%;
}
.img-container img {
width: 100%;
transition: width ease-in 0.15s;
}
.img-container:hover img {
width: 95%;
transition: width ease-in 0.15s;
}
My problem is that, because of the animation duration, if I hover on images from the top row, for a brief moment both animations are active, forcing the row's height to decrease, which makes the elements beneath it bounce up and down.
Is there a way to force the row to keep its height constant during these animations?
.container {
display: flex;
flex-wrap: wrap;
align-content: center;
}
.box {
display: flex;
flex-direction: column;
justify-content: center;
margin-top: 1.5%;
align-items: center;
margin-right: 2%;
flex: 0 1 48%;
}
.box:nth-of-type(2n) {
margin-right: 0;
}
.img-container {
text-align: center;
position: relative;
animation: fadein 1s;
animation-timing-function: ease-out;
}
.img-container img {
width: 100%;
transition: width ease-in 0.15s;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
.img-container:hover img {
width: 95%;
transition: width ease-in 0.15s;
}
<div class="container">
<div class="box">
<div class="img-container">
<img src="http://via.placeholder.com/800x800?text=1">
</div>
</div>
<div class="box">
<div class="img-container">
<img src="http://via.placeholder.com/800x800?text=2">
</div>
</div>
<div class="box">
<div class="img-container">
<img src="http://via.placeholder.com/800x800?text=3">
</div>
</div>
<div class="box">
<div class="img-container">
<img src="http://via.placeholder.com/800x800?text=4">
</div>
</div>
</div>
Example in this plunker.
You animate with transform: scale() instead. It will give you a much smoother animation and the other elements won't be affected.
.img-container img {
width: 100%;
transition: transform ease-in 0.15s;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
.img-container:hover img {
transform: scale(.95);
}
Stack snippet
.container {
display: flex;
flex-wrap: wrap;
align-content: center;
}
.box {
display: flex;
flex-direction: column;
justify-content: center;
margin-top: 1.5%;
align-items: center;
margin-right: 2%;
flex: 0 1 48%;
}
.box:nth-of-type(2n) {
margin-right: 0;
}
.img-container {
text-align: center;
position: relative;
animation: fadein 1s;
animation-timing-function: ease-out;
}
.img-container img {
width: 100%;
transition: transform ease-in 0.15s;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
}
.img-container:hover img {
transform: scale(.95);
}
<div class="container">
<div class="box">
<div class="img-container">
<img src="http://via.placeholder.com/800x800?text=1">
</div>
</div>
<div class="box">
<div class="img-container">
<img src="http://via.placeholder.com/800x800?text=2">
</div>
</div>
<div class="box">
<div class="img-container">
<img src="http://via.placeholder.com/800x800?text=3">
</div>
</div>
<div class="box">
<div class="img-container">
<img src="http://via.placeholder.com/800x800?text=4">
</div>
</div>
</div>

Any way to get box-shadow only on content-box

It would be lovely to have the option of where to place a box-shadow. Currently I have a div with some padding. The background color is set to clip on the content-box. That's good. However the box-shadow that I have appear on hover begins at the border-box. Perhaps there is some super secret css I don't know (one can wish, right?)
I know I can add another div after .wrapper, but I'm looking to avoid that. More curious if it is actually possible to position the box-shadow on the content-box.
.page {
background: #e9e9e9 none repeat scroll 0 0;
min-height: 100vh;
height:100%;
width: 100%;
}
.container {
width: 30%;
margin: 0 auto;
padding-top: 50px;
}
.wrapper {
padding-bottom: 1em;
padding-right: 1em;
background: white none repeat scroll 0 0;
color: #666;
transition: box-shadow 0.2s ease-in-out 0s;
background-clip:content-box;
}
.wrapper:hover {
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.15);
}
img{width:100%;}
<div class="page">
<div class="container">
<div class="wrapper">
<a href="#">
<img src="http://placekitten.com/g/330/175">
<div class="content-wrapper">
<h4>Events</h4>
<p>Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer?</p>
</div>
</a>
</div>
</div>
You do already have this wrapper you talk about , the <a> around it.
You need to style it too and apply the shadow to it:
.wrapper a {
padding-bottom:1px;/* to deal with collapsing margin if not reset (to <p> here) */
display:block;
transition: box-shadow 0.2s ease-in-out 0s;
}
.wrapper a:hover {
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.15);
}
.page {
background: #e9e9e9 none repeat scroll 0 0;
min-height: 100vh;
height:100%;
width: 100%;
}
.container {
width: 30%;
margin: 0 auto;
padding-top: 50px;
}
.wrapper {
padding-bottom: 1em;
padding-right: 1em;
background: white none repeat scroll 0 0;
color: #666;
background-clip:content-box;
}
.wrapper a {
padding-bottom:1px;
display:block;
transition: box-shadow 0.2s ease-in-out 0s;
}
.wrapper a:hover {
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.15);
}
img{width:100%;}
<div class="page">
<div class="container">
<div class="wrapper">
<a href="#">
<img src="http://placekitten.com/g/330/175">
<div class="content-wrapper">
<h4>Events</h4>
<p>Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer?</p>
</div>
</a>
</div>
</div>
pseudo approach
.page {
background: #e9e9e9 none repeat scroll 0 0;
min-height: 100vh;
height:100%;
width: 100%;
}
.container {
width: 30%;
margin: 0 auto;
padding-top: 50px;
}
.wrapper {
padding-bottom: 1em;
padding-right: 1em;
background: white none repeat scroll 0 0;
color: #666;
background-clip:content-box;
position:relative;
}
.wrapper:before {
content:'';
position:absolute;
pointer-events:none; /* allow to reach links or inside wrapper content */
top:0;
bottom:1em;
left:0;
right:1em;
transition: box-shadow 0.2s ease-in-out 0s;
}
.wrapper:hover:before {
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.15);
}
img{width:100%;}
<div class="page">
<div class="container">
<div class="wrapper">
<a href="#">
<img src="http://placekitten.com/g/330/175">
<div class="content-wrapper">
<h4>Events</h4>
<p>Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer?</p>
</div>
</a>
</div>
</div>
Just use margin-bottom: 1em; margin-right: 1em; in your wrapper instead of padding.
CODE SNIPPET:
.page {
background: #e9e9e9 none repeat scroll 0 0;
min-height: 100vh;
height:100%;
width: 100%;
}
.container {
width: 30%;
margin: 0 auto;
padding-top: 50px;
}
.wrapper {
margin-bottom: 1em;
margin-right: 1em;
background: white none repeat scroll 0 0;
color: #666;
transition: box-shadow 0.2s ease-in-out 0s;
background-clip:content-box;
}
.wrapper:hover {
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.15);
}
img{width:100%;}
<div class="page">
<div class="container">
<div class="wrapper">
<a href="#">
<img src="http://placekitten.com/g/330/175">
<div class="content-wrapper">
<h4>Events</h4>
<p>Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer?</p>
</div>
</a>
</div>
</div>
Another way is to apply the padding-top to the .page class instead of the .container class. A code snippet below might explain
.page {
background: #e9e9e9 none repeat scroll 0 0;
min-height: 100vh;
height: 100%;
width: 100%;
padding-top: 50px;
}
.container {
width: 30%;
margin: 0 auto;
}
.wrapper {
padding-bottom: 1em;
padding-right: 1em;
background: white none repeat scroll 0 0;
color: #666;
transition: box-shadow 0.2s ease-in-out 0s;
}
.wrapper:hover {
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.15);
}
img {
width: 100%;
background-clip: content-box;
}
<div class="page">
<div class="container">
<div class="wrapper">
<a href="#">
<img src="http://placekitten.com/g/330/175">
<div class="content-wrapper">
<h4>Events</h4>
<p>Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer? Want to suggest an event or volunteer?</p>
</div>
</a>
</div>
</div>
</div>
Here's a solution that works with background-clip:content-box;
Use the following instead of box-shadow :
filter: drop-shadow(0 5px 10px rgba(0, 0, 0, 0.15));
-webkit-filter: drop-shadow(0 5px 10px rgba(0, 0, 0, 0.15));

Semantic UI: how to cut down the Item's height

I am using the Semantic UI.
and here is my HTML JSFiddle
:
<div class="ui items" id="test">
<div class="item">
<div class="content">
<div class="meta">two days ago</div>
<div class="name">hello</div>
<div class="extra">ten pages</div>
<p class="description">I am a pythoner</p>
</div>
</div>
</div>
And the CSS:
#test{
height:100px;
}
But it seems that CSS does't work. I can't change the height.
where did these go wrong?
You SemanticUI.css contains some base theming which determines the height of the .item class.
.ui.items>.row>.item, .ui.items>.item {
display: block;
float: left;
position: relative;
top: 0;
width: 316px;
min-height: 375px; /* here */
margin: 0 .5em 2.5em;
padding: 0;
background-color: #FFF;
line-height: 1.2;
font-size: 1em;
-webkit-box-shadow: 0 0 0 1px rgba(0,0,0,.1);
box-shadow: 0 0 0 1px rgba(0,0,0,.1);
border-bottom: .2em solid rgba(0,0,0,.2);
border-radius: .33em;
-webkit-transition: -webkit-box-shadow .2s ease;
transition: box-shadow .2s ease;
padding: .5em;
}
You will need to change or delete that property.

Resources