How to prevent an image from scaling outside parent's borders? - css

I have list of different services provided, each service has an image, heading, and description. I've set it up so that image scales to 1.3x size on mouse hover. The scaling works, but it ignores the parent's borders when doing so.
I've captured a GIF of what it looks like in action.
Here is the code I'm working with.
.cleaningservices {
max-width: 250px;
max-height: 250px;
}
/* Default state of the image */
.hover01 img {
-webkit-transform: scale(1);
transform: scale(1);
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}
/* Scale the image to 1.3 it's size on mouse hover */
.hover01:hover img {
-webkit-transform: scale(1.3);
transform: scale(1.3);
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.11.2/css/bootstrap-select.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">
<div class="cleaningservices">
<div class="col-sm-6 col-md-4">
<div class="thumbnail hover01">
<img src="https://bosworthco.com/wp-content/uploads/2016/10/cleaning-268134_960_720.jpg" alt="deep house cleaning">
<div class="caption">
<h3>Deep Cleaning</h3>
<p>Usually, on our first visit we will most likely have to complete a deep cleaning. It is a far more intensive cleaning that our regular cleaning. After first deep cleaning we will continue with one of our regularly scheduled cleanings below.</p>
</div>
</div>
</div>
</div>
</div>
What changes do I have to make to make the images scale inside the parent's borders on mouse hover?

you could add the image to a div and give the div overflow:hidden;
.hover01 img {
-webkit-transform: scale(1);
transform: scale(1);
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
width:100%;
}
.hover01:hover img {
-webkit-transform: scale(1.3);
transform: scale(1.3);
}
.img-parent{
overflow:hidden;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.11.2/css/bootstrap-select.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">
<div class="cleaningservices">
<div class="col-sm-6 col-md-4">
<div class="thumbnail hover01">
<div class="img-parent">
<img src="http://fiusms.fiu.edu/wp-content/uploads/Residential-Cleaning-Watauga-TX.jpg" alt="deep house cleaning">
</div>
<div class="caption">
<h3>Deep Cleaning</h3>
<p>Usually, on our first visit we will most likely have to complete a deep cleaning. It is a far more intensive cleaning that our regular cleaning. After first deep cleaning we will continue with one of our regularly scheduled cleanings below.</p>
</div>
</div>
</div>
</div>
</div>

just use overflow: hidden;
.hover01 img {
-webkit-transform: scale(1);
transform: scale(1);
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
overflow: hidden;
}

Create an img container on which you set overflow: hidden;. I added a background-color on body so you see it works.
body {
background-color: #f0f0f0 !important;
padding: 50px;
}
.noverflow {
overflow: hidden;
}
.thumbnail {
background-color: #fff;
}
.hover01 img {
-webkit-transform: scale(1);
transform: scale(1);
-webkit-transition: .3s ease-in-out;
transition: .3s ease-in-out;
}
.hover01:hover img {
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.11.2/css/bootstrap-select.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">
<div class="cleaningservices">
<div class="col-sm-6 col-md-4">
<div class="thumbnail hover01">
<div class="noverflow"><img src="http://fiusms.fiu.edu/wp-content/uploads/Residential-Cleaning-Watauga-TX.jpg" alt="deep house cleaning"></div>
<div class="caption">
<h3>Deep Cleaning</h3>
<p>Usually, on our first visit we will most likely have to complete a deep cleaning. It is a far more intensive cleaning that our regular cleaning. After first deep cleaning we will continue with one of our regularly scheduled cleanings below.</p>
</div>
</div>
</div>
</div>
</div>

Related

Delay Animation with CSS only

I've got the following code which rotates words with a CSS animation. I'm trying to figure out how to pause the animation on each word, before moving to the next word. I've tried using animation-delay, but that only applies to the start of the animation rather than each item.
How can I pause the animation FOR EACH WORD?
.im {
float: left;
margin-right: 0.3em;
}
.im-wrapper {
display: flex;
height: 1.1em;
}
.im-items {
overflow: hidden;
}
.im-item {
display: block;
height: 100%;
color: $primary;
animation: move 10s infinite;
animation-delay: 1s;
white-space: nowrap;
}
#keyframes move {
0% {
transform: translateY(0%);
}
20% {
transform: translateY(-100%);
}
40% {
transform: translateY(-200%);
}
60% {
transform: translateY(-300%);
}
80% {
transform: translateY(-400%);
}
100% {
transform: translateY(0%);
}
}
<div class="hero-top-title">
<div style="display: inline-block;">
<div>Hi</div>
</div>, I'm
<div style="display: inline-block;">
<div>A Person</div>
</div>.
<br>
<div class="im">Am I a</div>
<div class="im-wrapper">
<div class="im-items">
<div class="im-item im-item1">Father</div>
<div class="im-item im-item2">Mother</div>
<div class="im-item im-item3">Brother</div>
<div class="im-item im-item4">Sister</div>
<div class="im-item im-item5">Grandma</div>
</div>
<div>?</div>
</div>
</div>
How can I pause the animation FOR EACH WORD?
Need to keep the same transform of couple of moment then trigger next. Please follow the code below and you will understand what I mean.
.im {
float: left;
margin-right: 0.3em;
}
.im-wrapper {
display: flex;
height: 1.1em;
}
.im-items {
overflow: hidden;
}
.im-item {
display: block;
height: 100%;
color: $primary;
animation: move 10s infinite;
animation-delay: 1s;
white-space: nowrap;
}
/* Here is the different */
#keyframes move {
0% {
transform: translateY(0%);
}
10% {
transform: translateY(-100%);
}
20% {
transform: translateY(-100%);
}
30% {
transform: translateY(-200%);
}
40% {
transform: translateY(-200%);
}
50% {
transform: translateY(-300%);
}
60% {
transform: translateY(-300%);
}
70% {
transform: translateY(-400%);
}
80% {
transform: translateY(-400%);
}
90% {
transform: translateY(0%);
}
100% {
transform: translateY(0%);
}
}
<div class="hero-top-title">
<div style="display: inline-block;">
<div>Hi</div>
</div>, I'm
<div style="display: inline-block;">
<div>A Person</div>
</div>.
<br>
<div class="im">Am I a</div>
<div class="im-wrapper">
<div class="im-items">
<div class="im-item im-item1">Father</div>
<div class="im-item im-item2">Mother</div>
<div class="im-item im-item3">Brother</div>
<div class="im-item im-item4">Sister</div>
<div class="im-item im-item5">Grandma</div>
</div>
<div>?</div>
</div>
</div>
Delay works only once at the start. So doesn't work with multiple iterations. You need to add blank frames like Feroz suggestd.
Here is a thread about the same topic: CSS animation delay in repeating
What you are trying is some sort of vertical carousel. Look for CSS only carousels. Following is an example, you can repurpose it to slide your text. You need to adjust animation slideMe to change pause time. Click on 'Full page' to see it better.
A codepen demo:
<iframe height="400px" style="width: 100%;" scrolling="no" title="CSS only - A scalable auto sliding carousel -vertical" src="https://codepen.io/onkarruikar/embed/RwZzrMp?default-tab=result&theme-id=dark" frameborder="no" loading="lazy" allowtransparency="true"
allowfullscreen="true">
See the Pen <a href="https://codepen.io/onkarruikar/pen/RwZzrMp">
CSS only - A scalable auto sliding carousel -vertical</a> by OnkarRuikar (#onkarruikar)
on CodePen.
</iframe>

Changing scale of pseudo-element slightly moves the parent element

I made a project with just the important code: git
You can see it on the navbar buttons here(live website of the git project).
This css also changes the color of the moved text on some browsers (friends chrome, but not on mine). Have no clue how to fix it.
.underline {
position: relative;
text-decoration: none;
transition: all 0.35s ease;
}
.underline::before {
content: "";
position: absolute;
width: 100%;
height: 2px;
bottom: 30%;
left: 0;
background-color: white;
visibility: hidden;
-webkit-transform: scaleX(0);
transform: scaleX(0);
-webkit-transition: all 0.3s ease-in-out 0s;
transition: all 0.3s ease-in-out 0s;
}
.underline:hover::before {
visibility: visible;
-webkit-transform: scaleX(0.9);
transform: scaleX(0.9);
}
nav {
height: 100px;
}
.navbar-item {
font-size: 25pt;
}
<nav className="navbar">
<div className="navbar-brand">
<Link href="/">
<a className="navbar-item">
<img src="/trinity-logo.png" />
</a>
</Link>
</div>
<div className="navbar-menu">
<div className="navbar-start">
<Link href="/">
<a className="navbar-item underline">
<b>Hover</b>
</a>
</Link>
<Link href="/">
<a className="navbar-item underline">
<b>Hover</b>
</a>
</Link>
<Link href="/">
<a className="navbar-item underline">
<b>Hover</b>
</a>
</Link>
</div>
</div>
</nav>
those navbar classes are from Bulma(I can't paste all of that css here).

Vertically Animate DOM Element with "align-self-center" Bootstrap Parent

Is it possible to vertically animate a DOM element such as animation-test within a certain bounds while its parent elements maintain vertically centered relative to the body of the document? The inclusion of the Bootstrap class align-self-center in animation-test-parent seems to prevent this from being possible.
For more context, I'm seeking to implement an animation similar to one on mobile Chrome, attached below while maintaining the vertical alignment of my content:
https://imgur.com/a/Dsmhkje
If the above isn't possible, how would you suggest implementing this UI?
Many thanks!
html,
body {
height: 100%;
}
#animation-test {
line-height: 1.5rem;
animation: fadein 2s;
-moz-animation: fadein 2s;
-webkit-animation: fadein 2s;
-o-animation: fadein 2s;
}
#-webkit-keyframes fadein {
0% {
line-height: 280px;
}
/* 100% {line-height: 100px;}*/
}
#-moz-keyframes fadein {
0% {
line-height: 280px;
}
/* 100% {line-height: 100px;}*/
}
#-o-keyframes fadein {
0% {
line-height: 280px;
}
/* 100% {line-height: 100px;}*/
}
#keyframes fadein {
0% {
line-height: 280px;
}
/* 100% {line-height: 100px;}*/
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<!-- Material Design Bootstrap -->
<link href="MDB-Free/css/mdb.min.css" rel="stylesheet">
<body>
<div class="container px-0 h-100">
<div class="row no-gutters h-100">
<div class="col align-self-center">
<div id="animation-test-parent" class="row no-gutters">
<div id="animation-test" class="col">
animation debug
</div>
</div>
</div>
</div>
</div>
</body>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<div class="row no-gutters h-100">
<div class="col align-self-center">
<div id="animation-test-parent" class="row no-gutters">
<div id="animation-test" class="col azk-title">
animation debug
</div>
</div>
</div>
</div>
#animation-test {
line-height: 1.5rem;
animation: fadein 2s;
-moz-animation: fadein 2s;
-webkit-animation: fadein 2s;
-o-animation: fadein 2s;
}
#-webkit-keyframes fadein {
0% {line-height: 280px;}
}
#-moz-keyframes fadein {
0% {line-height: 280px;}
}
#-o-keyframes fadein {
0% {line-height: 280px;}
}
#keyframes fadein {
0% {line-height: 280px;}
}

Bootstrap - I need to zoom image on the mouse hover, but keep its original size

I am trying to create a bootstrap grid with images with some padding, which are zoomed in on hover. The problem is that even after I set overflow to "hidden", they keep blocking the padding line I set - padding is set in the same element and for some reason they override it. For example, when I hover over the left image, it grows a bit and blocks the vertical white line in the middle. How can I force the css to respect the padding?
My html
<div class="row" style="height:100%">
<div class="col-md-6 img-hover" style="padding-right:3px;height:100%;overflow:hidden;">
<img class="img-responsive" src="Images/image.jpg")" style="overflow: hidden" />
</div>
<div class="col-md-6" style="overflow:hidden;height:100%; padding-right: 3px;">
<div class="row">
<img class="img-responsive" src="/Images/image2.jpg")" />
</div>
<div class="row" style="padding-top:3px;height:100%">
<div class="col-md-6" style="padding-left: 0px; padding-right: 3px">
<img class="img-responsive" src="/Images/image3.jpg")" />
</div>
<div class="col-md-6" style="padding-left: 0px; padding-right: 3px">
<img class="img-responsive" src="/Images/image3.jpg")" />
</div>
</div>
</div>
</div>
My css:
.img-hover img {
-webkit-transition: all .3s ease; /* Safari and Chrome */
-moz-transition: all .3s ease; /* Firefox */
-o-transition: all .3s ease; /* IE 9 */
-ms-transition: all .3s ease; /* Opera */
transition: all .3s ease;
overflow:hidden;
}
.img-hover img:hover {
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-webkit-transform:translateZ(0) scale(1.20); /* Safari and Chrome */
-moz-transform:scale(1.10); /* Firefox */
-ms-transform:scale(1.10); /* IE 9 */
-o-transform:translatZ(0) scale(1.10); /* Opera */
transform:translatZ(0) scale(1.10);
}
And this is the image I have. What changes should I do so the zoomed image stops blocking the padding line? Thanks a lot.
You can use overflow: hidden property on <div> block that is containing the <img>. And on :hover use transform: scale(x) property.
Have a look at the snippet below:
.grid-box {
display: flex;
flex-direction: column;
}
.first-row {
display: flex;
}
.grid {
border: 1px solid #fff;
overflow: hidden;
transition: all .3s linear;
}
.one, .two {
width: 100px;
height: 100px;
}
.three {
width: 202px;
height: 100px;
}
.grid:hover img {
transform: scale(2);
transition: all .2s linear;
}
<div class="grid-box">
<div class="first-row">
<div class="grid one">
<img src="http://placehold.it/100x100" alt="" />
</div>
<div class="grid two">
<img src="http://placehold.it/100x100" alt="" />
</div>
</div>
<div class="grid three">
<img src="http://placehold.it/202x100" alt="" />
</div>
</div>
Hope this helps!

addThis Sharing Buttons for Wordpress, how to animate?

I'm looking for a plugin/code that can give some nice mouse hover animation over addThis share buttons, but still want to enjoy the 1-click tweet,like,etc. feature of addThis default buttons.
The one i have now is default, looks like,
What i want is something similar to the one used in arduino.cc blog, the default 1-click buttons are hidden by default and get visible only on mouse hover.
eg:-
How can i achieve this?
You can do this placing custom Images with actual sharing buttons together.
Keep all the sharing button width 0 by default and make them visible on hover by increasing width.
Also add CSS transition to expend the buttons smoothly.
Consider this example.
.sharing-buttons {
float: left;
margin: 5px;
}
.share-button {
float: right;
margin-left: 5px;
overflow: hidden;
transition: all 0.6s ease 0s;
white-space: nowrap;
width: 0;
}
.sharing-buttons:hover .share-button {
width: 100px;
}
<div id="wrapper">
<div class="sharing-buttons fb">
Custom Image
<div class="share-button">Button iframe</div>
</div>
<div class="sharing-buttons tw">
Custom Image
<div class="share-button">Button iframe</div>
</div>
</div>
Edit: Final addThis code & CSS
.addthis_toolbox a.at300b, .addthis_toolbox a.at300m {
padding: 5px;
width: auto;
}
.social-container {
float: left;
margin: 5px;
width:auto;
}
.social-content {
float: right;
margin-left: 5px;
overflow: hidden;
-moz-transition: max-width .3s ease-out;
-webkit-transition: max-width .3s ease-out;
-o-transition: max-width .3s ease-out;
transition: max-width .3s ease-out;
white-space: nowrap;
max-width: 0;
}
.social-container:hover .social-content {
-moz-transition: max-width .2s ease-in;
-webkit-transition: max-width .2s ease-in;
-o-transition: max-width .2s ease-in;
transition: max-width .2s ease-in;
max-width: 95px;
}
<div class="addthis_toolbox addthis_default_style ">
<!-- FACEBOOK -->
<div class="social-container">
<img src="<?php bloginfo('template_directory'); ?>/images/facebook.png" alt="" />
<div class="social-content">
<a class="addthis_button_facebook_like at300b" fb:like:layout="button_count"></a>
</div>
</div>
<!-- G+ -->
<div class="social-container">
<img src="<?php bloginfo('template_directory'); ?>/images/gplus.png" alt="" />
<div class="social-content">
<a class="addthis_button_google_plusone" g:plusone:size="large"></a>
</div>
</div>
<!-- TWITTER -->
<div class="social-container">
<img src="<?php bloginfo('template_directory'); ?>/images/twitter.png" alt="" />
<div class="social-content">
<a class="addthis_button_tweet at300b"></a>
</div>
</div>
</div>

Resources