Shape transition with :target - html

How to :target 1 little red box to do transition into a yellow circle by clicking hyperlink and then make the same little box to transition into a blue square?
Here is my CSS for the little red square:
#Redsquare{
height: 15px;
width: 15px;
background-color: rgb(255,0,0);
position: absolute;
top: 330px;
left: 640px;
transition: all 0.5s linear;
}
Here is the code which targets the #Redsquare into yellow circle.
#Redsquare:target{
height: 300px;
width: 300px;
border-radius: 50%;
background-color: rgb(255,255,0);
top: 200px;
left: 500px;
}
But I want the same little circle to transform into a Bluesquare as well by pressing another button.

This can be done. But it requires nesting in the HTML like shown in the code below. Please do not use this approach if you need the same div to be transformed more than two or three times as the markup will become too messy.
Basically what we are doing here is as follows:
The element that will be transformed is the div with class as box. But how and what it would be transformed to depends on the link that is clicked and the associated target.
When the 1st link is clicked, the outermost div with Yellowcircle is the target. As per the CSS, an element with class box will be transformed to a yellow circle when the target is Yellowcircle.
When the 2nd link is clicked, the Bluesquare div becomes the target and as per CSS in this case, the box should become a blue square.
Finally when the 3rd link is clicked, the target is the general #, so the default .box CSS style will be applied and it goes back to being a red square.
There are other alternatives but they involve JavaScript.
.box {
height: 150px;
width: 150px;
background-color: rgb(255, 0, 0);
transition: all 0.5s linear;
}
#Yellowcircle:target .box {
border-radius: 50%;
background-color: rgb(255, 255, 0);
}
#Bluesquare:target .box {
background-color: rgb(0, 0, 255);
}
/* Just for demo */
a {
position: relative;
margin: 0px 4px;
text-decoration: none;
font-family: Calibri;
font-variant: small-caps;
color: crimson;
}
a:after {
position: absolute;
content: "|";
padding: 0px 4px;
}
a:last-of-type:after {
display: none;
}
<div id='Yellowcircle'>
<div id='Bluesquare'>
<div class='box'>
</div>
</div>
</div>
<a href='#Yellowcircle'>Transform to yellow circle</a>
<a href='#Bluesquare'>Transform to blue square</a>
<a href='#'>Go back to default</a>
This is what I meant by markup becoming messy while needing to transform into more than 3 shapes. Notice how we have to introduce an extra level for each extra shape that is needed.
.box {
height: 150px;
width: 150px;
background-color: rgb(255, 0, 0);
transition: all 0.5s linear;
}
#Yellowcircle:target .box {
border-radius: 50%;
background-color: rgb(255, 255, 0);
}
#Bluesquare:target .box {
background-color: rgb(0, 0, 255);
}
#Greenoval:target .box {
border-radius: 75px 100px;
background-color: rgb(0, 255, 0);
}
/* Just for demo */
a {
position: relative;
margin: 0px 4px;
text-decoration: none;
font-family: Calibri;
font-variant: small-caps;
color: crimson;
}
a:after {
position: absolute;
content: "|";
padding: 0px 4px;
}
a:last-of-type:after {
display: none;
}
<div id='Yellowcircle'>
<div id='Bluesquare'>
<div id='Greenoval'> <!-- notice how for each shape we need to add an extra level -->
<div class='box'>
</div>
</div>
</div>
</div>
<a href='#Yellowcircle'>Transform to yellow circle</a>
<a href='#Bluesquare'>Transform to blue square</a>
<a href='#Greenoval'>Transform to green oval</a>
<a href='#'>Go back to default</a>

Related

How do I add a triangle at the end of a div with opacity 0.2?

I want it to turn out like this, but unfortunately my triangle goes into the background of the next stage. I spent 3 hours on it. Help please
https://stackblitz.com/edit/angular-3llbmq?file=src/components/sales-funnel/sales-funnel.component.html
Here it is done with polygon, adapt colors yourself
div.container {
display: inline-flex;
align-items: center;
position: relative;
background: black;
width: 100%;
}
div.tangle {
height: 50px;
width: 200px;
clip-path: polygon(0% 20%,
60% 20%,
95% 20%,
100% 50%,
95% 80%,
60% 80%,
0% 80%);
}
div.tangle:nth-child(1) {
background:lightgreen;
transform: translateX(20px);
z-index:3;
}
div.tangle:nth-child(2) {
background:green;
transform: translateX(10px);
}
div.normal {
height: 30px;
width: 200px;
background: white;
}
<div class="container">
<div class="tangle"></div>
<div class="tangle"></div>
<div class="normal"></div>
</div>
This can easily be achieved with the use of ::before and ::after pseudo-elements - with one providing the background of the 'next step' and one providing the triangle with the 'current step' bg color.
Not sure if you neeed a elements in the lis - so I just did straight li's but it would not be hard to change the styling for the use of a elements.
Its best not to try to to use opacity for the step differences - its more accessible to use hex codes directly rather than the one hex code with different opacity values.
Note that the solution of preventing the bleeding color is to space the li's apart with margin and to use the before / after pseudo-elements to fill the gaps - its better to do this than overlap the element over he next step to prevent issues with clicking on areas that are covered by the triangles
ul {
display: flex;
list-style: none;
padding: 0;
border: solid 1px #d4d4d4;
background: lemonChiffon
}
li {
font-size: 16px;
line-height: 20px;
margin-right: 16px;
padding: 4px 32px 4px 8px;
position: relative;
}
.visited {
background: #AFD954;
color: #fff;
}
.visited::before {
content: '';
width: 16px;
height: 28px;
z-index: 5;
position: absolute;
top: 0;
right:-16px;
background: #9BCE29
}
.visited::after {
content: '';
width: 0;
height: 0;
border-top: 14px solid transparent;
border-bottom: 14px solid transparent;
border-left: 14px solid #AFD954;
position: absolute;
right:-14px;
z-index: 9;
top: 0
}
.active {
background: #9BCE29;
color: #fff
}
.active::before {
content: '';
width: 16px;
height: 28px;
z-index: 5;
position: absolute;
top: 0;
right:-16px;
background: lemonChiffon
}
.active::after {
content: '';
width: 0;
height: 0;
border-top: 14px solid transparent;
border-bottom: 14px solid transparent;
border-left: 14px solid #9BCE29 ;
position: absolute;
right:-14px;
z-index: 9;
top: 0
}
.not-visited {
background: lemonChiffon
}
<ul>
<li class="visited">New Deal</li>
<li class="active">Contact</li>
<li class="not-visited">Qualified</li>
</ul>
I had edited your stackbliz example. Please note the HTML and CSS changes.
Don't use opacity to lighten the color. Instead, use SCSS lighten and darken methods.
Please utilize the most of the CSS than the HTML part for the assigning styles. Utilize the classes you have.
NOTE: Please take the benefit of SCSS variables, nesting and pre-defined methods.
Added the reverse z-index to stack the previous element to place over next element.
Below 6 is the total elements
[ngStyle]="{
zIndex: 6 - i
}"
https://stackblitz.com/edit/angular-jhk6qf?file=src/components/sales-funnel/sales-funnel.component.scss

css hover div flickering

Well, my HTML looks like this, when I hover over the image the two checkboxes with a black background should be visible.
<img class='itemImage'/>
<div class='hoverDisplay'>
<div class="selctImgInptWrapper big">
<input class="selctImgInpt" type="checkbox" value="">
</div>
<div class="selectWrapperImgRetouch big">
<input class="selctImgRetouch" type="checkbox" value="">
</div>
</div>
My CSS
.hoverDisplay {
height: 75px;
font-size: 0.80rem;
background-color: rgba(44, 44, 44, 0.3);
background: rgba(44, 44, 44, 0.3);
color: #ffffff;
width: 95%;
bottom: 8px;
position: absolute;
padding: 2px 5px;
display: none; }
.hoverDisplay .selctImgInptWrapper {
bottom: 50px;
position: absolute;
padding: 2px 5px;
}
.hoverDisplay .selectWrapperImgRetouch {
bottom: 30px;
position: absolute;
padding: 2px 5px; }
.itemImage:hover ~ .hoverDisplay {
display: block; }
It works fine when I hover on the image, the two checkboxes are visible, the problem starts when I hover on the checkboxes it starts to flicker
I am not able to figure out the false scenario here.
When I move my cursor to the black are which is hoverDisplay class it starts to flicker and I am not able to check any checkboxes. While moving my
Simply because you will loss the hover when you want to use the input as you are no more hovering the image but another element which is a sibling. To avoid this add another property to keep the display:block state:
.itemImage:hover ~ .hoverDisplay,
.hoverDisplay:hover {
display: block;
}
The problem is that you show the checkboxes when you hover over the image. And then when you hover the checkboxes ( because they are not inside the image ( they are impossible to be) ) you hover out the image and css tries to hide them. But checkboxes are on top of the image, so the flickering happens.
You basically hover in and out the image in the same time.
One solution would be to wrap the img and checkboxes in a div and show the checkboxes when you hover over the div not just the img.
.img-container {
position:relative;
width:350px;
}
.hoverDisplay {
height: 75px;
font-size: 0.80rem;
background-color: rgba(44, 44, 44, 0.3);
background: rgba(44, 44, 44, 0.3);
color: #ffffff;
width: 95%;
bottom: 8px;
position: absolute;
padding: 2px 5px;
display: none;
}
.hoverDisplay .selctImgInptWrapper {
bottom: 50px;
position: absolute;
padding: 2px 5px;
}
.hoverDisplay .selectWrapperImgRetouch {
bottom: 30px;
position: absolute;
padding: 2px 5px;
}
.img-container:hover .hoverDisplay {
display: block;
}
<div class="img-container">
<img class="itemImage" src="http://via.placeholder.com/350x150">
<div class='hoverDisplay'>
<div class="selctImgInptWrapper big">
<input class="selctImgInpt" type="checkbox" value="">
</div>
<div class="selectWrapperImgRetouch big">
<input class="selctImgRetouch" type="checkbox" value="">
</div>
</div>
</div>

css filter: blur frosting glass effect not working, no blur, content is influenced

I want to have a background photo with a div in front.
The div should have a blurry dark background and white text.
But what it is doing at the moment is: dark background without blur and dark text.
Please help me!
#section0 {
background-color: lightgreen; /*normally the photo*/
}
.blurwrapper {
position: relative;
overflow: hidden;
}
.blur {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: black;
filter: blur(1px);
opacity: 0.2;
transform: scale(1.5);
z-index: 1;
}
h1 {
color: white;
}
.about {
color: white;
background: none;
margin: auto;
margin-top: 20px;
max-width: 800px;
font-size: 15px;
padding: 20px;
text-align: center;
letter-spacing: 2px;
color: white;
border-top: 1px solid white;
z-index: 2;
}
<div class="section active" id="section0">
<div class="blurwrapper">
<h1><span>...</span></h1>
<p class="about">...</p>
<div class="blur"></div>
</div>
</div>
the blur filter as you can see is applied to the current element.
This means that if you want to blur the image you need to apply the blur to the #section0 container that has the background-image set. If you have a colour instead of an image you will see only the border blurred.
For more information please have a look at the documentation.
https://developer.mozilla.org/en-US/docs/Web/CSS/filter
To give a more clear example using your code: http://codepen.io/ThePeach/full/egYbbe/

How to make a <p> not to inherit the <span> opacity style? [duplicate]

This question already has answers here:
I do not want to inherit the child opacity from the parent in CSS
(18 answers)
Closed 6 years ago.
I'm trying to make a white button with rounded corners and with a little transparency. The text should not be transparent. I tried to use opacity: initial for <p> style but it seems to not work. Take a look at my snippet to understand better.
body {
background-color: #264D38;
}
.button {
display: inline-block;
width: 150px;
border-radius: 2px;
margin-top: 20px;
margin-bottom: 20px;
background-color: #898989;
opacity: 0.4;
filter: alpha(opacity=40); /* Para IE8 e anteriores */
}
span.button > p {
opacity: initial;
padding: 10px;
color: #ffffff;
font-weight: bold;
text-align: center;
}
.button:hover {
background-color: #000000;
}
<body>
<span class="button"><p>BUY NOW</p></span>
</body>
You could use an RGBA value for the background colour instead of using opacity.
Example
.button {
display: inline-block;
width: 150px;
border-radius: 2px;
margin-top: 20px;
margin-bottom: 20px;
background-color: rgba(137,137,137,.4);
}
Opacity affects all children elements. Children can't have a 0% transparency, when a parent have 40%.
Other solution is setting only semi-transparent background.
body {
background-color: #264D38;
}
.button {
display: inline-block;
width: 150px;
border-radius: 2px;
margin-top: 20px;
margin-bottom: 20px;
background-color: rgba(255, 255, 255, 0.1);
}
span.button > p {
padding: 10px;
color: #ffffff;
font-weight: bold;
text-align: center;
}
.button:hover {
background-color: rgba(0, 0, 0, 0.2);
}
<body>
<a href="#">
<span class="button">
<p>BUY NOW</p>
</span>
</a>
</body>
First, use a proper structure of the code. span is an inline type and must be in the p element, which is a block type, as #hungerstar says it will not be a valid markup.
Then you can do it like this, with :before pseudo element to set the background and absolute position of the span :
See it here
You can use RGBA or HSLA for your background-color. You can improve on your markup so it's no longer invalid (you're wrapping a block level element <p> with an inline element <span>). We now have one less element with the same results.
Support chart for rgba() and hsla().
<span class="button">BUY NOW</span>
body {
background-color: #264D38;
}
.button {
display: inline-block;
width: 150px;
padding: 26px 0;
border-radius: 2px;
margin-top: 20px;
margin-bottom: 20px;
background-color: rgba( 137, 137, 137, 0.4 );
color: #FFF;
font-weight: bold;
text-align: center;
}
.button:hover {
background-color: #000;
}
Demo JSFiddle.

HTML/CSS transparency through multiple layers

Is it possible to create an element, that creates a transparency through x-number of layers 'behind' it?
Example: I have layers with z-indexes 1,2,3,4, whereas 1 is red. I then create a '5th' layer, that I want to cut through the colors of layers 2,3,4 and see the red color through. Is that possible?
You can experiment with the new mix-blend-mode and/or background-blend-mode (if you have background images) which is currently in candidate recommendation for Compositing and blending Level 1.
References: blend modes, and mix-blend-mode.
Be advised though, that this is currently not supported by IE, Edge and Opera.
In the example below, you can see that the top-level div shows red seeping thru from the lowest-level div.
Example Snippet:
.red { background-color: red; }
.blue { background-color: blue; }
.green { background-color: green; }
.yellow { background-color: yellow; }
div {
width: 120px; height: 120px;
position: absolute;
top: 16px; left: 16px;
}
div:nth-of-type(2) { top: 32px; left: 32px; mix-blend-mode: difference; }
div:nth-of-type(3) { top: 48px; left: 48px; mix-blend-mode: overlay;}
div:nth-of-type(4) { top: 64px; left: 64px; mix-blend-mode: multiply; }
<div class="red">1</div>
<div class="blue">2</div>
<div class="green">3</div>
<div class="yellow">4</div>
Transparensy trough multiple elements
Lets try it out:
div {
width: 500px;
height: 300px;
border: 50px solid transparent;
}
.a1 {
background-color: rgba(255, 0, 0, 1);
}
.a2 {
background-color: rgba(255, 165, 0, 0.5);
}
.a3 {
background-color: rgba(0, 128, 0, 0.5);
}
.a4 {
background-color: rgba(0, 0, 255, 0.5);
}
.a5 {
background-color: rgba(238, 130, 238, 0.5);
}
<div class="a1">
<div class="a2">
<div class="a3">
<div class="a4">
<div class="a5">
</div>
</div>
</div>
</div>
</div>
Seems like there is transparency trough all elements.
You can specify the color and transparency of that color in css,
If none of the opacity's combined is 100%, you should be able to get a mix of the colors.
That would look like:
.elclass{
background-color:#f00;
opacity:.2; //20% opacity;
}
if you don't want the opacity of the object to be 20%, but just the background-color use:
.elclass{
background-color:rgba(255,0,0,.2);
}
rgba colors are however not 100% browser safe.