How to create a cross (x) inside a div that cointains an image? The cross must also overlap the image, is possible do it in pure css or I must to create a new image with the cross?
Background blend mode with two images It's as easy as adding two background images in the CSS declaration. The next choice is to have a background color (or not). If you do not want a background color, this can be removed and the images will blend together depending on the blend mode that you choose.
The task is to make the close button using Pure CSS. There are two approaches that are discussed below. Approach 1: Create a <div> inside another <div> which has alphabet 'X' in it which helps in displaying the close button. When the “click” event occurs on 'X', then perform the operation.
CSS-
#cross {
width: 100px;
height: 100px;
position: relative;
transform:rotate(45deg);
-ms-transform:rotate(45deg); /* IE 9 */
-webkit-transform:rotate(45deg); /* Safari and Chrome */
}
#cross:before, #cross:after {
content: "";
position: absolute;
z-index: -1;
background: #d00;
}
#cross:before {
left: 50%;
width: 30%;
margin-left: -15%;
height: 100%;
}
#cross:after {
top: 50%;
height: 30%;
margin-top: -15%;
width: 100%;
}
Demo
Ways to reproduce this-
Step-
Create a simple square by adding no background color to it-
#cross {
width: 100px;
height: 100px;
position: relative;
}
Second step-
`CSS gives you compatibility to play with sudo-elements`.
There is always content space onto every element in css.
Example- Adding before after sudo-element
Third step-
By aligning these before after elements position:absolute
to relative parent you get the shape.
Last step- Transform rotate it the way you want. an example-
Transform in css
By the way @Adam's way of doing this is clever and once preferred by me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With