I have a div which contains an image and overlay:
<div class="container">
<div class="overlay"></div>
<img src="tablet.png" alt="tablet">
</div>
How can I make an overlay with shadow like ?
While it surely can be done via CSS or SVG, most likely that shadow is just a background image where the shadow is already drawn.
However, here's an example of how you could think of it in css:
.scene {
position: relative;
width: 200px;
height: 200px;
background: #60c18b;
overflow: hidden;
}
.object {
position: absolute;
width: 40px;
height: 45px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-image: url(https://proxy.duckduckgo.com/iu/?u=https%3A%2F%2Fcdn.onlinewebfonts.com%2Fsvg%2Fimg_121330.png&f=1);
background-repeat: no-repeat;
background-size: 100% 100%;
background-position: top left;
}
.object:after, .object:before {
content: '';
display: block;
width: 100%;
height: 100px;
background: linear-gradient(rgba(0,0,0,0.3), transparent);
transform: skew(-45deg, 0deg);
transform-origin: top left;
position: absolute;
}
.object:before {
transform: translateY(2px) skew(0deg, -45deg);
transform-origin: top right;
width: 100px;
height: 100%;
position: absolute;
right: 0;
background: linear-gradient(to left, rgba(0,0,0,0.3), transparent);
}
<div class="scene">
<div class="object"></div>
</div>
Note that this is just for fun, it's not perfect and I wouldn't use this on a production site.
Related
How to remove line behind transparent button in CSS? See Picture Below
How to remove line behind transparent button in CSS? See Picture Below
How to remove line behind transparent button in CSS? See Picture Below
.fullscreen {
height: 100%;
width: 100%;
background: no-repeat url("https://www.planetware.com/wpimages/2019/10/switzerland-in-pictures-most-beautiful-places-matterhorn.jpg") center / cover;
}
.line {
position: absolute;
width: 3px;
height: 100%;
background-color: rgba(255, 255, 255, 1);
top: 0;
left: 50%;
}
.btn {
position: absolute;
width: 100px;
height: 100px;
border: 3px solid #ffffff;
transform: translate(-50%, -50%);
top: 50%;
left: 50%;
z-index: 1;
}
.btn::after {
content: '';
display: block;
width: 60px;
height: 60px;
background: #ffffff;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<div class="fullscreen">
<span class="line"></span>
<div class="btn"></div>
</div>
This is more of a hack and might not work for you because you didn't provide any code so far.
My idea was to give the (in my case) .outer_box the same background-image as the .background and scale it the same way.
.fullscreen {
height: 100vh;
width: 100vw;
background: no-repeat url("https://www.planetware.com/wpimages/2019/10/switzerland-in-pictures-most-beautiful-places-matterhorn.jpg") center / cover;
}
.line {
position: absolute;
width: 3px;
height: 100%;
background-color: rgba(255, 255, 255, 1);
top: 0;
left: 50%;
}
.btn {
position: absolute;
width: 100px;
height: 100px;
border: 3px solid #ffffff;
transform: translate(-50%, -50%);
top: 50%;
left: 50%;
z-index: 1;
background: no-repeat url("https://www.planetware.com/wpimages/2019/10/switzerland-in-pictures-most-beautiful-places-matterhorn.jpg") center / cover;
background-size: 100vw;
}
.btn::after {
content: '';
display: block;
width: 60px;
height: 60px;
background: #ffffff;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
<div class="fullscreen">
<span class="line"></span>
<div class="btn"></div>
</div>
I'm trying to design a website section that has 3 hexagons lined up. Inside the hexagons I want an image, which I have figured out how to do. BUT I also want to add a color overlay. Every time I try, the image disappears and the overlay gets doubled up in some places because of how I had to make the hexagon shape.
You can check out the code or see it live: https://jsfiddle.net/dfmcu4gt/
If you could tell me how to do this in tailwind CSS that would be even better.
#overlay {
background: rgba(9, 37, 90, 0.4);
object-fit: cover;
z-index: 2;
}
.hexagon {
position: relative;
width: 300px;
height: 173.21px;
margin: 86.60px 0;
background-image: url(https://www.uplers.com/wp-content/uploads/2020/06/Hiring-Web-Developers-Agencies-vs-Freelance-Portals.jpg);
background-size: auto 346.4102px;
background-position: center;
}
.hexagon1 {
position: relative;
width: 300px;
height: 173.21px;
margin: 86.60px 0;
background-image: url(https://www.octalsoftware.com.sg/blog/wp-content/uploads/2019/07/inhouse-developers-team.jpg);
background-size: auto 346.4102px;
background-position: center;
}
.hexagon2 {
position: relative;
width: 300px;
height: 173.21px;
margin: 86.60px 0;
background-image: url(https://blog.hubspot.com/hubfs/WordPress%20developer%20reviewing%20WordPress%20core.jpg);
background-size: auto 346.4102px;
background-position: center;
}
.hexTop,
.hexBottom {
position: absolute;
z-index: 1;
width: 212.13px;
height: 212.13px;
overflow: hidden;
-webkit-transform: scaleY(0.5774) rotate(-45deg);
-ms-transform: scaleY(0.5774) rotate(-45deg);
transform: scaleY(0.5774) rotate(-45deg);
background: inherit;
left: 43.93px;
}
/*counter transform the bg image on the caps*/
.hexTop:after,
.hexBottom:after {
content: "";
position: absolute;
width: 300.0000px;
height: 173.20508075688775px;
-webkit-transform: rotate(45deg) scaleY(1.7321) translateY(-86.6025px);
-ms-transform: rotate(45deg) scaleY(1.7321) translateY(-86.6025px);
transform: rotate(45deg) scaleY(1.7321) translateY(-86.6025px);
-webkit-transform-origin: 0 0;
-ms-transform-origin: 0 0;
transform-origin: 0 0;
background: inherit;
}
.hexTop {
top: -106.0660px;
}
.hexTop:after {
background-position: center top;
}
.hexBottom {
bottom: -106.0660px;
}
.hexBottom:after {
background-position: center bottom;
}
.hexagon:after {
content: "";
position: absolute;
top: 0.0000px;
left: 0;
width: 300.0000px;
height: 173.2051px;
z-index: 2;
background: inherit;
}
<div id="overlay" class="hexagon">
<div class="hexTop"></div>
<div class="hexBottom"></div>
</div>
<div class="hexagon1">
<div class="hexTop"></div>
<div class="hexBottom"></div>
</div>
<div class="hexagon2" style="">
<div class="hexTop"></div>
<div class="hexBottom"></div>
</div>
I'm trying to achive frosted glass effect with CSS like here: https://codepen.io/GreggOD/full/xLbboZ
But I think, I'm missing something, because it shows me the full image, but smaller size
I have set background-size: cover; background-attachment: fixed;, yet this doesn't fix the problem
#second_wrapper {
background-image: url("https://images.pexels.com/photos/2466644/pexels-photo-2466644.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260");
background-attachment: fixed;
background-size: cover;
background-position: center;
height: 250px;
width: 500px;
}
#test_image {
background: inherit;
position: relative;
left: 50%;
top: 50%;
overflow: hidden;
height: 200px;
width: 400px;
transform: translate(-50%, -50%);
}
#blur {
position: absolute;
height: 100%;
width: 100%;
background: inherit;
filter: blur(5px);
}
<div id='second_wrapper'>
<div id='test_image'>
<div id='blur'>
</div>
</div>
</div>
Is this what u wanted?
I added new css rules to #test_image:after
background: inherit;
position: relative;
left: 10%;
top: 10%;
height: 200px;
width: 400px;
/*transform: translate(-50%, -50%);*/
Note that you cannot use transform in this case , because, when you transform, the inherited background image also moves with the div.
Try uncommenting transform and change the values of translate in devtools
#second_wrapper {
background-image: url("https://images.pexels.com/photos/2466644/pexels-photo-2466644.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260");
background-attachment: fixed;
background-size: cover;
background-position: center;
height: 250px;
width: 500px;
}
#test_image {
background: inherit;
position: relative;
left: 10%;
top: 10%;
height: 200px;
width: 400px;
/*transform: translate(-50%, -50%);*/
}
#test_image:after {
content: "";
background: inherit;
filter: blur(10px);
width: 400px;
height: 200px;
display: block;
}
<div id='second_wrapper'>
<div id='test_image'>
<div id=''>
T
</div>
</div>
</div>
I have a div which has been rotated 45 degrees, this creates a diamond shape. Inside I have another div with a minus 45-degree rotation so the content is square I set the inner container to have 100% width & heightbut because of the rotation, it doesn't fill all the space.
I know the output I get is accurate to the code I've written because of the rotation it is 100%, so I suppose I need it larger than 100% and to scale as the browser scales.
.headerImg {
position: absolute;
top: -100px;
right: -100px;
width: 50%;
display: block;
background: #eee;
height: 95vh;
overflow: hidden;
transform: rotate(45deg);
}
.rotateBack {
width: 100%;
height: 100%;
transform: rotate(-45deg);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}
<div class="headerImg">
<div class="rotateBack" style="background-image: url('https://www.rd.com/wp-content/uploads/2017/06/05-dog-breed-Safety-Tips-to-Keep-Your-Dog-in-Top-Shape-This-Summer-508549561-Yevgen-Romanenko.jpg')">
</div>
</div>
An example JSFiddle
HTML
<div class="part">
<div class="losange">
<div class="los1">
<img src="http://farm3.staticflickr.com/2178/3531465579_8bff044e9b_z.jpg?zz=1" alt="" width="255" height="320" />
</div>
</div>
CSS
.losange, .losange div {
margin: 0 auto;
transform-origin: 50% 50%;
overflow: hidden;
width: 250px;
height: 250px;
}
.losange {
transform: rotate(45deg) translateY(10px);
}
.losange .los1 {
width: 355px;
height: 355px;
transform: rotate(-45deg) translateY(-74px);
}
.losange .los1 img {
width: 100%;
height: auto;
}
I found this and have used for a project of mine. Hope it helps you, understand the main idea.
Since the container div has fixed size you can use absolute position with the image and make it overflow by specifing negative values on top/left/bottom/right;
.headerImg {
width: 50%;
margin: auto;
display: block;
background: #eee;
height: 95vh;
overflow: hidden;
transform: rotate(45deg);
position: relative;
}
.rotateBack {
position: absolute;
top: -30%;
left: -30%;
bottom: -30%;
right: -30%;
transform: rotate(-45deg);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}
<div class="headerImg">
<div class="rotateBack" style="background-image: url('https://www.rd.com/wp-content/uploads/2017/06/05-dog-breed-Safety-Tips-to-Keep-Your-Dog-in-Top-Shape-This-Summer-508549561-Yevgen-Romanenko.jpg')">
</div>
</div>
By the way here is another way to achive what you want using clip-path:
body {
margin: 0;
}
.rotateBack {
height: 100vh;
width: 50%;
margin: auto;
clip-path: polygon(50% 0, 0 50%, 50% 100%, 100% 50%);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}
<div class="rotateBack" style="background-image: url('https://www.rd.com/wp-content/uploads/2017/06/05-dog-breed-Safety-Tips-to-Keep-Your-Dog-in-Top-Shape-This-Summer-508549561-Yevgen-Romanenko.jpg')">
</div>
Or using linear-gradient (but the background cannot be transparent):
body {
margin: 0;
}
.back {
height: 100vh;
width: 50%;
margin: auto;
background:
linear-gradient(45deg, #fff 25%, transparent 20%, transparent 75%, #fff 70%),
linear-gradient(-45deg, #fff 25%, transparent 20%, transparent 75%, #fff 20%),
url('https://www.rd.com/wp-content/uploads/2017/06/05-dog-breed-Safety-Tips-to-Keep-Your-Dog-in-Top-Shape-This-Summer-508549561-Yevgen-Romanenko.jpg') center/cover no-repeat;
}
<div class="back">
</div>
i want help to add two image one over the other and position two images in center
<div class="im1"> </div>
.im1{
position: relative; top: 0; left: 0;
background-image:url("../images/img-shadow.png"),url("../images/img-1.png");
background-size:contain;
height:358px;
background-repeat: no-repeat,no-repeat;
}
background image is with shadow
i want it to be
This actually can be solved only with CSS.
I created an example here that generates the rotated border of the image.
Now you can insert any image inside :)
p.s of course you need to change the width and the height of the image inside to be the same as the frame diagonal. you can use CSS calculate for this.
body {
background-color: #F3F5F6;
}
.shadow:before,
.shadow:after {
content: "";
position: absolute;
z-index: -1;
height: 10%;
max-width: 90%;
width: 90%;
}
.shadow:before {
-webkit-transform: rotate(86deg);
left: -72px;
right: auto;
top: 118px;
box-shadow: 0 15px 5px rgba(0, 0, 0, 0.2);
}
.shadow:after {
-webkit-transform: rotate(84deg);
left: auto;
right: -92px;
bottom: 75px;
box-shadow: 0 -15px 5px rgba(0, 0, 0, 0.2);
}
.rotate {
-webkit-transform: rotate(45deg);
}
.box {
width: 200px;
height: 200px;
position: absolute;
top: 100px;
left: 100px;
}
.pic-wrapper {
width: 100%;
height: 100%;
border: 10px solid #fff;
overflow: hidden;
}
.pic {
background-image: url('http://modernschoolec.com/wp-content/uploads/2015/04/11-980x408.jpg');
background-repeat: no-repeat;
background-size: cover;
background-position: center;
/* (side)(sqrt(2)) */
width: 282px;
height: 282px;
-webkit-transform: rotate(-45deg);
position: relative;
top: -40px;
left: -40px;
}
<div class="box shadow rotate">
<div class="pic-wrapper">
<div class="pic"></div>
</div>
</div>
You could either give the shadow image a z-index of 100 and give the school image a z-index of 101 or set one to be position relative and one to be position absolute, but you will need media queries to make it responsive.
.im1{
background-image:url("../images/img-1.png"),url("../images/img-shadow.png");
height:358px;
background-repeat: no-repeat,no-repeat;
background-position: center , center;
}