How to change something when a button is clicked [closed] - html

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed yesterday.
Improve this question
I am was making a slider, but I can’t get it to have an animation when a person clicks a button to move to the other image. How can I fix it?
The HTML code:
<h2>client showcase</h2>
<br />
<img src="images here.jpeg" />
<br />
<img src="left.jpg" alt="previous client" />
<img src="right.jpg" alt="next client" />
The CSS code:
.slider2 .change{ border-radius: 5px; width: 300px; height: 300px; transition: opacity 1s; }
I have tried many ways, but I can’t get a proper animation. I have tried adding classes, but it does not work properly.

I solved this by adding a class to the image when a button is clicked so the image will move, change, change colours, fade, rotate and many more
CSS
.slider2 .change{
border-radius: 5px;
width: 500px;
height: 300px;
}
.small{
font-size: xx-small;
color: #a8a0a0;
}
.slider2 .change2{
border-radius: 5px;
width: 500px;
height: 300px;
}
.slider2 .change3{
border-radius: 5px;
width: 500px;
height: 300px;
}
.slider2 .change4{
border-radius: 5px;
width: 500px;
height: 300px;
}
.slider2{
position: relative;
top: 0;
left: 0;
position: relative;
width: 50%;
}
.change{
opacity: 1;
position: relative;
top: 0;
left: 0;
border: 1px solid #000000;
transition: 0.3s;
}
.change2{
position: absolute;
top: 0px;
left: 0px;
border: 1px solid #000000;
transition: opacity 0.3s;
}
.change3{
position: absolute;
top: 0px;
left: 0px;
border: 1px solid #000000;
}
.change4{
position: absolute;
top: 0px;
left: 0px;
border: 1px solid #000000;
}
.ninja{
opacity: 0;
}
.hidden{
opacity: 0;
}
.hide{
animation: move 400ms ;
}
.show{
opacity: 1;
}
.slided{
animation: slide 400ms;
}
#keyframes move{
from{opacity: 100%;}
to{opacity: 0%;}
}
#keyframes slide{
from{
transform: translateX(0px);
}
to{
transform: translateX(-500px);
}
}

Related

Why does the opacity not work when I hover over the square?

When I hover over the square, I want the text "MENU" to go and "Google" and "Youtube" to appear. I gave the opacity value for it. "MENU" text disappears but other texts are not visible. Why is Youtube and Google text not showing?
I gave visibility: visible and visibility: hidden instead of opacity but I still get the same result. Am i selecting the wrong div's?
CSS body {
background-color: aquamarine;
}
.square {
width: 100px;
height: 100px;
border-radius: 10px;
background-color: azure;
position: relative;
transition: 1s transform;
}
.square:hover {
transform: scale(4);
}
.div1::after {
position: absolute;
content: "MENU";
right: 27px;
top: 40px;
}
.square:hover div:nth-child(1) {
opacity: 0;
}
.div2::after {
content: "- Google";
position: absolute;
bottom: 25px;
right: 5px;
font-size: 10px;
border: 2px solid grey;
padding: 2px;
opacity: 0;
}
.square:hover div:nth-child(2) {
opacity: 1;
}
.div3::after {
content: "- Youtube";
position: absolute;
bottom: 2px;
right: 5px;
font-size: 10px;
border: 2px solid grey;
padding: 2px;
opacity: 0;
}
.square:hover div:nth-child(3) {
opacity: 1;
}
HTML
<div class="square">
<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>
</div>
If you have added content using after , then add after in those hover also to work the way you want.
That is use .square:hover div:nth-child(2):after instead of .square:hover div:nth-child(2) only
It works like this see below snippet :
body {
background-color: aquamarine;
}
.square {
width: 100px;
height: 100px;
border-radius: 10px;
background-color: azure;
position: relative;
transition: 1s transform;
}
.square:hover {
transform: scale(4);
}
.div1::after {
position: absolute;
content: "MENU";
right: 27px;
top: 40px;
}
.square:hover div:nth-child(1) {
opacity: 0;
}
.div2::after {
content: "- Google";
position: absolute;
bottom: 25px;
right: 5px;
font-size: 10px;
border: 2px solid grey;
padding: 2px;
opacity: 0;
}
.square:hover div:nth-child(2):after {
opacity: 1;
}
.div3::after {
content: "- Youtube";
position: absolute;
bottom: 2px;
right: 5px;
font-size: 10px;
border: 2px solid grey;
padding: 2px;
opacity: 0;
}
.square:hover div:nth-child(3):after {
opacity: 1;
}
<div class="square">
<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>
</div>
I changed your code a bit. See if this does what you need:
I added transform-origin: top left; to prevent the scaling from happening in all directions which caused some of the element to be displayed outside of the viewport.
I got rid of the :after pseudo-elements as they did not contribute to the desired outcome and only complicated things (in my opinion).
CSS body {
background-color: aquamarine;
}
.options {
height: 100px;
margin-top: 5px;
display: none;
}
.options>div {
border: 2px solid gray;
margin-bottom: 4px;
}
.square {
width: 100px;
height: 100px;
border: 1px solid gray;
border-radius: 10px;
background-color: azure;
position: relative;
transition: 1s transform;
}
.square:hover {
transform-origin: top left;
transform: scale(4);
}
.menu {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.square:hover .options {
display: block;
font-size: 10px;
padding: 2px;
}
.square:hover .menu {
display: none;
}
<div class="square">
<div class="menu">Menu</div>
<div class="options">
<div class="div2">Google</div>
<div class="div3">You Tube</div>
</div>
</div>

How could I create a transition effect similar to the "start voting" button on this website? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I would like to create a transition effect on hover that is similar to the large "start voting" button on this website but, while I am familiar with css transition effects, I dont know how to create that one in particular. Thank you for taking the time to read this.
You can use a background-size transition:
a {
position: relative;
display: inline-block;
padding: 12px 80px;
border: 2px solid #BDAA67;
color: white;
font-size: 30px;
text-decoration: none;
background-color: black;
background-image: linear-gradient(#BDAA67, #BDAA67);
background-position: 50% 50%;
background-repeat: no-repeat;
background-size: 0% 0%;
transition: background-size .3s, color .3s;
}
a:hover {
background-size: 100% 100%;
color: #000;
}
<a href="#" class="button">
CLICK ME!
</a>
{content: "";
background-color: #bdaa67;
height: 0%;
width: 50%;
position: absolute;
left: 25%;
transition: all .15s ease-in-out;
top: 48%;
z-index: -1;}
Try this
Add the following lines of code to your HTML,
<button class="custom-btn">Start now</button>
Add the following lines of code to your custom.css. This will give the exact style on hover for the button. You can minimise the code if you are willing to use bootstrap. Here we have custom styled the button from scratch.
.custom-btn {
font-size: 25px;
padding: 32px 105px;
text-shadow: none;
border: 2px solid #000;
background: #000;
color: #fff;
font-weight: bold;
text-transform: uppercase;
position: relative;
z-index: 1;
transition: all .33s ease-in-out;
}
.custom-btn:hover {
border: 2px solid #bdaa67;
color: #000;
}
.custom-btn::before {
content: "";
background-color: #bdaa67;
height: 0%;
width: 50%;
position: absolute;
left: 25%;
transition: all .15s ease-in-out;
top: 48%;
z-index: -1;
}
.custom-btn:hover::before {
height: 100%;
width: 100%;
left: 0;
top: 0;
}
<body>
<button> START VOTING </button>
</body>
body {
margin: 0;
padding: 0;
height: 100vh;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
background: red;
}
button {
position: absolute;
padding: 40px 120px;
font-weight: bold;
border: 0;
color: #fff;
font-size: 2em;
text-transform: uppercase;
background: #000;
z-index: 1;
}
button::before {
content:"";
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background: #bdaa67;
transform: scale(0);
transition: 0.3s;
z-index: -1;
}
button:hover:before {
transform: scale(1);
}
button:hover {
border: 3px solid #bdaa67;
color: #000;
}

Limit hover area of CSS shapes to :after

I am trying to make a sort of Venn-Diagram that is going to be used for navigation later.
I have three intersecting ellipsoids created with CSS shapes. Each ellipsoid, as well as their two intersections, will be distinct links later on. Also, when you hover over them they should pop out as per transform: scale(1.3).
My issue is that I'm using ellipsoids which are partially transparent with :after to create the intersections, which creates a problem when hovering over them because the :hover condition gets triggered when hovering anywhere on the partially transparent ellipsoid and not just the :after part. This means that the nonintersecting areas are not hoverable because they are obstructed by the other invisible ellipsoid.
I think the example will make this clearer.
Here is the code:
CSS:
.venn-container{position: relative; left: 0;}
.cat_one{
width: 400px;
height: 200px;
background: red;
border-radius: 200px / 100px;
position: absolute;
float: left;
opacity: 0.5;
}
.cat_two{
width: 400px;
height: 200px;
background: green;
border-radius: 200px / 100px;
position: absolute;
float: left;
left: 240px;
opacity: 0.5;
}
.cat_three{
width: 400px;
height: 200px;
background: blue;
border-radius: 200px / 100px;
position: absolute;
float: left;
left: 480px;
opacity: 0.5;
}
.int1{
background: transparent;
width: 400px;
height: 200px;
border-radius: 200px / 100px;
position: relative;
opacity: 0.5;
overflow: hidden;
float: left;
}
.int1:after{
background: black;
position: absolute;
content: '';
border-radius: 200px / 100px;
width: 400px;
height: 200px;
left: 240px;
}
.int1:hover{
transform: scale(1.3);
left: -35px;
}
.int2{
background: transparent;
width: 400px;
height: 200px;
border-radius: 200px / 100px;
position: relative;
opacity: 0.5;
overflow: hidden;
float: left;
left: 80px;
}
.int2:after{
background: black;
position: absolute;
content: '';
border-radius: 200px / 100px;
width: 400px;
height: 200px;
left: -240px;
}
.int2:hover{
transform: scale(1.3);
left: 115px;
}
HTML:
<div class="venn-container">
<div class="cat_one"></div>
<div class="cat_two"></div>
<div class="cat_three"></div>
<div class="int1"></div>
<div class="int2"></div>
</div>
And here is a fiddle: https://jsfiddle.net/y3Lvmuqg/2/
I would like the :hover to only get triggered in the intersections, and later make cat_one and cat_two hoverable outside the intersections.
I don't know if there is a way I'm doing this is the best and I'm open to suggestions.
Thanks for getting back to me #ge0rg I spent about an hour fiddling with CSS and HTML and came up with this code using just divs with background colors, hover events and border radius's (along with a few z-index and positioning techniques).
Hope you enjoy your reworked venn diagram...
You may have to mess around with the size, and definetly will have to mess with the positioning (however they're all inside a div and so it makes it so that you can just position the div and the rest will happen magically) I added a background color to the div just to show that nothing was transparent, and I also added a always on top function for viewing a section, and I hope you enjoy!
.Venn {
background: linear-gradient(to bottom right, blue, lightblue);
}
.d1:hover, .d2:hover, .d3:hover {
color: #565656;
animation: top 2s steps(2, end) forwards;
-webkit-animation: top 2s steps(2, end) forwards;
box-shadow: 0px 0px 20px white;
}
.d1, .d2, .d3 {
overflow-wrap: break-word;
}
.d1 center, .d3 center {
position: absolute;
top: 50%;
left: 50%;
transform: translateY(-50%) translateX(-50%);
}
.d1 {
padding: 10px;
width: 100px;
height: inherit;
z-index: 1;
position: absolute;
border-radius: 100%;
top: 0px;
}
.d3 {
padding: 10px;
width: 100px;
height: inherit;
z-index: 2;
position: absolute;
border-radius: 100%;
top: 0px;
left: 81px;
}
.d1:hover, .d3:hover {
transform: scale(1.05);
}
.d2 {
border-radius: 100% 0;
height: 90px;
width: 87.5px;
transform: rotate(-45deg) scale(.7);
position: absolute;
top: 15px;
left: 55.35px;
z-index: 3;
border: 1px solid black;
}
.d2b {
transform: rotate(45deg);
padding: 0;
margin: 0;
}
.d2b center {
position: relative;
left: 20px;
}
.d2:hover {
transform: rotate(-45deg);
}
.Venn {
height: 100px;
}
-webkit #keyframes top {
99% {
z-index: previous;
background-image: none;
}
100% {
z-index: 7;
}
}
#keyframes top {
99% {
z-index: previous;
background-image: none;
}
100% {
z-index: 7;
}
}
<div class="Venn" style="position: relative; left: 50px; width: 300px; height: 100px;">
<div class="d1" style=" background-color: grey;">
<center> 1 </center>
</div>
<div class="d2" style=" background-color: #AAAAAA;">
<div class="d2b" style="max-width: inherit;">
<center> 2 </center>
</div>
</div>
<div class="d3" style=" background-color: lightgrey;">
<center> 3 </center>
</div>
</div>
For those of you who would prefer a JSfiddle/ CodePen here you go a Codepen.

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>

How to make an expanding circle with button [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm trying to make first circle can expanding as big as the second circle in the background with button, do anyone know how ?
Well one way to do it would be to use java script to add and remove classes which hold the properties of your circle.
You could create a css class that holds one set of properties that is then called by javascript when a button is clicked.
.circle_b {
height: 200px;
width: 200px;
border-radius: 50%;
background: #ddd;
position: relative;
}
.circle_s {
height: 80px;
width: 80px;
border-radius: 50%;
background: #ddd;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
border: 0;
background: coral;
cursor: pointer;
transition: all 0.2s ease;
}
.sizePlus{
height: 200px;
width: 200px;
transition: all 0.2s ease;
}
button{
display: block;
position: absolute;
width: 200px;
height: 100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<script type="text/javascript">
$(document).click(function (e) {
$el = $(e.target);
if ($el.hasClass('clickme')) {
$(".circle_s").toggleClass('sizePlus');
} else {
$(".circle_s").removeClass('sizePlus');
}
});
</script>
<div class="circle_b">
<button class="circle_s clickme">
CLICK ME
</button>
</div>
</body>
DEMO
Animation is on hover of button
HTML
<div class="circle_b">
<button class="circle_s">
HOVER ME!
</button>
</div>
CSS
.circle_b {
height: 200px;
width: 200px;
border-radius: 50%;
background: #ddd;
position: relative;
}
.circle_s {
height: 80px;
width: 80px;
border-radius: 50%;
background: #ddd;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
border: 0;
background: coral;
cursor: pointer;
transition: all 0.2s ease;
}
.circle_s:hover {
height: 200px;
width: 200px;
transition: all 0.2s ease;
}