Box-shadow is not working on my image element - html

box-shadow is not working on my image element - I'm talking about .card img:nth-child(1). Here is my HTML code:
.card {
display: flex;
flex-flow: column wrap;
align-items: center;
}
.card img:nth-child(1) {
height: 220px;
width: 100%;
object-fit: cover;
box-shadow: 0px 10px 5px 0px rgba(0, 0, 0, 0.75);
clip-path: polygon(0 0, 100% 0, 100% 86%, 63% 100%, 28% 87%, 0 100%);
}
.card img:nth-child(2) {
height: 150px;
width: 150px;
object-fit: cover;
border-radius: 50%;
border: 10px solid #fff;
box-shadow: 5px 0 10px rgba(0, 0, 0, .7);
margin-top: -40%;
z-index: 2;
}
<div class="card">
<!--img src="img/card-bg1.jpg"-->
<img src="https://via.placeholder.com/550" />
<!-- I'm talking about this image -->
<!--img src="img/profile1.jpg"-->
<img src="https://via.placeholder.com/150" />
<h2>Jane Smith</h2>
<p>FrontEnd Developer</p>
<p>Esdsdsd.</p>
<button type="button">Message me!</button>
</div>
Why isn't it working?

The box shadow is properly applied also on the second image, but you are clipping it using the clip-path property
.card {
display: flex;
flex-flow: column wrap;
align-items: center;
}
.card img:nth-child(1) {
height: 220px;
width: 100%;
object-fit: cover;
box-shadow: 0px 10px 5px 0px rgba(0, 0, 0, 0.75);
}
.card img:nth-child(2) {
height: 150px;
width: 150px;
object-fit: cover;
border-radius: 50%;
border: 10px solid #fff;
box-shadow: 5px 0 10px rgba(0, 0, 0, .7);
margin-top: -40%;
z-index: 2;
}
<div class="card">
<img src="img/card-bg1.jpg">
<!-- I'm talking about this image -->
<!--img src="img/profile1.jpg"-->
<img src="https://via.placeholder.com/150" />
<h2>Jane Smith</h2>
<p>FrontEnd Developer</p>
<p>Esdsdsd.</p>
<button type="button">Message me!</button>
</div>

You need to wrap the image in a parent element set to the same size, and use filter: with drop-shadow(0px 10px 5px rgba(0, 0, 0, 0.75)); on the parent element to create the shadow effect that you want.
You can see the parent element I have added is a div with the class "img-wrap".
.card {
display: flex;
flex-flow: column wrap;
align-items: center;
}
.card img:nth-child(1) {
height: 220px;
width: 100%;
object-fit: cover;
box-shadow: 0px 10px 5px 0px rgba(0, 0, 0, 0.75);
clip-path: polygon(0 0, 100% 0, 100% 86%, 63% 100%, 28% 87%, 0 100%);
}
.img-wrap {
height: 220px;
width: 100%;
filter: drop-shadow(0px 10px 5px rgba(0, 0, 0, 0.75));
}
.card img:nth-child(2) {
height: 150px;
width: 150px;
object-fit: cover;
border-radius: 50%;
border: 10px solid #fff;
box-shadow: 5px 0 10px rgba(0, 0, 0, .7);
margin-top: -40%;
z-index: 2;
}
<div class="card">
<div class="img-wrap">
<img src="https://picsum.photos/id/237/200/300"> <!-- I'm talking about this image -->
</div>
<img src="https://picsum.photos/id/237/200/300">
<h2>Jane Smith</h2>
<p>FrontEnd Developer</p>
<p>Esdsdsd.</p>
<button type="button">Message me!</button>
</div>

You can't use box-shadow on that parent either, because the parent is still a rectangle and the shadow will look wrong.
.tag-wrap {
filter: drop-shadow(-1px 6px 3px rgba(50, 50, 0, 0.5));
}
.tag {
background: #FB8C00;
color: #222;
padding: 2rem 3rem 2rem 4rem;
font: bold 32px system-ui;
-webkit-clip-path: polygon(0 0, 100% 0, 100% 86%, 63% 100%, 28% 87%, 0 100%);
clip-path: polygon(0 0, 100% 0, 100% 86%, 63% 100%, 28% 87%, 0 100%);
}
<span class="tag-wrap">
<span class="tag">
drop-shadow
</span>
</span>

The problem is that clip-path is overriding box-shadow styles.
You then need to create a new parent and use the drox-shadow filter to it to retain the polygonal shape.
Please, have a look here for a clear presentation and solution of the problem.

Just remove clip-path: polygon(0 0, 100% 0, 100% 86%, 63% 100%, 28% 87%, 0 100%); from .card img:nth-child(1). If you need clip-path and box-shadow both together you need to add one parent class to clip-path and give that class filter: drop-shadow(0px 10px 5px 0px rgba(0, 0, 0, 0.75));
.card {
display: flex;
flex-flow: column wrap;
align-items: center;
}
.card-img:nth-child(1){
height: 220px;
width: 100%;
object-fit: cover;
filter: drop-shadow(-1px 6px 3px rgba(50, 50, 0, 0.5));
}
.card img:nth-child(1) {
height: 220px;
width: 100%;
object-fit: cover;
clip-path: polygon(0 0, 100% 0, 100% 86%, 63% 100%, 28% 87%, 0 100%);
}
.card img:nth-child(2) {
height: 150px;
width: 150px;
object-fit: cover;
border-radius: 50%;
border: 10px solid #fff;
box-shadow: 5px 0 10px rgba(0, 0, 0, .7);
margin-top: -40%;
z-index: 2;
}
<div class="card">
<div class="card-img">
<img src="img/card-bg1.jpg">
</div>
<!-- I'm talking about this image -->
<!--img src="img/profile1.jpg"-->
<div class="card-img">
<img src="https://via.placeholder.com/150" />
</div>
<h2>Jane Smith</h2>
<p>FrontEnd Developer</p>
<p>Esdsdsd.</p>
<button type="button">Message me!</button>
</div>

Related

How to make such a button

enter image description here
It needs to meet the following conditions
The button needs to have a slanted edge
Shadows on the bottom and right
Each corner has border-radius
The background color is gradient
The width of the button is dynamic
This is some data given by the designer
width: 128px;
height: 48px;
background: linear-gradient(317deg, #0099EE 0%, #0077EE 100%);
box-shadow: 0px 3px 0px 0px #0482CC, 0px 2px 4px 0px rgba(10, 127, 238, 0.3);
border-radius: 100px 4px 4px 100px;
width: 192px;
height: 48px;
background: linear-gradient(133deg, #FD7F5A 0%, #F53841 100%);
box-shadow: 0px 3px 0px 0px #C63A38, 0px 2px 4px 0px rgba(255, 71, 0, 0.3);
border-radius: 4px 100px 100px 4px;
You could use border-radius and clip-path together to cut of edges . grid can also help you to give an average ratio for each text portions .
here within a single button, what could be done :
button {
background:none;
border:none;
display:inline-grid;
grid-template-columns:1.5fr 2fr;
font-size:1.5em;
filter:drop-shadow(1px 1px 2px gray)
}
button span {
background:linear-gradient(to right,#0099EE,#0077EE);
padding:1em 3em;
color:white;
border-radius:1.5em 7px 1.5em 1.5em / 1.5em 1em 0.5em 1.5em;
clip-path: polygon(0 0, 100% 0%, calc( 100% - 1em) 100%, 0% 100%);
box-shadow:inset 0 -2px 1px 2px #0681D3;
}
button span + span {
margin-left:-0.75em;
clip-path: polygon(1em 0, 100% 0%, 100% 100%, 0% 100%);
border-radius:1.5em 1.5em 1.5em 7px / 0.5em 1.5em 1.5em 1em;
background:linear-gradient(to right,#FD7F5A, #F53841);
box-shadow:inset 0 -2px 1px 2px #CD3C30
}
<button><span>text 1</span><span> text 2 </span></button>
Use clip-path
#buttonA {
display: inline-flex;
align-items: center;
justify-content: center;
width: 150px;
height: 48px;
background: linear-gradient(317deg, #0099ee 0%, #0077ee 100%);
box-shadow: 0px 3px 0px 0px #0482cc, 0px 2px 4px 0px rgba(10, 127, 238, 0.3);
border-radius: 100px 4px 4px 100px;
clip-path: polygon(0 0, 100% 0, 85% 100%, 0% 100%);
}
#buttonB {
display: inline-flex;
align-items: center;
justify-content: center;
width: 200px;
height: 48px;
background: linear-gradient(133deg, #fd7f5a 0%, #f53841 100%);
box-shadow: 0px 3px 0px 0px #c63a38, 0px 2px 4px 0px rgba(255, 71, 0, 0.3);
border-radius: 4px 100px 100px 4px;
clip-path: polygon(10% 0, 100% 0, 100% 100%, 0% 100%);
}
<div>
<div id="buttonA">buttonA</div>
<div id="buttonB">buttonB</div>
</div>

Merge two div to have same linear-gradient and shadow

Hello partners!
I wanted to see if someone could advise me on how to do the following:
In a webapp that I am making I have a stylized NavBar as seen in the photos (in AdobeXD it is shown as a union of a rectangle with a circle).
Nav Example AdobeXD | Complete View
How could I make that navbar with HTML / CSS?
I already have the following but I have the problem of how to merge the div of the rectangle and the div of the circle in order to have the same shadow and the same linear gradient, it is possible to do that? 🥺 or would it be better to export that nav as SVG?
body{
margin: 0;
}
.navContainer{
width:100vw;
}
.mainNav{
width:100vw;
background: linear-gradient(#30355e 0%, #383e6e 100%);
box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.16);
height: 73px;
border-radius: 0 0 40px 40px;
filter: drop-shadow(0px 5px 8px rgba(0, 0, 0, 0.25));
}
.circleNav{
width:110px;
height:110px;
background: linear-gradient(#30355e 0%, #383e6e 100%);
border-radius: 50%;
position: absolute;
left: calc(50% - 57px);
top: 10px;
box-shadow: 0px 3px 6px rgba(0, 0, 0, 0.16);
}
<html>
<div class="navContainer">
<div class="mainNav">
</div>
<div class="circleNav">
</div>
</div>
</html>
You can do it like below:
body {
margin: 0;
}
.navContainer {
width: 100vw;
filter: drop-shadow(0px 5px 8px rgba(0, 0, 0, 0.45)); /* filter on main container */
}
.mainNav {
background:
linear-gradient(#30355e 0%, #383e6e 100%)
top/100% 110px; /* 110px = height of circle */
height: 75px;
border-radius: 0 0 40px 40px;
}
.circleNav {
width: 110px;
height: 110px;
background: linear-gradient(#30355e 0%, #383e6e 100%);
border-radius: 50%;
margin: -75px auto 0; /* same as height of nav */
}
<div class="navContainer">
<div class="mainNav">
</div>
<div class="circleNav">
</div>
</div>
Or with a reduced code like below:
body {
margin: 0;
}
.navContainer {
filter: drop-shadow(0px 5px 8px rgba(0, 0, 0, 0.45)); /* filter on main container */
height: 110px;
}
.navContainer::before,
.navContainer::after{
content:"";
position:absolute;
top:0;
height:100%;
border-radius: 50%;
background-image:linear-gradient(#30355e, #a3aae4);
}
.navContainer::before {
left:0;
right:0;
height:70%;
background-size:100% calc(100%/0.7);
background-position:top;
border-radius: 0 0 40px 40px;
}
.navContainer::after {
left:50%;
aspect-ratio:1/1; /* the support of this is low so you can replace it with width:110px */
transform:translate(-50%);
}
<div class="navContainer">
</div>

HTML/ CSS: placing section on right side of the screen using flexbox

I wonder how I can place the section class="teacher__section on the right side of the screen using flexbox. Not by float. I have written "justify-content: flex-end;", width 80% also 100% but it doesnt seem to be placing on right side.
I mean I have on the picture below succeeded placing the section on the right side, but the problem now is the left side where I want to get rid of the extra white box and the extra box-shadow. I want it to go around the image just like in
<section class="explore__section"> where I have the box-shadow go around the image. Source code is under below the image.
Source code:
.explore__container {
margin: 5% 0 2% 0;
display: flex;
width: 80%;
height: 10rem;
box-shadow: 1rem 1rem 1rem 1rem rgb(0, 0, 0, 0.2);
border-radius: 0rem 2rem 2rem 0;
}
.forkids__info {
flex-basis: 70%;
height: 100%;
background-color: bisque;
clip-path: polygon(0 0, 75% 0, 100% 100%, 0 100%);
margin-right: -20%;
}
.forkids__img {
background-image: url(/img/kids-science.jpeg);
flex-basis: 50%;
height: 100%;
clip-path: polygon(0 0, 100% 0%, 100% 100%, 25% 100%);
background-position: center;
background-size: cover;
background-repeat: no-repeat;
border-radius: 0rem 2rem 2rem 0;
}
.teacher__section {
display: flex;
justify-content: flex-end;
width: 100%;
height: 10rem;
box-shadow: 1rem 1rem 1rem 1rem rgb(0, 0, 0, 0.2);
border-radius: 0rem 2rem 2rem 0;
}
.teacher__container {
display: flex;
justify-content: flex-end;
width: 100%;
height: 10rem;
box-shadow: 1rem 1rem 1rem 1rem rgb(0, 0, 0, 0.2);
border-radius: 2rem 0 0 2rem;
}
.teacher__info {
flex-basis: 70%;
height: 100%;
background-color: bisque;
clip-path: polygon(25% 0, 100% 0, 100% 100%, 0 100%);
margin-left: -20%;
text-align: right;
font-size: 2rem;
}
.teacher__img {
background-image: url(/img/teacher-science.jpg);
flex-basis: 50%;
height: 100%;
clip-path: polygon(0 0, 100% 0, 75% 100%, 0 100%);
background-position: center;
background-size: cover;
background-repeat: no-repeat;
border-radius: 2rem 0 0 2rem;
}
<section class="explore__section">
<div class="explore__container">
<div class="forkids__info"> some text</div>
<div class="forkids__img"></div>
</div>
</section>
<section class="teacher__section">
<div class="teacher__container">
<div class="teacher__img"></div>
<div class="teacher__info">some text</div>
</div>
</section>
Try this solution, Hope this will help
<section class="explore__section">
<div class="explore__container">
<div class="forkids__info"> some text</div>
<div class="forkids__img"></div>
</div>
</section>
<section class="teacher__section">
<div class="teacher__container">
<div class="teacher__img"></div>
<div class="teacher__info">some text</div>
</div>
</section>
<style>
.explore__container {
margin: 5% 0 2% 0;
display: flex;
width: 80%;
height: 10rem;
box-shadow: 1rem 1rem 1rem 1rem rgb(0, 0, 0, 0.2);
border-radius: 0rem 2rem 2rem 0;
}
.forkids__info {
flex-basis: 70%;
height: 100%;
background-color: bisque;
clip-path: polygon(0 0, 75% 0, 100% 100%, 0 100%);
margin-right: -20%;
}
.forkids__img {
background-image: url(/img/kids-science.jpeg);
flex-basis: 50%;
height: 100%;
clip-path: polygon(0 0, 100% 0%, 100% 100%, 25% 100%);
background-position: center;
background-size: cover;
background-repeat: no-repeat;
border-radius: 0rem 2rem 2rem 0;
}
.teacher__section {
display: flex;
justify-content: flex-end;
width: 100%;
height: 10rem;
border-radius: 0rem 2rem 2rem 0;
}
.teacher__container {
display: flex;
justify-content: flex-end;
width: 80%;
height: 10rem;
box-shadow: 1rem 1rem 1rem 1rem rgb(0, 0, 0, 0.2);
border-radius: 2rem 0 0 2rem;
}
.teacher__info {
flex-basis: 70%;
height: 100%;
background-color: bisque;
clip-path: polygon(25% 0, 100% 0, 100% 100%, 0 100%);
margin-left: -20%;
text-align: right;
font-size: 2rem;
}
.teacher__img {
background-image: url(/img/teacher-science.jpg);
flex-basis: 50%;
height: 100%;
clip-path: polygon(0 0, 100% 0, 75% 100%, 0 100%);
background-position: center;
background-size: cover;
background-repeat: no-repeat;
border-radius: 2rem 0 0 2rem;
}
</style>

Cascading divs with triangles pointing downwards

What would be the easiest way to create the following (see image) with triangles at the bottom of the div.
I have tried using the css after method but get overlapping triangles. I am thinking the easiest way maybe to just create background images of the triangle on each div.
.triangle {
position: relative;
margin: 0;
padding: 1em;
box-sizing: border-box;
background: white;
box-shadow: 0px 3px 3px 0 rgba(0, 0, 0, 0.4);
}
.triangle::after{
content: "";
position: absolute;
width: 0;
height: 0px;
margin-left: -0.5em;
bottom: -2em;
left: 80%;
box-sizing: border-box;
border: 1em solid black;
border-color: transparent transparent white white;
transform-origin: 0 0;
transform: rotate(-45deg);
box-shadow: -3px 3px 3px 0 rgba(0, 0, 0, 0.4);
}
This seems a perfect job for clip-path:
.container {
padding:20px;
background:#dce2cc;
}
.box {
height:200px;
clip-path: polygon(0 0, calc(70% - 30px) 0, 70% 15%, calc(70% + 30px) 0, 100% 0, 100% 85%, calc(70% + 30px) 85%, 70% 100%, calc(70% - 30px) 85%, 0 85%);
background-color:red;
background-size:cover;
background-position:center;
}
.box:first-child {
clip-path: polygon(0 0, 100% 0, 100% 85%, calc(70% + 30px) 85%, 70% 100%, calc(70% - 30px) 85%, 0 85%);
}
.box:last-child {
clip-path: polygon(0 0, calc(70% - 30px) 0, 70% 15%, calc(70% + 30px) 0, 100% 0, 100% 100%,0 100%);
}
.box:not(:first-child) {
margin-top:-10px;
}
<div class="container">
<div class="box" style="background-image:url(https://picsum.photos/500/500?image=0)"></div>
<div class="box" style="background-image:url(https://picsum.photos/500/500?image=1069)"></div>
<div class="box" style="background-image:url(https://picsum.photos/500/500?image=1072)"></div>
<div class="box" style="background-image:url(https://picsum.photos/500/500?image=1052)"></div>
</div>
you can achieve this using css :after and :before see below working snippet
body{
background:rgb(220, 226, 204);
}
.arrow {
position: relative;
background: #fff;
height:100px;
margin-top:10px;
}
.arrow:after, .arrow:before {
top: 88%;
left: 80%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
z-index: 1;
filter: drop-shadow(0px 12px 0px rgb(220, 226, 204));
-webkit-filter: drop-shadow(0px 12px 0px rgb(220, 226, 204));
}
.arrow:after {
border-color: rgba(194, 225, 245, 0);
border-top-color: #fff;
border-width: 35px;
margin-left: -35px;
}
.arrow:before {
border-color: rgba(194, 225, 245, 0);
border-top-color: #fff;
border-width: 38px;
margin-left: -38px;
}
.arrow.no-arrow:after,.arrow.no-arrow:before{
display:none;
}
<div class="arrow">
content goes here
</div>
<div class="arrow">
content goes here
</div>
<div class="arrow no-arrow">
content goes here
</div>

How change the shape of div corners?

I am trying to achieve this shape of div to hold profile information.
So far I've curved one of the corners. However, I am having problems parallel lines.
My HTML:
<div class="profile-card">
<h1>Sector Specialist</h1>
<p>Frank ocean</p>
</div>
My CSS:
.profile-card{
margin-top:150px;
float:right;
background-color: rgba(0,0,0,0.4);
height:500px;
text-align:center;
padding: 50px 40px;
border: 2px solid red;
border-top-left-radius: 39px;
}
The codepen is https://codepen.io/anon/pen/wjMQmw
Thank you in advance.
I would consider a solution with pseudo-element with some skew transformation:
.profile-card {
background: rgba(0, 0, 0, 0.4);
width: 200px;
text-align: center;
padding: 50px 0 0 40px;
border-top-left-radius: 39px;
border-left: 1px solid red;
border-top: 1px solid red;
position: relative;
}
.profile-card:before {
content: "";
position: absolute;
right: -40px;
width: 40px;
top: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.4);
transform: skewY(45deg);
transform-origin: top left;
border-top: 1px solid red;
border-right: 1px solid red;
box-sizing:border-box;
}
.profile-card:after {
content: "";
position: absolute;
bottom: -40px;
height: 40px;
right: 0;
left: 0;
background: rgba(0, 0, 0, 0.4);
transform: skewX(45deg);
border-left: 1px solid red;
border-bottom: 1px solid red;
transform-origin: top left;
box-sizing:border-box;
}
body {
background:linear-gradient(to right,lightblue,pink)
}
<div class="profile-card">
<h1>Sector Specialist</h1>
<p>Frank ocean</p>
</div>
Without the border I would consider multiple gradient to achieve the layout:
.profile-card {
background:
linear-gradient(to bottom left,rgba(0, 0, 0, 0.4) 50%,transparent 51%)0 100%/50px 50px no-repeat,
linear-gradient(to top right,rgba(0, 0, 0, 0.4) 50%,transparent 51%)100% 0/50px 50px no-repeat,
linear-gradient(rgba(0, 0, 0, 0.4),rgba(0, 0, 0, 0.4))100% 100%/calc(100% - 50px) 50px no-repeat,
linear-gradient(rgba(0, 0, 0, 0.4),rgba(0, 0, 0, 0.4))0 0/calc(100% - 50px) 50px no-repeat,
linear-gradient(rgba(0, 0, 0, 0.4),rgba(0, 0, 0, 0.4))0 50px/100% calc(100% - 100px) no-repeat;
width: 200px;
text-align: center;
padding: 50px 40px;
border-top-left-radius: 39px;
}
<div class="profile-card">
<h1>Sector Specialist</h1>
<p>Frank ocean</p>
</div>
Or the clip-path solution:
.profile-card {
background:rgba(0, 0, 0, 0.4);
width: 200px;
text-align: center;
padding: 50px 40px;
border-top-left-radius: 39px;
-webkit-clip-path: polygon(1% 0%, 75% 1%, 100% 30%, 100% 100%, 21% 100%, 0% 74%);
clip-path: polygon(1% 0%, 75% 1%, 100% 30%, 100% 100%, 21% 100%, 0% 74%)
}
<div class="profile-card">
<h1>Sector Specialist</h1>
<p>Frank ocean</p>
</div>
For super complex bordering, one option is to use SVG. Here is an example of basic usage of polygon. SVG embedded into HTML can be styled using CSS easily:
body{
margin:0;
height: 500px;
background: url('https://cdn3.tropicalsky.co.uk/images/1280x720/downtown-dubai-aerial-view.jpg');
}
.profile-card{
margin-top:5px;
background-color: transparent;
height:800px;
width: 200px;
text-align:center;
padding: 50px 40px;
position: relative;
}
.profile-card h1, .profile-card p {
position: relative;
}
.frame {
position: absolute;
top: 20px;
left: 20px;
opacity: 0.7;
}
<div class="profile-card">
<svg class="frame" height="300" width="300">
<polygon points="50 0,250 0,300 50,300 300, 50 300, 0 250, 0 50,7.5 25, 15 15, 25 7.5" style="fill:lightgrey;stroke:orange;stroke-width:1" />
</svg>
<h1>Sector Specialist</h1>
<p>Frank ocean</p>
</div>