I am quite new to html and css, and have started using transitions. I watched Kevin Powell's video on it, and all his demonstrations had the transition applied when transitioning out (for instance when he stopped hovering on the element). However in my example, the transition works when the logo moves to the left, but instantly teleports back. Why is this, and what have I done wrong?
body {
background: #121212;
color: #FFFFFF;
font-family: Helvetica, Arial, sans-serif;
}
nav {
background: #212121;
width: 100%;
height: 80px;
position: absolute;
top: 0;
left: 0;
}
nav:hover .logobg {
left: 0;
transform: translateX(0);
transition-duration: 1000ms;
transition-timing-function: ease-in-out;
}
.navtext {
left: 50%;
transform: translateX(-50%);
position: absolute;
font-size: 30px;
}
.logo {
top: 0%;
font-size: 65px;
position: absolute;
left: 50%;
transform: translate(-50%, -50%);
top: 50%;
text-decoration: none;
color: #FFF;
}
.logobg {
width: 150px;
height: 100%;
position: absolute;
left: 50%;
transform: translateX(-50%);
}
.navelements {
position: absolute;
left: 50%;
transform: translateX(-50%);
background: red;
height: 100%;
}
.navelements:hover {
background: #303030;
transition-duration: 300ms;
}
.navbarline {
background: linear-gradient(90deg, rgba(221, 16, 247, 1) 0%, rgba(0, 212, 255, 1) 100%);
width: 100%;
height: 4px;
position: absolute;
top: 80px;
left: 0;
}
<nav>
<a href="index.html">
<div class="logobg">
<div class="logo">
AI
</div>
</div>
</a>
<a href="blank.html">
<div class="">
</div>
</a>
</nav>
<div class="navbarline"></div>
you should add this rule:
nav .logobg {
left: 50%;
transform: translateX(0);
transition-duration: 1000ms;
transition-timing-function: ease-in-out;
}
So when mouse leave the element it should apply the transition you defined that overrides the :hover rule.
Lety has a solid answer but I thought I would elaborate on my comment earlier. So I had the right idea just wrong placement. I moved .logobg up above nav:hover .logobg and added your duration and timing to .logobg. It now transitions smoothly back and forth.
body {
background: #121212;
color: #FFFFFF;
font-family: Helvetica, Arial, sans-serif;
}
nav {
background: #212121;
width: 100%;
height: 80px;
position: absolute;
top: 0;
left: 0;
}
.logobg {
width: 150px;
height: 100%;
position: absolute;
left: 50%;
transform: translateX(-50%);
transition-duration: 1000ms;
transition-timing-function: ease-in-out;
}
nav:hover .logobg {
left: 0;
transform: translateX(0);
}
.navtext {
left: 50%;
transform: translateX(-50%);
position: absolute;
font-size: 30px;
}
.logo {
top: 0%;
font-size: 65px;
position: absolute;
left: 50%;
transform: translate(-50%, -50%);
top: 50%;
text-decoration: none;
color: #FFF;
}
.navelements {
position: absolute;
left: 50%;
transform: translateX(-50%);
background: red;
height: 100%;
}
.navelements:hover {
background: #303030;
transition-duration: 300ms;
}
.navbarline {
background: linear-gradient(90deg, rgba(221, 16, 247, 1) 0%, rgba(0, 212, 255, 1) 100%);
width: 100%;
height: 4px;
position: absolute;
top: 80px;
left: 0;
}
<nav>
<a href="index.html">
<div class="logobg">
<div class="logo">
AI
</div>
</div>
</a>
<a href="blank.html">
<div class="">
</div>
</a>
</nav>
<div class="navbarline"></div>
CSS transitions reverse once the "hover" event stops. Here's a way to do it with javascript.
I'm adding an "id" with the styling that you require. An id's css will always override that of a class, which is why this works.
The javascript:
const nav = document.querySelector("nav");
const logobg = document.querySelector(".logobg");
nav.addEventListener("mouseover", () => {
logobg.setAttribute("id", "move");
})
The css:
body{
background: #121212;
color: #FFFFFF;
font-family: Helvetica, Arial, sans-serif;
}
nav{
background: #212121;
width: 100%;
height: 80px;
position: absolute;
top: 0;
left: 0;
}
#move {
left: 0;
transform: translateX(0);
transition-duration: 1000ms;
transition-timing-function: ease-in-out;
}
.navtext{
left: 50%;
transform: translateX(-50%);
position: absolute;
font-size: 30px;
}
.logo{
top: 0%;
font-size: 65px;
position: absolute;
left: 50%;
transform: translate(-50%,-50%);
top: 50%;
text-decoration: none;
color: #FFF;
}
.logobg{
width: 150px;
height: 100%;
position: absolute;
left: 50%;
transform: translateX(-50%);
}
.navelements{
position: absolute;
left: 50%;
transform: translateX(-50%);
background: red;
height: 100%;
}
.navelements:hover{
background: #303030;
transition-duration: 300ms;
}
.navbarline {
background: linear-gradient(90deg, rgba(221,16,247,1) 0%, rgba(0,212,255,1) 100%);
width: 100%;
height: 4px;
position: absolute;
top: 80px;
left: 0;
}
Related
I am trying to get an element to display when hovering another element. I already have other elements that works perfectly as-is, but one of them I just cannot seem to hit. I've tried using both > and ~, and just :hover. Regardless what I try, I cannot seem to target it.
The page is made with Elementor in WP, but don't mind it, all I need is knowledge of how to hit target the right element.
My code is as follows:
.elementor-post__thumbnail {
position: relative;
}
.elementor-post__thumbnail img {
position: relative;
}
.elementor-post__thumbnail:before {
content: '';
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
opacity: 0;
transition: opacity .3s ease-in-out;
background: #0E122E;
}
.elementor-post__thumbnail:hover:after {
opacity: .9;
}
.elementor-post__thumbnail::after {
content: '';
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
opacity: 0;
transition: opacity .3s ease-in-out;
background: #0E122E;
}
.elementor-post {
position: relative;
width: 100%;
height: 100%;
}
/* Image Post Title (The one I cant target when hovered) */
.elementor-post__text .elementor-post__title a {
opacity: 0;
text-align: right!important;
color: white!important;
position: absolute;
bottom: 5%;
right: 0;
font-family: "rbn02-medium", Sans-serif;
font-weight: 100!important;
font-size: 32px;
padding-right: 20px;
}
/* + Icon Hover */
.elementor-post__thumbnail:before {
content: "+";
display: block;
height: 40px;
width: 40px;
color: #0E122E;
background: white;
border-radius: 50%;
line-height: 30px;
text-align: center;
font-size: 2.7em;
font-weight: 900;
position: absolute;
top: 50%;
left: 50%;
opacity: 0;
transition: opacity .3s ease-in-out;
transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
z-index: 999;
}
.elementor-post__thumbnail:hover:before {
opacity: 1;
}
<article class="elementor-post elementor-grid-item post-240171 post type-post status-publish format-standard has-post-thumbnail hentry category-middagsretter category-opskrifter">
<a class="elementor-post__thumbnail__link" href="http://pagelink.com/">
<div class="elementor-post__thumbnail">
::before
<img width="1080" height="1350" src="imgpath.jpeg" class="attachment-full size-full" alt="alt tag" loading="lazy"> :::after
</div>
</a>
<div class="elementor-post__text">
<h3 class="elementor-post__title">
Link Text
</h3>
</div>
</article>
The element I can't target is the image post title - the <a> within .elementor-post__text .elementor-post__title.
I am trying to do opacity: 1; whenever the main container is hovered upon. Anyone who can tell me if I am using a wrong selector, if it is even doable, or what else I might be doing wrong? All the other hover-elements shows just fine!
You can use a sibling selector following the :hover, like .elementor-post__thumbnail__link:hover + .elementor-post__text > .elementor-post__title > a { ... }:
.elementor-post__thumbnail {
position: relative;
}
.elementor-post__thumbnail img {
position: relative;
}
.elementor-post__thumbnail:before {
content: '';
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
opacity: 0;
transition: opacity .3s ease-in-out;
background: #0E122E;
}
.elementor-post__thumbnail:hover:after {
opacity: .9;
}
.elementor-post__thumbnail::after {
content: '';
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
opacity: 0;
transition: opacity .3s ease-in-out;
background: #0E122E;
}
.elementor-post {
position: relative;
width: 100%;
height: 100%;
}
/* Image Post Title (The one I cant target when hovered) */
.elementor-post__text .elementor-post__title a {
opacity: 0;
text-align: right!important;
color: white!important;
position: absolute;
bottom: 5%;
right: 0;
font-family: "rbn02-medium", Sans-serif;
font-weight: 100!important;
font-size: 32px;
padding-right: 20px;
}
/* + Icon Hover */
.elementor-post__thumbnail:before {
content: "+";
display: block;
height: 40px;
width: 40px;
color: #0E122E;
background: white;
border-radius: 50%;
line-height: 30px;
text-align: center;
font-size: 2.7em;
font-weight: 900;
position: absolute;
top: 50%;
left: 50%;
opacity: 0;
transition: opacity .3s ease-in-out;
transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
z-index: 999;
}
.elementor-post__thumbnail:hover:before {
opacity: 1;
}
.elementor-post__thumbnail__link:hover + .elementor-post__text > .elementor-post__title > a {
opacity: 1;
}
<article class="elementor-post elementor-grid-item post-240171 post type-post status-publish format-standard has-post-thumbnail hentry category-middagsretter category-opskrifter">
<a class="elementor-post__thumbnail__link" href="http://pagelink.com/">
<div class="elementor-post__thumbnail">
::before
<img width="1080" height="1350" src="https://picsum.photos/1080/1350" class="attachment-full size-full" alt="alt tag" loading="lazy"> :::after
</div>
</a>
<div class="elementor-post__text">
<h3 class="elementor-post__title">
Link Text
</h3>
</div>
</article>
I have three images with text over them. I want to have text for first and third images to be floated to the left, and the second one to be floated to the right. I got the first and the third images to work, but I am struggling with the second image. I have been looking around but couldn't find any help. and also, I am new to html & css, so I would appreciate if someone could help.
<style>
.image {
position: relative;
width: 100%;
}
h2{
position: absolute;
top: 200px;
left: 0;
width: 100%;
}
.h2:nth-of-type(2){
position: absolute;
bottom: 200px;
left: 200px;
width: 100%;
}
h2 span {
color: white;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0); /* fallback color */
background: rgba(0, 0, 0, 0.7);
padding: 10px;
}
.overlay-image {
position: relative;
}
.overlay-image .image {
display: block;
}
.overlay-image .text {
color: #81282A;
font-size: 30px;
line-height: 1.5em;
text-shadow: 2px 2px 2px #000;
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 100%;
}
.overlay-image .hover {
position: absolute;
top: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
}
.overlay-image:hover .hover {
opacity: 1;
}
.overlay-image .normal {
transition: .5s ease;
}
.overlay-image:hover .normal {
opacity: 0;
}
.overlay-image .hover {
background-color: rgba(0,0,0,0.8);
}
.pp{
color: white;
}
#store-container {
position: relative;
width: 100%;
}
#store-image {
opacity: 0.3;
display: block;
width: 100%;
height: auto;
transition: .5s ease;
backface-visibility: hidden;
}
#store-middle {
transition: .5s ease;
opacity: 1;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
text-align: center;
}
#store-text {
background-color: #4CAF50;
color: white;
font-size: 16px;
padding: 16px 32px;
}
.TEXT{
position: relative;
width: 831px;
height: 134px;
left: 180px;
top: 56px;
padding-top: 10px;
margin-bottom: 15%;
font-style: normal;
font-weight: 300;
font-size: 35px;
line-height: 47px;
text-align: center;
color: black;
}
</style>
<div class="image"><img src="//cdn.shopify.com/s/files/1/0254/5067/6317/files/smart_large.jpg?v=1562170226" width="1179" height="480" alt="Alt text" />
<h2><span>Custom Smart Kitchens<br />We build Custom smart kitchens</span></h2>
</div>
<div class="pp">here</div>
<div class="image"><img src="//cdn.shopify.com/s/files/1/0254/5067/6317/files/laptopRepair_large.jpg?v=1561171348" width="1179" height="480" alt="Alt text" />
<h2><span>We have our own designer</span></h2>
</div>
<div class="pp">here</div>
<div class="image"><img src="//cdn.shopify.com/s/files/1/0254/5067/6317/files/electric_car_large.jpeg?v=1562179941" width="1179" height="480" alt="Alt text" />
<h2><span>We come and build it for you</span></h2>
</div>
<div class="pp">here</div>
<div class="TEXT">
<p>For more designs, visit us at the store.<br />
Call us to schedule a free quote</p>
</div>
The easiest way would be to mark the h2 you want to align right diretly in the markup
So change the markup (html) of the second <h2> and add a class <h2 class="right"> and apply the following additional css rules
div.image {
display: inline-block;
width: auto;
}
h2.right {
right: 0px;
left: auto;
width: auto;
}
Im having a very annoying problem in Shopify. My banners were working fine but all of a sudden this class called "row" came up and is pushing my banner off to the side on both mobile and desktop. I cant get my banners to work correctly, I went through my entire code to see if I had any errors and I do not, I tried to look for a ".row" that could be messing up everything but its only gridlock .row and that is something I dont feel I should be messing with, as im not sure what it does. Anyhow, thank you for your time!
Any help is greatly appreciated!
Problem
What I see as the issue
CSS
.bannerheadercontainer {
width: 100vw;
position: relative;
top: 0px;
left: calc(-50vw + 50%);
display: table;
padding: 0px;
margin: 0px;
}
.bannercontainer {
position: relative;
width: 100%;
}
.bannercontainer .btnstyle {
font-weight: bold;
position: absolute;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-webkit-appearance: none;
color: white;
font-size: 15px;
font-size: 4vw;
border: none;
border-radius: 0px! important;
height: 16%;
text-align: center;
line-height: 0vw;
cursor: pointer;
}
.bannercontainer .imgstyle {
position: absolute;
}
.bannercontainer .btnstyle span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
}
.bannercontainer .btnstyle span:after {
content: '\00bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
}
.bannercontainer .btnstyle:hover span {
padding-right: 25px;
}
.bannercontainer .btnstyle:hover span:after {
opacity: 1;
right: 0;
}
.bannercontainer .btnstyleDesktop {
position: absolute;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-webkit-appearance: none;
color: white;
font-weight: bold;
font-size: 8px;
font-size: 1.5vw;
border: none;
border-radius: 0px! important;
height: 12%;
text-align: center;
line-height: 0vw;
cursor: pointer;
}
.bannercontainer .btnstyleDesktop span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
}
.bannercontainer .btnstyleDesktop span:after {
content: '\00bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
}
.bannercontainer .btnstyleDesktop:hover span {
padding-right: 25px;
}
.bannercontainer .btnstyleDesktop:hover span:after {
opacity: 1;
right: 0;
}
.bannerimg {
filter: brightness(30%);
}
/*------ CSS MOBILE ONLY -----*/
#media only screen and (max-width: 599px) {
.bannerheadercontainer {
top: -10px;
}
.pagetitle {
font-size: 18px !important;
}
.overlaybanner {
top: -1px;
height: 98%;
}
.index-banner {
height: 300px !important;
background-size: 200% 100%;
background-repeat: no-repeat;
}
.styc-container {
width: 100%;
}
.index-gray-section-style {
background-color: #F9F9F9;
min-height: 390px;
width: 100%;
}
.index-gray-section-connected {
background-color: #F9F9F9;
min-height: 390px;
width: 100%;
}
}
HTML CODE
<!----START BANNER----->
<div id="content-desktop">
<div class="bannerheadercontainer">
<img style="width: 100%;" class="bannerimg" src="https://cdn.shopify.com/s/files/1/0025/8719/7497/files/ecobanner-compressor_2048x2048.png?v=1529095445">
<div class="overlayheaderbanner"></div>
<div class="pagetitle">ECO-FRIENDLY</div>
</div>
</div>
<div id="content-mobile">
<div class="bannerheadercontainer">
<img style="width: 100%;" class="bannerimg" src="https://cdn.shopify.com/s/files/1/0025/8719/7497/files/eco-compressor_large.png?v=1529427950">
<div style="top: 0px; height: 97%;" class="overlayheaderbanner"></div>
<div class="pagetitle">ECO-FRIENDLY</div>
</div>
</div>
<!----END BANNER----->
Change width '100vw to 100%' in your code, it will work
.bannerheadercontainer { width: 100%;}
I would like to have a span within the .btn rotate 180 deg when I click the .btn. However, the span also moved to the right and went down after it was rotated. Could anyone help me explain why it moved like that.
I tried to transform: translate(-21px, 1px) after rotation then the span will moved the right place but I believe there will be another better way to fix it. I also tried transform-origin: 50% 50% but it doesn't work either.
$('.btn').on('click', function(){
$(this).toggleClass('open');
})
#import "https://fonts.googleapis.com/css?family=Raleway";
body {
background-color: #ddd;
font-family: "Raleway", "Microsoft JhengHei", Arial, sans-serif;
color: #7a7b7c;
}
.btn {
width: 80px;
height: 80px;
background-color: #6F7272;
border-radius: 50%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
box-shadow: 0 0 2rem #babbbc;
position: absolute;
}
.btn span {
width: 40px;
height: 2px;
background-color: #ffffff;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
position: absolute;
}
.btn::before, .btn::after {
content: "";
width: 40px;
height: 2px;
background-color: #ffffff;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
position: absolute;
}
.btn::before {
margin-top: -7px;
}
.btn::after {
margin-top: 7px;
}
.open {
transition: 0.3s ease-in-out;
background-color: #6F7272;
}
.open span {
transition: .3s ease-in-out;
transform: rotate(180deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="btn">
<span></span>
</div>
If you remove transform: translate(-50%, -50%); and just keep left:26% and top: 49% It works fine.
To your question why it is happening. Because you have moved it using left and top position and again you are trying to neutralise it by translate. which is moving the center of animation to different position.
$('.btn').on('click', function(){
$(this).toggleClass('open');
})
#import "https://fonts.googleapis.com/css?family=Raleway";
body {
background-color: #ddd;
font-family: "Raleway", "Microsoft JhengHei", Arial, sans-serif;
color: #7a7b7c;
}
.btn {
width: 80px;
height: 80px;
background-color: #6F7272;
border-radius: 50%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
box-shadow: 0 0 2rem #babbbc;
position: absolute;
}
.btn span {
width: 40px;
height: 2px;
background-color: #ffffff;
top: 49%;
left: 26%;
// transform: translate(-50%, -50%);
position: absolute;
}
.btn::before, .btn::after {
content: "";
width: 40px;
height: 2px;
background-color: #ffffff;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
position: absolute;
}
.btn::before {
margin-top: -7px;
}
.btn::after {
margin-top: 7px;
}
.open {
transition: 0.3s ease-in-out;
background-color: #6F7272;
}
.open span {
transition: .3s ease-in-out;
transform: rotate(180deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="btn">
<span></span>
</div>
Your approach isn't working as expected, because after click event, you are transforming the X & Y values of your span using translate property and then rotating it. This causes it to shift it's location when transformed.
You used position: absolute to place your span in middle. this can be also be achieved via other CSS properties like display: table or display :flex
Check out the below suggestion - most of the code is all yours with just slight change.
$('.btn').on('click', function() {
$(this).toggleClass('open');
})
#import "https://fonts.googleapis.com/css?family=Raleway";
body {
background-color: #ddd;
font-family: "Raleway", "Microsoft JhengHei", Arial, sans-serif;
color: #7a7b7c;
}
.btn {
width: 80px;
height: 80px;
background-color: #6F7272;
border-radius: 50%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
box-shadow: 0 0 2rem #babbbc;
position: absolute;
display: flex;
justify-content: center;
align-items: center;
}
.btn span {
width: 40px;
height: 2px;
background-color: #ffffff;
/* top: 50%;
left: 50%;
transform: translate(-50%, -50%);
position: absolute; */
}
.btn::before,
.btn::after {
content: "";
width: 40px;
height: 2px;
background-color: #ffffff;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
position: absolute;
}
.btn::before {
margin-top: -7px;
}
.btn::after {
margin-top: 7px;
}
.open {
transition: 0.3s ease-in-out;
background-color: #6F7272;
}
.open span {
transition: .3s ease-in-out;
transform: rotate(180deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="btn">
<span></span>
</div>
Update this style
.open span {
transition: .3s ease-in-out;
transform: rotate(180deg) translate(20px, 1px );
}
$('.btn').on('click', function(){
$(this).toggleClass('open');
})
#import "https://fonts.googleapis.com/css?family=Raleway";
body {
background-color: #ddd;
font-family: "Raleway", "Microsoft JhengHei", Arial, sans-serif;
color: #7a7b7c;
}
.btn {
width: 80px;
height: 80px;
background-color: #6F7272;
border-radius: 50%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
box-shadow: 0 0 2rem #babbbc;
position: absolute;
}
.btn span {
width: 40px;
height: 2px;
background-color: #ffffff;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
position: absolute;
}
.btn::before, .btn::after {
content: "";
width: 40px;
height: 2px;
background-color: #ffffff;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
position: absolute;
}
.btn::before {
margin-top: -7px;
}
.btn::after {
margin-top: 7px;
}
.open {
transition: 0.3s ease-in-out;
background-color: #6F7272;
}
.open span {
transition: .3s ease-in-out;
transform: rotate(180deg) translate(20px, 1px );
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="btn">
<span></span>
</div>
Check if this is what you are trying to achieve.
Here, I have added a single line to the css transform-origin: 10px;. Everything else is the same. The change in JS is to remove the add class as soon as the animation carried out. Otherwise, you will need to click double times on the button to see the animation again.
$('.btn').on('click', function(){
$(this).addClass('open');
setTimeout(function() {
$('.btn').removeClass('open');
}, 300);
})
body {
background-color: #ddd;
font-family: "Raleway", "Microsoft JhengHei", Arial, sans-serif;
color: #7a7b7c;
}
.btn {
width: 80px;
height: 80px;
background-color: #6F7272;
border-radius: 50%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
box-shadow: 0 0 2rem #babbbc;
position: absolute;
}
.btn span {
width: 40px;
height: 2px;
background-color: #ffffff;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
position: absolute;
}
.btn::before, .btn::after {
content: "";
width: 40px;
height: 2px;
background-color: #ffffff;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
position: absolute;
}
.btn::before {
margin-top: -7px;
}
.btn::after {
margin-top: 7px;
}
.open {
transition: 0.3s ease-in-out;
background-color: #6F7272;
}
.open span {
transition: .3s ease-in-out;
transform: rotate(180deg);
transform-origin: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="btn">
<span></span>
</div>
I'm trying to create a rainbow circle with 8 segments, 45 degrees in size.
You'll notice that the orange segment is double the size of the others. I think these are number 1 and 8. I can't however figure out how to separate them. Are my degree wrong?
Thanks for your help.
body {
overflow: hidden;
}
.pie {
position: relative;
margin: 1em auto;
border: dashed 1px;
padding: 0;
width: 32em;
height: 32em;
border-radius: 50%;
list-style: none;
}
.slice1 {
overflow: hidden;
/**/
position: absolute;
top: 0;
right: 0;
width: 50%;
height: 50%;
transform-origin: 0% 100%;
transform: rotate(-22.5deg) skewY(0deg);
}
.slice2 {
overflow: hidden;
/**/
position: absolute;
top: 0;
right: 0;
width: 50%;
height: 50%;
transform-origin: 0% 100%;
transform: rotate(22.5deg) skewY(0deg);
}
.slice3 {
overflow: hidden;
/**/
position: absolute;
top: 0;
right: 0;
width: 50%;
height: 50%;
transform-origin: 0% 100%;
transform: rotate(67.5deg) skewY(0deg);
}
.slice4 {
overflow: hidden;
/**/
position: absolute;
top: 0;
right: 0;
width: 50%;
height: 50%;
transform-origin: 0% 100%;
transform: rotate(112.5deg) skewY(0deg);
}
.slice5 {
overflow: hidden;
/**/
position: absolute;
top: 0;
right: 0;
width: 50%;
height: 50%;
transform-origin: 0% 100%;
transform: rotate(157.5deg) skewY(0deg);
}
.slice6 {
overflow: hidden;
/**/
position: absolute;
top: 0;
right: 0;
width: 50%;
height: 50%;
transform-origin: 0% 100%;
transform: rotate(202.5deg) skewY(0deg);
}
.slice7 {
overflow: hidden;
/**/
position: absolute;
top: 0;
right: 0;
width: 50%;
height: 50%;
transform-origin: 0% 100%;
transform: rotate(247.5deg) skewY(0deg);
}
.slice8 {
overflow: hidden;
/**/
position: absolute;
top: 0;
right: 0;
width: 50%;
height: 50%;
transform-origin: 0% 100%;
transform: rotate(-67.5deg) skewY(0deg);
}
.slice-contents1 {
position: absolute;
left: -100%;
width: 200%;
height: 200%;
border-radius: 50%;
background: #ffff4d;
text-align: center;
transition: background-color .5s;
}
.slice-contents2 {
position: absolute;
left: -100%;
width: 200%;
height: 200%;
border-radius: 50%;
background: #9AC147;
text-align: center;
transition: background-color .5s;
}
.slice-contents3 {
position: absolute;
left: -100%;
width: 200%;
height: 200%;
border-radius: 50%;
background: #639b47;
text-align: center;
transition: background-color .5s;
}
.slice-contents4 {
position: absolute;
left: -100%;
width: 200%;
height: 200%;
border-radius: 50%;
background: #3869c3;
text-align: center;
transition: background-color .5s;
}
.slice-contents5 {
position: absolute;
left: -100%;
width: 200%;
height: 200%;
border-radius: 50%;
background: #1e3868;
text-align: center;
transition: background-color .5s;
}
.slice-contents6 {
position: absolute;
left: -100%;
width: 200%;
height: 200%;
border-radius: 50%;
background: #c682bb;
text-align: center;
transition: background-color .5s;
}
.slice-contents7 {
position: absolute;
left: -100%;
width: 200%;
height: 200%;
border-radius: 50%;
background: #9a1d34;
text-align: center;
transition: background-color .5s;
}
.slice-contents8 {
position: absolute;
left: -100%;
width: 200%;
height: 200%;
border-radius: 50%;
background: #f7941e;
text-align: center;
transition: background-color .5s;
}
.slice1 .slice2 .slice3 .slice4 .slice5 .slice6 .slice7 .slice8 .slice-contents1 .slice-contents2 .slice-contents3 .slice-contents4 .slice-contents5 .slice-contents6 .slice-contents7 .slice-contents8 {
transform: skewY(40deg) rotate(25deg);
}
.slice-contents1:hover {
background: #ffff1a;
}
.slice-contents2:hover {
background: #8db23c;
}
.slice-contents3:hover {
background: #588a3f;
}
.slice-contents4:hover {
background: #2d549b;
}
.slice-contents5:hover {
background: #132340;
}
.slice-contents6:hover {
background: #ad4f9e;
}
.slice-contents7:hover {
background: #85192d;
}
.slice-contents8:hover {
background: #f38809;
}
<html>
<body>
<ul class='pie'>
<li class='slice1'>
<div class='slice-contents1'>#</div>
</li>
<li class='slice2'>
<div class='slice-contents2'>#</div>
</li>
<li class='slice3'>
<div class='slice-contents3'>#</div>
</li>
<li class='slice4'>
<div class='slice-contents4'>#</div>
</li>
<li class='slice5'>
<div class='slice-contents5'>#</div>
</li>
<li class='slice6'>
<div class='slice-contents6'>#</div>
</li>
<li class='slice7'>
<div class='slice-contents7'>#</div>
</li>
<li class='slice8'>
<div class='slice-contents8'>#</div>
</li>
<ul>
</body>
</html>
Ohh thats obvious ... you are using square element(li) and rotating it in different angles to make that pi..
According to your design each li div will be of 90 Degree ,while 45 degree of every will be hidden by other element,
for every element upto slices 7 will work good but slice 8 of angle=90.will cover yellow colored element.
take your fiddle for example ..you will notice only yours orange element(slice 8) is of 90 degree and rest are good except yellow(slice 1 ) that was hidden inside your slice 8.
to solve it you should reduce your arc to make it fit..
Make changes to following ..your pie will be go to go
.slice-contents8 {
position: absolute;
left: -100%;
width: 200%; height: 200%;
border-radius: 50%;
text-align: center;
transition: background-color .5s;
background-image: linear-gradient(135deg, transparent 50%, #f7941e 50%), linear-gradient(90deg, white 50%, transparent 50%);
}
.slice8 {
overflow: hidden; /**/
position: absolute;
top: 0; right: 0;
width: 50%; height: 50%;
transform-origin: 0% 100%;
transform: rotate(-112.5deg);
}
see the below demo
Working Fiddle