How to fade in changes to elements in CSS - html

I am trying to fade in edits to elements in CSS when an element is hovered over. Specifically changing a border from solid to dotted, by fading in the change, how do I do that?
EDIT:
Perhaps I need to be more specific about context here is my current code:
li {
font-family: 'Roboto', sans-serif;
font-size: 20px;
color: black;
border-bottom: 1px solid black;
}
li:hover {
border-bottom: 1px dotted black;
opacity: 1;
transition: opacity 1s ease-in-out;
}

Here is some CSS trickery that gives that effect. The downside being the inside cannot be transparent.
div {
position: relative;
width: 50px;
height: 50px;
display: block;
border: 3px dotted red;
background: red;
transition: 1s ease-in-out all;
}
div:after {
position: absolute;
content: ' ';
top: 0;
bottom: 0;
left: 0;
right: 0;
background: white;
}
div:hover {
background: transparent;
}
<div></div>

You could place 2 divs on top of each other with different stroke types then transition them out.
* {
box-sizing: border-box;
}
html,
body {
height: 100%;
margin: 0;
}
body {
display: flex;
}
div {
width: 11rem;
height: 11rem;
margin: auto;
background-color: #f2f2f2;
border: 5px #bbb solid;
border-radius: 2rem;
opacity: 1;
cursor: pointer;
}
.dotted {
border: 5px #bbb dotted;
position: absolute;
top: 50%;
left: 50%;
transform: translate( -50%, -50% );
z-index: 0;
}
.solid {
position: relative;
z-index: 1;
transition: opacity 1s;
}
.solid:hover {
opacity: 0;
}
<div class="solid"></div>
<div class="dotted"></div>

You can achieve this using pseudoelements. This version works even with transparent background. Added gradient to body to show this.
div {
position: relative;
/* just styles for demo */
width: 250px;
height: 250px;
border-width: 5px;
border-style: solid;
transition: 1s ease-in-out all;
border-radius: 10px;
}
div:after {
position: absolute;
content: ' ';
top: -5px;
bottom: -5px;
left: -5px;
right: -5px;
border-width: inherit;
border-style: dotted;
border-radius: inherit;
}
div, div:after {
border-color: tomato;
}
div:hover {
border-color: transparent;
}
/* just styles for demo showing that this will work even for transparent background */
body {
background-image: linear-gradient(to bottom, transparent, #ddd);
min-height: 100vh;
margin: 0;
}
<div></div>

It's not a soo elegant solution but it goes off of 'Niet the Dark Absol's' comment on my original question. Here is the code:
li {
font-family: 'Roboto', sans-serif;
font-size: 20px;
color: black;
position: relative;
border-bottom: 1px solid transparent; /* invisible border */
}
li:before, li:after {
content: '';
position: absolute;
left: 0; right: 0;
top: 0; bottom: 0;
margin: -1px; /* same as border width */
transition: opacity 1s linear;
}
li:before {
border-bottom: 1px solid #000;
}
li:after {
border-bottom: 1px dotted #000;
opacity: 0;
}
li:hover:before {
opacity: 0;
}
li:hover:after {
opacity: 1;
}

Related

How to replace <b> </b> tags with a circle

I was told they should not be in there, but how do I remove them?
https://jsfiddle.net/jqzs6d3o/
That is all I am doing in the code.
Removing the <b> </b> tags from the html it.
How would that be done?
Is this something hard to do?
Removing <b></b> removes the blue circle. I want to keep the circle and remove <b></b>
<button class="exitnew" type="button" aria-label="Close"><b></b></button>
.exitnew {
-webkit-appearance: none;
appearance: none;
position: relative;
box-sizing: border-box;
margin: auto;
padding: 0;
width: 48px;
height: 48px;
cursor: pointer;
background: transparent;
border: none;
border-radius: 50%;
clip-path: circle(50%);
transition: all 1s ease;
overflow: hidden;
}
.exitnew::before,
.exitnew::after {
content: "";
position: absolute;
height: 5px;
width: 38px;
top: 22px;
left: 5px;
right: 5px;
background: red;
transform: rotate(45deg);
transition: all 1s ease;
}
.exitnew::after {
transform: rotate(-45deg);
}
.exitnew:hover {
background: transparent;
}
.exitnew:hover::before,
.exitnew:hover::after {
background: green;
}
.exitnew b {
box-sizing: border-box;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
border: 5px solid blue;
border-radius: 50%;
}
<button class="exitnew" type="button" aria-label="Close"><b></b></button>
Added some styles #circle ID and changed your positioning a bit of .exitnew Also made b display: none; Check the changes below.
.exitnew {
-webkit-appearance: none;
appearance: none;
position: relative;
box-sizing: border-box;
margin: auto;
padding: 0;
width: 48px;
height: 48px;
cursor: pointer;
background: transparent;
border: none;
border-radius: 50%;
clip-path: circle(50%);
transition: all 1s ease;
overflow: hidden;
}
.exitnew::before,
.exitnew::after {
content: "";
position: absolute;
height: 5px;
width: 38px;
top: 17px;
left: -1px;
right: 5px;
background: red;
transform: rotate(45deg);
transition: all 1s ease;
}
.exitnew::after {
transform: rotate(-45deg);
}
.exitnew:hover {
background: transparent;
}
.exitnew:hover::before,
.exitnew:hover::after {
background: green;
}
.exitnew b {
display: none;
box-sizing: border-box;
position: relative;
width: 100%;
height: 100%;
border: 5px solid blue;
border-radius: 50%;
}
#circle {
background-color:#fff;
border-width: 2rem;
border:4px solid darkblue;
height:45px;
border-radius:50%;
-moz-border-radius:50%;
-webkit-border-radius:50%;
width: 45px;
margin-left: 1rem;
position: absolute;
}
<button class="exitnew" id="circle" type="button" aria-label="Close"><b></b></button>
You can utilize the button itself as the circle.
With this you’ll have cleaner code where you can just completely remove b tag without losing the circle.
.exitnew {
box-sizing: border-box;
position: absolute;
left: 0;
top: 0;
width: 38px;
height: 40px;
border: 5px solid blue;
border-radius: 50%;
}
Here’s the changes I made.
https://jsfiddle.net/Lnbuxvc0/

CSS hover effect doesn't work over picture

I'm trying to get the border on my button to appear, it works perfectly with solid background colors but not with a image . You can see the border when clicking on the button but not when mouse over it.
I just want the border to be visible.
<html lang="en"> <head>
<style>
#import url(https://fonts.googleapis.com/css?family=Montserrat);
*, *::after, *::before {
box-sizing: border-box;
}
body {
{ background-image: url("https://cdn.pixabay.com/photo/2016/09/05/15/07/concrete-1646788_960_720.jpg") }
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
height: 100vh;
width: 100vw;
text-align: center;
}
button {
font-family: "Montserrat", sans-serif;
text-transform: uppercase;
}
button {
position: relative;
border: none;
font-size: 18px;
transition: color 0.5s, transform 0.2s, background-color 0.2s;
outline: none;
border-radius: 3px;
margin: 0 10px;
padding: 23px 33px;
border: 3px solid transparent;
}
button:active {
transform: translateY(3px);
}
button::after, button::before {
border-radius: 3px;
}
.shrink-border {
background-color: transparent;
color: #1b1b20;
}
.shrink-border:hover {
background-color: transparent;
box-shadow: none;
color: #E3BD1C;
}
.shrink-border::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: 3px solid #1b1b20;
transition: opacity 0.3s, border 0.3s;
}
.shrink-border:hover::before {
opacity: 0;
}
.shrink-border::after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: transparent;
border: 3px solid #E3BD1C;
opacity: 0;
z-index: -1;
transform: scaleX(1.1) scaleY(1.3);
transition: transform 0.3s, opacity 0.3s;
}
.shrink-border:hover::after {
opacity: 1;
transform: scaleX(1) scaleY(1);
}
.material-bubble {
background-color: transparent;
color: #EEC02C;
border: 3px solid #EEC02C;
overflow: hidden;
box-shadow: none;
}
.material-bubble:hover {
color: #EEC02C;
}
.material-bubble::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: 3px solid #EEC02C;
transition: opacity 0.3s, border 0.3s;
}
.material-bubble:hover::before {
opacity: 0;
}
.material-bubble::after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 200px;
height: 200px;
background-color: #EEC02C;
border-color: #EEC02C;
border-radius: 50%;
transform: translate(-10px, -70px) scale(0.1);
opacity: 0;
z-index: -1;
transition: transform 0.3s, opacity 0.3s, background-color 0.3s;
}
.material-bubble:hover::after {
opacity: 1;
transform-origin: 100px 100px;
transform: scale(1) translate(-10px, -70px);
}
</style>
</head>
<body translate="no">
<div class="container">
<div>
<div style="background-image: url('https://cdn.pixabay.com/photo/2016/09/05/15/07/concrete-1646788_960_720.jpg');">
<a href="https://sites.google.com/u/0/d/1qexyDxBEpBgUx3IVqODoqfLs59AG0eV1/p/1SsjI8NaKooq171w4dA5LW0NvxKX9ACkG/preview?authuser=0">
<button class="shrink-border">Make an Appointment</button>
</a>
</a>
</div>
</div>
</body></html>
Just add a z-index to your border:
.shrink-border {
background-color: transparent;
color: #1b1b20;
z-index: 0; /* <--- Add this */
}
Full working Demo:
<html lang="en"> <head>
<style>
#import url(https://fonts.googleapis.com/css?family=Montserrat);
*, *::after, *::before {
box-sizing: border-box;
}
body {
{ background-image: url("https://cdn.pixabay.com/photo/2016/09/05/15/07/concrete-1646788_960_720.jpg") }
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
height: 100vh;
width: 100vw;
text-align: center;
}
button {
font-family: "Montserrat", sans-serif;
text-transform: uppercase;
}
button {
position: relative;
border: none;
font-size: 18px;
transition: color 0.5s, transform 0.2s, background-color 0.2s;
outline: none;
border-radius: 3px;
margin: 0 10px;
padding: 23px 33px;
border: 3px solid transparent;
}
button:active {
transform: translateY(3px);
}
button::after, button::before {
border-radius: 3px;
}
.shrink-border {
background-color: transparent;
color: #1b1b20;
z-index: 0; /* <--- Add this */
}
.shrink-border:hover {
background-color: transparent;
box-shadow: none;
color: #E3BD1C;
}
.shrink-border::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: 3px solid #1b1b20;
transition: opacity 0.3s, border 0.3s;
}
.shrink-border:hover::before {
opacity: 0;
}
.shrink-border::after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: transparent;
border: 3px solid #E3BD1C;
opacity: 0;
z-index: -1;
transform: scaleX(1.1) scaleY(1.3);
transition: transform 0.3s, opacity 0.3s;
}
.shrink-border:hover::after {
opacity: 1;
transform: scaleX(1) scaleY(1);
}
.material-bubble {
background-color: transparent;
color: #EEC02C;
border: 3px solid #EEC02C;
overflow: hidden;
box-shadow: none;
}
.material-bubble:hover {
color: #EEC02C;
z-index: -1;
}
.material-bubble::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: 3px solid #EEC02C;
transition: opacity 0.3s, border 0.3s;
}
.material-bubble:hover::before {
opacity: 0;
}
.material-bubble::after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 200px;
height: 200px;
background-color: #EEC02C;
border-color: #EEC02C;
border-radius: 50%;
transform: translate(-10px, -70px) scale(0.1);
opacity: 0;
z-index: -1;
transition: transform 0.3s, opacity 0.3s, background-color 0.3s;
}
.material-bubble:hover::after {
opacity: 1;
transform-origin: 100px 100px;
transform: scale(1) translate(-10px, -70px);
}
</style>
</head>
<body translate="no">
<div class="container">
<div>
<div style="background-image: url('https://cdn.pixabay.com/photo/2016/09/05/15/07/concrete-1646788_960_720.jpg');">
<a href="https://sites.google.com/u/0/d/1qexyDxBEpBgUx3IVqODoqfLs59AG0eV1/p/1SsjI8NaKooq171w4dA5LW0NvxKX9ACkG/preview?authuser=0">
<button class="shrink-border">Make an Appointment</button>
</a>
</a>
</div>
</div>
</body></html>
Add this to your css
.shrink-border:hover {
transform: translateY(3px);
}

Div border in curve shape

I'm trying to achieve div border in the convex shape and on hover it should be in normal square shape. I have added in the bottom as same I want to add on the top I tried using before but unable to achieve the result. Can anyone help me Below is my code so far I have done.
Any help will be appreciated
* {
box-sizing: border-box;
}
.services {
position: relative;
width: 500px;
height: 420px;
margin: 100px;
background-color: #cccccc;
transition: all 0.2s ease;
animation: down-bump 0.4s ease;
}
.services:before {
}
.serv_section {
top: 83%;
position: relative;
overflow: hidden;
padding: 50px 0 0;
}
.serv_inner {
position: relative;
background: #fff;
height: 25px;
}
.serv_inner:after {
box-shadow: 0 0 0 80px #fff;
border-radius: 100%;
position: absolute;
height: 150px;
content: '';
right: -20%;
left: -20%;
top: -150px;
transition: all 0.4s ease-in-out;
}
.services:hover .serv_inner:after {
top: -120px;
}
.serv_inner:before {
/* box-shadow: 0 0 0 80px #fff;
border-radius: 100%;
position: absolute;
height: 150px;
content: '';
right: -20%;
left: -20%;
top: 130px;
transition: all 0.4s ease-in-out; */
}
span.image_caption {
position: absolute;
color: red;
padding: 10px 20px;
font-size: 30px;
z-index: 10;
animation-duration: 2.5s;
animation-fill-mode: both;
}
span.image_caption p {
font-size: 32px;
font-weight: 900;
font-family: 'Dancing Script', cursive;
color: cadetblue;
}
<div class='services'>
<div class="serv_section">
<div class="serv_inner">
</div>
</div>
</div>
You can use the before and after elements to make the curve, on hover hide the psuedo elements behind the element and remove the curve like this:
.services {
position: relative;
width: 100px;
height: 60px;
margin: 100px;
background-color: #cccccc;
z-index: 0;
}
.services:hover:before{
top: 0px;
border-radius: 0;
}
.services:hover:after{
bottom: 0px;
border-radius: 0;
}
.services:before, .services:after{
content: ' ';
position: absolute;
width: 100%;
height: 40px;
background-color: #cccccc;
border-radius: 50%;
z-index: -1;
transition: all .4s;
}
.services:before {
top: -20px;
}
.services:after {
bottom: -20px;
}
<div class='services'>
</div>
If I understand it right you can achieve this by simple using of different values for horizontal and vertical dimensions of the border-radius property (more info at https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius):
div {
background: grey;
height: 100px;
width: 200px;
transition: border-radius .15s ease-out;
}
/* border-radius on default state */
div {
border: 4px solid black;
border-radius: 50%/20px;
}
div:hover {
border-radius: 0;
}
<div></div>

CSS border opacity affected by translucent overlay [duplicate]

This question already has answers here:
How do I reduce the opacity of an element's background using CSS?
(29 answers)
Closed 5 years ago.
I have this project:
https://jsfiddle.net/3xw9aqew/
When a user hovers over the grey box, a red overlay appears with a green border/outline. However this border is applied to the overlay which has an opacity value applied to it on hover.
.image-container:hover .overlay {
opacity: 0.3;
}
I want the overlay to be translucent, allowing the image below to be seen, but I want the border around this to be solid so its a standard "green" colour. This is the CSS for the overlay:
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: red;
border:10px solid green;
box-sizing:border-box;
}
How can i achieve this?
For the intended behaviour, apply the required transparency directly to the background-color property value instead of the containing element as a whole. This can be done by adjusting the rgba value as demonstrated in the embedded code snippet below.
opacity applies to the element as a whole, including its contents,
even though the value is not inherited by child elements. Thus, the
element and its children all have the same opacity relative to the
element's background, even if they have different opacities relative
to one another.
opacity - CSS | MDN
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 1;
transition: .5s ease;
background-color: transparent;
border: 10px solid transparent;
box-sizing: border-box;
}
.image-container:hover .overlay {
background-color: rgba(255, 0, 0, 0.3);
border: 10px solid green;
}
Updated JSFiddle
Code Snippet Demonstration:
var imgContainer = document.getElementById("imgContainer");
var lorem = document.querySelector(".hdr-left");
var ipsum = document.querySelector(".hdr-right");
//When clicking on imgContainer toggle between class to change colour and position
imgContainer.addEventListener('click', function() {
lorem.classList.toggle("hdr-color-white");
ipsum.classList.toggle("hdr-color-white");
lorem.classList.toggle('hdr-left-middle');
ipsum.classList.toggle('hdr-right-middle');
});
body {
max-width: 100%;
overflow-x: hidden;
background: yellow;
font-family: sans-serif;
}
.container {
width: 85%;
max-width: 700px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
img {
width: 100%;
max-width: 920px;
}
p {
font-size: 18px;
color: blue;
font-weight: bold
}
p.left {
position: absolute;
top: 0;
bottom: 0px;
right: -32%;
transform: rotate(-90deg);
}
p.right {
position: absolute;
top: 0;
bottom: 0;
left: -32%;
transform: rotate(90deg);
}
h2 {
font-size: 5em;
position: absolute;
text-transform: uppercase;
letter-spacing: 2px;
font-weight: bold;
margin: 0;
z-index: 5;
color: blue;
transition: all 0.5s ease-in-out;
}
.hdr-color-white {
color: white;
}
.hdr-left {
left: -12%;
top: -35%;
}
.hdr-left-middle {
left: 7%;
top: 40%;
}
.hdr-right {
right: -10%;
top: 110%;
}
.hdr-right-middle {
right: 7%;
top: 40%;
}
/*Hovers*/
.container:hover {
cursor: pointer
}
.container:hover>p {
color: red;
}
.container .image-container:hover {}
/*Hovers Ends*/
/*Overlay*/
.image-container {
position: relative;
width: 100%;
padding: 10px;
box-sizing: border-box;
}
.image {
display: block;
width: 100%;
height: auto;
outline: 5px solid blue;
}
.container .image-container:hover>.image {
outline: none;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 1;
transition: .5s ease;
background-color: transparent;
border: 10px solid transparent;
box-sizing: border-box;
}
.image-container:hover .overlay {
background-color: rgba(255, 0, 0, 0.3);
border: 10px solid green;
}
/*Overlay Ends*/
<div class="container">
<!--Rotated Text-->
<p class="right">Harolds</p>
<p class="left">Harolds</p>
<!--//Rotated Text-->
<h2 class="hdr-left hdr-color" id="lorem">Lorem</h2>
<div class="image-container" id="imgContainer">
<img src="http://via.placeholder.com/980x550" alt="gucci" class="image">
<!--colour overlay-->
<div class="overlay"></div>
<!--//colour overlay-->
</div>
<h2 class="hdr-right hdr-color" id="ipsum">Ipsum</h2>
</div>

Input design validation issue in CSS

I want to reproduce that validation.
This is what I achieved yet:
I am missing that triangle from the bottom. I want to use css/css3 to solve this. This is what I tried, but without succes:
.contact-form .parsley-errors-list .parsley-required:after{
padding: 8px;
background-color:red
margin-top: 1px;
transition: none 0s ease 0s;
position: absolute;
content: "";
left: -6px;
transform: rotate(45deg);
}
Can you guide me How do I achieve that triangle with css/css3 ? thx
Use this and see if it helps
.contact-form .parsley-errors-list .parsley-required{
position: relative;
}
.contact-form .parsley-errors-list .parsley-required:after{
content: '';
position: absolute;
top: 100%;
left: 10px;
border-left: 10px solid red;
border-bottom: 10px solid transparent;
transition: none 0s ease 0s;
}
.arrow_box {
position: relative;
background: #FF0000;
}
.arrow_box:after {
top: 100%;
left: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-color: rgba(255, 0, 0, 0);
border-top-color: #FF0000;
border-width: 15px;
margin-left: -15px;
}
For a "straight" arrow.
width: 0;
height: 0;
border-style: solid;
border-width: 20px 20px 0 0;
border-color: #ff0000 transparent transparent transparent;
This lets you create it using borders.