I'm trying to do a circle that expands-change color from the center, and i want it to expand it with border-radius: 50%, you'll understand what i'm talking about if you watch the example i made
Checkout the sample i made for better understanding
Thanks for any help
You could run a transition over an inset box-shadow, like so
div {
width: 300px;
height: 300px;
display: flex;
color: #FFF;
justify-content: center;
align-items: center;
border-radius: 50%;
background: #03BF60;
cursor: pointer;
transition: box-shadow .75s 0s, color .5s 0s;
box-shadow: inset 0 0 0 0 #DCEDC8;
}
div p {
color: inherit;
text-align: center;
}
div:hover {
color: #444;
box-shadow: inset 0 0 0 150px #DCEDC8;
}
<div>
<p>
Responsive design. I get this certificate by
learning HTML, CSS, web design, media query plus
animations using keyframes, declaring variables
on css and a lot of CSS components.
</p>
</div>
You could to use Keyframes...
<div class="shape">
<div class="to-animate animate"></div>
</div>
.shape {
border-radius: 50%;
width: 200px;
height: 200px;
background: red;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
}
.to-animate {
width: 0;
height: 0;
background: blue;
}
.animate {
animation: my-animation 1s forwards;
}
#keyframes my-animation {
to {
width:200px;
height: 200px;
}
}
https://jsfiddle.net/hernangiraldo89/ba3ne675/
Keyframes are a powerful tool, here its documentation:
https://developer.mozilla.org/en-US/docs/Web/CSS/#keyframes
Related
How can I change the background color of a div tag permanently once it is clicked.
Tried the following code :
div {
min-height: 50px;
background-color: yellow;
border-radius: 4px 4px 0 0;
padding: 10px;
display: flex;
align-items: center;
&:active {
background-color: red;
}
}
But with this the background color is restored to previous one after the click is released.
Is there a way to do this with SCSS and html alone?
<div class="div">
<p>Hello</p>
</div>
If you want pure CSS/SCSS approach, you can do it using transition delay.
First of all you set transition of 0s, and a delay of some higher value (like 100000s). Now when you active the element, change the transition to 0s without delay so that it changes it's color immediately, now since there is a huge delay it becomes almost permanent. (but after the delay time that you set is over, it would become back to it's initial state)
div {
min-height: 50px;
background-color: yellow;
border-radius: 4px 4px 0 0;
padding: 10px;
display: flex;
align-items: center;
transition: background-color 0s 100000s;
&:active {
background-color: red;
transition: background-color 0s;
}
}
div {
min-height: 50px;
background-color: yellow;
border-radius: 4px 4px 0 0;
padding: 10px;
display: flex;
align-items: center;
transition: background-color 0s 100000s;
}
div:active {
background-color: red;
transition: background-color 0s;
}
<div></div>
HTML
<div class="div" id="myDiv">
<p>Hello</p>
</div>
CSS
div {
min-height: 50px;
background-color: yellow;
border-radius: 4px 4px 0 0;
padding: 10px;
display: flex;
align-items: center;
}
JS
let myDiv=document.getElementById("myDiv");
myDiv.addEventListener('click',()=>{
myDiv.style.background='red';
})
Image hover overlay is working on all other platforms that I have tested (desktop, android, etc.) but it doesn't seem to work on iPhone. Can anyone point me in the right direction, please? I'm not sure if it is to do with the z-index or whether it might need web-kits?
When you hover or click on .service it should show the overlay text. Please see below the code:
.service {
position: relative;
width: 80%;
height: 200px;
margin: 60px 10%;
box-shadow: rgba(0, 0, 0, 0.3) 0px 19px 38px, rgba(0, 0, 0, 0.22) 0px 15px 12px;
transition: all 0.3s;
}
.main-img-title {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
font-size: 2.5em;
font-weight: 700;
color: #f8f9fa;
opacity: 1;
transition: 0.5s;
}
.img-title {
background-color: rgba(0, 0, 0, 0.7);
padding: 2px 10px;
font-size: 1.1em;
}
.img-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
padding: 0 1%;
background: rgba(0, 0, 0, 0.7);
color: #f8f9fa;
display: flex;
flex-direction: wrap;
justify-content: center;
align-items: flex-end;
text-align: center;
opacity: 0;
}
.service:hover .main-img-title .img-title {
animation-name: title-slide-up;
animation-duration: 0.3s;
animation-fill-mode: forwards;
z-index: 50;
background-color: rgba(0, 0, 0, 0);
}
.service:hover .img-overlay {
opacity: 1;
}
#service-event:hover .main-img-title .img-title {
animation-name: title-slide-up-low;
animation-duration: 0.3s;
animation-fill-mode: forwards;
}
.overlay-img-description {
font-size: 18px;
height: 70%;
display: flex;
justify-content: center;
align-items: center;
margin: 0;
padding: 0 1%;
width: 100%;
max-height: 200px;
}
.overlay-img-description ul {
padding: 0;
}
.overlay-img-description li {
display: inline-block;
font-size: 20px;
}
.overlay-img-description li+li::before {
content: "";
display: inline-block;
vertical-align: middle;
margin: 0 13px;
width: 10px;
height: 10px;
border-radius: 50%;
background-color: currentColor;
}
.overlay-img-description p {
margin: 10px 0 0 0;
font-size: 0.9em;
}
#keyframes title-slide-up-low {
from {
transform: translateY(0)
}
to {
transform: translateY(-45px)
}
}
<div id="service-event" class="service">
<img class="bg-img" src="Images/Steel .JPG" alt="Steel" id="steel">
<div class="main-img-title">
<div class="img-title" id="steel-title">STEEL</div>
</div>
<div class="img-overlay">
<p class="overlay-img-description" id="steel-desc">Our steel crews are experienced with the construction of system scaffolding, black steel tower and truss structures. We specialise in supplying steel climbing teams with the support of steelhand ground labourers as well as plant operators who are
familiar with the requirements of truss and steel assembly.</p>
</div>
</div>
add z-index for img-title and img-overlay, define higher value for img-overlay that will fixed your issue.
The pseudo-class :hover is not supported on mobile devices.
See this question for an alternative to :hover
If you use :active selector in combination with :hover you can achieve this according to w3schools as long as the :active selector is called after the :hover selector.
.info-slide:hover, .info-slide:active{
height:300px;
}
EDIT:
Because :active doesn't work in safari, an alternative is adding an onclick="function()" to the uppermost element. function() should create the desired changes on the webpage. The downside to this solution is the mobile user has to click the element again to close it, instead of it automatically closing.
i need to animate the border bottom of the div using keyframe animation without using :before or :after or modifying the current html structure
div{
padding:3px 6px;
display:inline-block;
position:relative;
border-bottom: 2px solid black;
}
<div><h1>Lorem Ipsum</h1></div>
You can simulate it like below. Hope that helps.
.container {
padding: 3px 6px;
display: inline-flex;
flex-direction: column;
}
.underline {
height: 2px;
max-width: 0%;
background-color: black;
animation: drawBorder 2s ease forwards;
}
#keyframes drawBorder {
from {
max-width: 0%;
}
to {
max-width: 100%;
}
}
<div class="container">
<h1>Lorem Ipsum</h1>
<div class="underline"></div>
</div>
Use gradient:
div.box {
padding: 3px 6px;
display: inline-block;
position: relative;
background: linear-gradient(#000, #000) bottom/0% 2px no-repeat;
transition:1s all;
}
div.box:hover {
background-size: 100% 2px;
}
<div class="box">
<h1>Lorem Ipsum</h1>
</div>
I could really use some help in my css code.
I'm trying to make my <h1> change color and shape using the transition property.
I want the shape and color to change slowly while I hover over the headline,
but currently only the color is affected, and the shape changes independently.
my code is as follows :
html :
<h1 class="box">Abcdefg</h1>
css :
.box {
background: #2db34a;
margin: 1px auto;
transition: background 1s linear;
border-radius: 0.3%;
color: white;
cursor: pointer;
height: 95px;
line-height: 95px;
text-align: center;
width: 400px;
}
.box:hover {
background: #ff7b29;
border-radius: 50%;
}
thanks.
You just need to add border-radius to your transition
.box {
background: #2db34a;
margin: 1px auto;
transition: background 1s linear, border-radius 1s linear;
border-radius: 0.3%;
color: white;
cursor: pointer;
height: 95px;
line-height: 95px;
text-align: center;
width: 400px;
}
.box:hover {
background: #ff7b29;
border-radius: 50%;
}
<h1 class="box">Abcdefg</h1>
You have the next line of code:
transition: background 1s linear;
The transition only works on the background right now. If you change background to all the transition will work on both background and border-radius, like this:
transition: all 1s linear;
Use all in the transition setting to affect both the border-radius and the background-color:
.box {
background: #2db34a;
margin: 1px auto;
transition: all 1s linear;
border-radius: 0.3%;
color: white;
cursor: pointer;
height: 95px;
line-height: 95px;
text-align: center;
width: 400px;
}
.box:hover {
background: #ff7b29;
border-radius: 50%;
}
<h1 class="box">Abcdefg</h1>
Transitions work only on properties that have numbers. That being said, the question is it should work for the border-radius as well. But the problem here is the browser is unable to find the initial state of the property. Just add border-radius: 0% and it should work.
HTML code:
<p> the code is :</p>
<h1 class="sheet">Abcdefg</h1>
CSS Code:
css code :
.sheet {
background: blue;
margin: 1px auto;
transition: background 5s linear , border-radius 5s ease-in-out ;
color: white;
cursor: pointer;
height: 95px;
line-height: 95px;
text-align: center;
width: 400px;
}
.sheet:hover {
background: red;
color:grey;
border-radius: 40%;
}
I've been coding a very simple "Traffic Light" program and have run into a problem where it doesn't run after the first #keyframes section completes correctly. From my own research online I'm guessing that I would need a transition(?) so that when the first #keyframes is complete, the next one would be run. However my inexperience with this I'm not sure if its whats required here. Essentially is there a "trigger" I'm missing or is it just something obvious I've left out?
Please excuse the rough code. Its does work as I described above
body {
background-color: #4d4d00
}
.container {
display: flex;
justify-content: center;
align-items: center;
}
#red {
position: absolute;
left: 50px;
text-align: center;
padding: 30px;
background-color: #e60000;
margin: 10px auto;
width: 50px;
height: 50px;
border-radius: 200px;
animation: red 4s 1s 3 linear;
}
#amber {
position: absolute;
left: 1px;
text-align: center;
padding: 30px;
background-color: #ff3300;
margin: 10px auto;
width: 50px;
height: 50px;
border-radius: 200px;
animation: amber 4s 1s 3 linear;
}
#green {
position: absolute;
left: 1px;
text-align: center;
padding: 30px;
background-color: #009933;
margin: 10px auto;
width: 50px;
height: 50px;
border-radius: 200px;
animation: green 4s 1s 3 linear;
}
#keyframes red {
from {
background-color: #e60000;
}
to {
background-color: #000000;
}
#keyframes amber {
from {
background-color: #ff3300;
}
to {
background-color: #000000;
}
#keyframes green {
from {
background-color: #009933;
}
to {
background-color: #000000;
}
}
<div class="container">
<div class="row">
<div id="red">
<br>
<br>
<div id="amber">
<br>
<br>
</div>
</div>
</div>
</div>
you may use animation-delay.
here is a short/minimal code example.
.red {
background: red;
}
.orange {
background: orange
}
.green {
background: lime;
}
/* layout */
div {
display: flex;
height: 150px;
width: 50px;
flex-direction: column;
border-radius: 1em;
background: #555;
margin: 1em;
}
b {
flex: 1;
margin: 5px;
border-radius: 50%;
animation: fade 9s steps(2, end) infinite;
box-shadow: 0 0 5px white
}
/* animation */
#keyframes fade {
66%,
100% {
background: gray;
box-shadow: 0 0
}
}
.red {
animation-delay: -12s
}
.orange {
animation-delay: -6s;
}
<div class=trafficLights>
<b class=red></b>
<b class=orange></b>
<b class=green></b>
</div>
here is a codepen to play with : https://codepen.io/gc-nomade/pen/YVWeQq
You have two way to do this
1) is use animation-delay and set an higher delay to elements you would like to animate after.
animation-delay: 1s;
-webkit-animation-delay:1s;
2) trigger an element.addClass("animatedClass"); with the end of a css animation using animationonend jquery function.
$(".animatedElement").one('webkitAnimationEnd oanimationend msAnimationEnd animationend', function(event) {
$(".animatedElement").addClass("newAnimatedClass");
});