CSS transition for border is pushing the button down - html

So I have a border transition on hover and on active for a circular button so the border increases in size. However, the border expands downwards, pushing the button downward. Is there any way to make it so the border expands evenly outward? I've searched this site and others for solutions, and while there are similar questions, they don't answer this specifically.
Thanks!
HTML:
<center><a class="btn" href="#"></a></center
CSS:
.btn {
vertical-align: top;
transform: translateY(20px);
background-color: black;
display: inline-block;
height: 300px;
width: 300px;
border-radius: 50%;
border: 0px solid red;
transition: border-width 0.1s ease-in;
margin: 0.5em;
}
.btn:hover {
border: 20px solid red;
}
.btn:focus {
border: 75px solid red;
}

Instead of using border, you can generate a border effect by placing a pseudoelement behind the button, and transforming its scale on hover and focus as needed.
*also note that <center> is deprecated in HTML5. You can center content with CSS instead.
.btn {
display: block;
margin: 5rem auto;
position: relative;
background-color: black;
height: 300px;
width: 300px;
border-radius: 50%;
transition: border-width 0.1s ease-in;
}
.btn:before {
content: '';
display: block;
position: absolute;
background: red;
border-radius: 50%;
width: 300px;
height: 300px;
z-index: -1;
transition: all .1s ease;
}
.btn:hover:before {
transform: scale(1.1);
}
.btn:focus:before {
transform: scale(1.25);
}
<a class="btn" href="#"></a>

Related

How to make pull up effect during hovering element? Just see this code once

I am trying to create an effect when div class="container" is being hovered, a smooth upper transition occurs of another div from bottom. Only during hover, this should happen cause I want that .bottom div to be hidden. When that div is not hidden, I can see the effect as I want. But as I hide the bottom div, that hovering effect smooth transition effect cannot be seen. Check this code once.
HTML CODE
<div class="box">
Hello
<div class="bottom">
Everyone
</div>
</div>
CSS code
.box{
border: 1px solid black;
display: inline-block;
border-radius: 3px;
padding: 8px;
font-size: 20px;
}
.bottom {
background: pink;
width: 80px;
text-align: center;
position: absolute;
top:80px;
left:0;
/* display: none; */
}
.box:hover .bottom {
display: block;
transition: linear 0.2s;
top:55px;
}
Here is the codepen link
https://codepen.io/Biebk/pen/MWpREqb
First off, rather than display: none to hide the incoming element altogether, you can set its opacity to 0, and then when the parent is hovered, set it to 1, like so:
.bottom {
opacity: 0;
}
.box:hover .bottom {
opacity: 1;
}
I suppose that given you want an incoming "pull-up" effect on hover, you want to that element to also "pull-down" when the hover ends. You can reverse the same effect by using a :not(:hover) on the parent element:
.box:not(:hover) .bottom {
opacity: 0;
}
Also, be sure to set the transition on the non-hovered state. The following example provides the smooth transition you're looking for:
.box {
border: 1px solid black;
display: inline-block;
border-radius: 3px;
padding: 8px;
font-size: 20px;
}
.bottom {
background: pink;
width: 80px;
text-align: center;
position: absolute;
left: 0;
transition: all .25s ease;
}
.box:not(:hover) .bottom {
top: 80px;
opacity: 0;
}
.box:hover .bottom {
top: 55px;
opacity: 1;
}
<div class="box">
Hello
<div class="bottom">
Everyone
</div>
</div>
A secondary approach would be to place the bottom div as a sibling to the box, and use the adjacent sibling combinator to apply the hover effects:
.box {
border: 1px solid black;
display: inline-block;
border-radius: 3px;
padding: 8px;
font-size: 20px;
}
.bottom {
font-size: 20px;
background: pink;
width: 80px;
text-align: center;
position: absolute;
left: 0;
top: 80px;
opacity: 0;
cursor: default;
transition: all .25s ease;
}
.box:hover + .bottom {
top: 55px;
opacity: 1;
}
<div class="box">
Hello
</div>
<div class="bottom">
Everyone
</div>
Use opacity property rather than display to achieve the desired effect, then
use the following code
.box {
border: 1px solid black;
display: inline-block;
border-radius: 3px;
padding: 8px;
font-size: 20px;
}
.bottom {
background: pink;
width: 80px;
text-align: center;
position: absolute;
top: 80px;
left: 0;
opacity: 0;
}
.box:hover .bottom{
opacity: 1;
transition: opacity 0.2s , top 1s;
top: 55px;
}
Use the following code.
.box {
border: 1px solid black;
display: inline-block;
border-radius: 3px;
padding: 8px;
font-size: 20px;
}
.hovered{
transition: all .2s;
}
.bottom {
background: pink;
width: 80px;
text-align: center;
position: absolute;
top: 80px;
left: 0;
visibility: hidden;
}
.hovered:hover+.bottom {
transition: all .2s;
top: 55px;
visibility: visible;
}
<div class="box">
<div class="hovered">Hello</div>
<div class="bottom">
Everyone
</div>
</div>

Image transition on hover

I am having two different issues. The first is really irritating. I am attempting to align the text with the image inside of the first box, so that they are side-by-side an inline fashion. I am not sure what I am doing wrong and I do not want to use floats.
Secondly, I am attempting to get the image to transform: translate on the x-axis on hover. The thing is, I want the image to transform on the .extra-box:hover...not on the actual image, but I only want the image to move. I cannot figure this out.
What am I doing wrong?
#extra {
margin: 25px auto;
width: 460px;
height: auto;
}
.extra-box {
position: relative;
width: 40%;
padding: 8px;
border-radius: 3px;
/*border: 1px solid #739BAF;*/
border: 2px solid black;
display: inline-block;
background: none;
transition: 0.5s ease;
}
.extra-box:hover {
border: 2px solid red;
transition: 0.5s ease;
}
.extra-box:first-child {
margin-left: 0;
width: 40%;
margin-right: 10%;
}
.extra-box:last-child {
width: 40%;
}
.extra-box a {
text-decoration: none;
}
.extra-box-text {
color: black;
font-size: 1em;
display: inline-block;
width: auto;
}
.extra-box-icon img {
padding-left: 5px;
width: 15px;
height: auto;
display: inline-block;
-webkit-transition: all .5 ease-in-out;
transition: all .5 ease-in-out;
/*transform: translateX(30px);
-webkit-transform: translateX(30px);*/
}
<div id="extra"><div class="extra-box">
<a href="contact">
<div class="extra-box-text">Need help?<br>Contact Us Now</div><div class="extra-box-icon"><img src="icons/right-arrow.png"></div>
</a>
</div><div class="extra-box">
<a href="register">
<div class="extra-box-text">Need an account?<br>Register Now</div>
</a>
</div>
</div>
As other answers pointed out, you were missing a display: inline-block, but the problem was in .extra-box-icon
I have also added the transform for the image: (See the beginning of the CSS)
.extra-box-icon {
display: inline-block;
}
img {
transition: transform 1s;
}
.extra-box:hover img {
transform: translateX(-100px);
}
#extra {
margin: 25px auto;
width: 460px;
height: auto;
}
.extra-box {
position: relative;
width: 40%;
padding: 8px;
border-radius: 3px;
/*border: 1px solid #739BAF;*/
border: 2px solid black;
display: inline-block;
background: none;
transition: 0.5s ease;
}
.extra-box:hover {
border: 2px solid red;
transition: 0.5s ease;
}
.extra-box:first-child {
margin-left: 0;
width: 40%;
margin-right: 10%;
}
.extra-box:last-child {
width: 40%;
}
.extra-box a {
text-decoration: none;
}
.extra-box-text {
color: black;
font-size: 1em;
display: inline-block;
width: auto;
}
.extra-box-icon img {
padding-left: 5px;
width: 15px;
height: auto;
display: inline-block;
-webkit-transition: all .5 ease-in-out;
transition: all .5 ease-in-out;
/*transform: translateX(30px);
-webkit-transform: translateX(30px);*/
}
<div id="extra">
<div class="extra-box">
<a href="contact">
<div class="extra-box-text">Need help?
<br>Contact Us Now</div>
<div class="extra-box-icon">
<img src="icons/right-arrow.png">
</div>
</a>
</div>
<div class="extra-box">
<a href="register">
<div class="extra-box-text">Need an account?
<br>Register Now</div>
</a>
</div>
</div>
Add vertical-align:top; in .extra-box class to align it to same level.
to fix the alignment issue and if you don't want to use float, you can change the display property of .extra-box-text and extra-box-text img to inline-block
.extra-box-text, .extra-box-text img{
display:inline-block;
width: /*adjust as needed*/
}
to deal with the animation, i suggest you set the image itself as a background of .extra-box, you would then change the background-position on hover
Hope this helps

bootstrap caption in jumbotron

Is it possible to caption a background image that I put in a Bootstrap Jumbotron? I would like the caption to slide up from the bottom and be semi-transparent. The thing is, my background image is in the css, like this:
.jumbotron {
background-image: url('../img/honeycomb.jpg');
background-repeat: no-repeat;
background-position: 100%;
padding: 200px 0 140px 0;
margin-bottom: 70px;
text-align: center;
padding-bottom: 50px;
}
I have searched for answers, but all are related to inline images. Thanks for any insight you can give.
My_neck_hurts, have a look at this Fiddle.
This code will use css to get the image into the jumbotron and it also has a caption that slides up from the bottom.
I added some notes in the css to help if you want to change some things at any time.
Normally you would set the width via the class in the css but using bootstrap here we just use the col-lg-X etc to control this as you will see in the code.
This way it keeps it responsive.
In the css comments also show where to adjust the height for how far you want the slider to come up. If you want to slider to cover the full height then there is two places you need to change, both are commented so it is easy to find.
Hope it help to get you started.
body {
padding-top: 50px;
}
.block {
height: 600px;
padding-top:20px;
}
.whatishere:before {
content: "?";
position: absolute;
top:20%;
left:11%;
font-weight: 800;
background: black;
text-shadow: 0 0 5px white;
color: black;
width: 100px;
height: 100px;
-webkit-border-radius: 120px;
-moz-border-radius: 120px;
border-radius: 120px;
text-align: center;
font-size: 30px;
line-height: 100px;
-moz-transition: all 0.6s ease;
opacity: 0.5;
}
.whatishere:hover:before {
opacity: 0;
}
/* The Box Style */
.box {
border: 5px solid #fff;
cursor: pointer;
height: 300px;
float: left;
margin: 5px;
position: relative;
overflow: hidden;
/* width: 300px; */ /* use col-lg-X to set the width */
-webkit-box-shadow: 1px 1px 1px 1px #ccc;
-moz-box-shadow: 1px 1px 1px 1px #ccc;
box-shadow: 1px 1px 1px 1px #ccc;
}
/* Caption Style */
.caption {
background-color: rgba(0,0,0,0.4);
position: absolute;
color: #fff;
z-index: 100;
-webkit-transition: all 300ms ease-out;
-moz-transition: all 300ms ease-out;
-o-transition: all 300ms ease-out;
-ms-transition: all 300ms ease-out;
transition: all 300ms ease-out;
left: 0;
}
/* The Slide Caption style */
.slide-caption {
height: 150px; /* set the height of the caption div */
/* width: 300px; */ /* use col-lg-X to set the width */
display: block;
bottom: -150px; /* hide the caption for how tall it is */
line-height: 20px;
text-align: center;
}
/* The Slide Caption :hover Behaviour */
.box:hover .slide-caption {
-moz-transform: translateY(-100%);
-o-transform: translateY(-100%);
-webkit-transform: translateY(-100%);
opacity: 1;
transform: translateY(-100%);
}
.image {
background-image: url(http://img1.goodfon.su/original/1920x1080/b/b3/soty-pchela-med-fon-nasekomoe.jpg);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
I didn't really get what you wanted to do with that image. But if your issue is that you can't edit the HTML to insert an inline image you can still put your image in a :before or :after like this :
.jumbotron:after {
content: url('../img/honeycomb.jpg');
display: inline;
}
At that point, you can apply the solutions you read for inline images. You can also give it an absolute position, etc.
Look at this jsfiddle. Is this the kind of effect you want ? Or do you want it to be animated ?
https://jsfiddle.net/bdasilva/kmjuz212/1/
Hope it helped.
My_neck_hurts, Ok so you are almost there.
Just wanted the body to hold the image.
Here is the Fiddle with it doing that.
I've changed the background of the jumbotron to be transparent if that helps.
The image is a public image on the internet. It came up in a google search.
.bodyimage {
background-image: url(http://img1.goodfon.su/original/1920x1080/b/b3/soty-pchela-med-fon-nasekomoe.jpg);
background-position: center;
background-repeat: no-repeat;
height:100vh;
width:100%;
z-index: -100;
}
.bg-clear {
background-color: rgba(250,250,250, 0.3);
}

Hide element behind transparent div

I'm trying to make next animation: logo should be revealed by the div moving down. Div has a transparent background.
Is it possible to hide overlaying part of logo behind transparent div?
<div class="transparent">Some content</div>
<div class="logo"></div>
.transparent { position: relative }
.logo { position: absolute }
I very much doubt if you could clip or mask anything behind a transparent element.
So, perhaps you need to rethink the "hiding behind" part and consider other options.
Perhaps animating the height:
* {
padding: 0;
margin: 0;
}
.transparent {
height: 2em;
line-height: 2em;
border-bottom: 1px solid grey;
position: relative;
}
.logo {
height: 0;
background: orange;
position: absolute;
top: 100%;
width: 100px;
transition: height 0.5s ease;
}
.transparent:hover .logo {
height: 25px; /* assuming height is known */
}
<div class="transparent">Some content
<div class="logo"></div>
</div>
you can try giving visibility hidden property to hide the logo.
visibility:hidden
Maybe an effect like this may help that background of logo is the same as background of the div you are referring to as transparent.
Like this: http://codepen.io/anon/pen/aOwZLJ
You will need to do some complex calculations, if the background is an image, in order to make it look as one element.
You can try this too. Related mostly to hide some part of border.
div {
border-top: 1px solid black;
border-right: 1px solid black;
width: 50px;
height: 50px;
position: relative;
overflow: hidden;
}
div::after {
content: "";
height: 50px;
width: 100%;
border: 1px solid green;
display: block;
position: absolute;
border-right: 0px;
border-top:0px;
border-bottom: 0px;
top: -10px;
}
div::before {
content: "";
height: 50px;
width: 100%;
border: 1px solid green;
display: block;
position: absolute;
border-right: 0px;
border-top:0px;
border-left: 0px;
top: -1px;
left: 10px;
}
<div>
</div>
In 2021, it's actually possible, with some trickery.
First of all, overflow-y:hidden hides something from the bottom... unless it's upside down.
The wrapper should have any height, as long as it can serve as a cut off.
.wrapper {
height: 70px;
position: relative;
overflow-y: hidden;
transform: rotate(180deg);
}
.logo {
animation-name: stretch;
animation-duration: 2s;
animation-timing-function: linear;
transform-origin: top;
}
#keyframes stretch {
0% {
transform: translateY(110px) rotate(180deg);
}
100% {
transform: translateY(40px) rotate(180deg);
}
}
So now the logo will slide down from a seemingly transparent background.

Cleaning up CSS jitters

I've built these circles that expand a border when there is a mouseover. The only problem I'm getting now is some times the circle will jitter/shake. And it becomes more apparent when I set the transition: all .1s ease-in-out; to more than .2s.
Is there a work around to this problem or is that just the way it is?
Here's the code in JsFiddle
Thanks for any and all help!
EDIT: I am transitioning the dimensions (width and height) of the circles to maintain centering. I realize this is causing the jittering during the transition. Is there a work around?
I got rid of the percent values for top/left positioning, cleaned up the margins and aligned the border-width of the outer circle:
Here is a DEMO
.box {
position: relative;
width: 220px;
height: 220px;
float: left;
margin-right: 50px;
}
.clearcircle {
position: absolute;
top:15px;
left:15px;
width: 190px;
height:190px;
border-radius: 100%;
background-color: transparent;
border: 5px solid #c0392b;
transition: all .2s ease-in-out;
}
.clearcircle:hover {
width:220px;
height: 220px;
top: 0px;
left: 0px;
border: 5px solid #c0392b;
}
.circle {
position: absolute;
top:50%;
margin-top: -100px;
left: 50%;
margin-left:-100px;
width: 200px;
height:200px;
border-radius: 100%;
background-color: #e74c3c;
overflow: hidden;
transition: all .2s ease-in-out;
}
.circle p {
position:relative;
text-align: center;
top: 50%;
margin-top: -55px;
color: white;
transition: all .3s;
}
.circle:hover{
background-color: #e97468;
}
Don't transition the width and the height. Keep the same width and height and just transition the border of your outer circle.
For your inner circle (.circle), set a white border 12px solid #ffffff. Now it is always in the same place relative to the outer circle, and now it will not have to change size. Also the title can not jump around because it is always in the same position.
For the outer circle, when it is not hovered, make sure it has the same size and border as when it is, but make the border white, 5px solid #ffffff.
I think you can then also do away with a lot of your extra positioning.
Here is a modified jsFiddle so you can take a look, and here is the CSS modified:
.box {
position: relative;
width: 220px;
height: 220px;
float: left;
margin-right: 50px;
text-align: center;
}
.clearcircle {
width: 225px;
height:225px;
border-radius: 100%;
background-color: transparent;
border: 5px solid #ffffff;
transition: all .2s ease-in-out;
}
.clearcircle:hover {
border: 5px solid #c0392b;
}
.circle {
width: 200px;
height:200px;
border: 12px solid #ffffff;
border-radius: 100%;
background-color: #e74c3c;
overflow: hidden;
transition: all .2s ease-in-out;
}
.circle p {
position:relative;
text-align: center;
color: white;
transition: all .3s;
}
.circle:hover{
background-color: #e97468;
}
Incidentally, putting a div or a p in your a tag breaks the tag for validated XHTML. You may want to use a div instead, with an "on click" action added that causes it to behave as a link.
Debounce jitter by margin: 0 -12%; if adding padding padding: 0 12%;
menu li a:hover {
margin: 0 -12%;
padding: 0 12%;
color: #fff;
background: #ff5a5f;
display: inline-block;
}