Is it possible to add a blur to only one side of a div using box-shadow?
What I am trying to achieve is a shadow with no width, just blur on only one side of a div. In my example I try to apply it to the bottom but the side really shouldn't matter.
I tried have using box-shadow: 0px 5px 5px -5px #000000; however using this method the shadow does not cover the whole length on the bottom of the div.
#bg {
text-align: center;
width: 200px;
height: 200px;
padding: 50px;
background: #eeeeee;
}
#box {
width: 100%;
height: 100%;
box-shadow: 0px 5px 5px -5px #000000;
background: yellow;
}
<div id="bg">
<div id="box"></div>
</div>
Only HTML and CSS solutions please.
You could use an after element and stretch it a little:
#bg {
text-align: center;
width: 200px;
height: 200px;
padding: 50px;
background: #eeeeee;
}
#box:after {
content:'';
display:block;
position:absolute;
z-index:0;
top:0;
left:-4px;
right:-4px;
bottom:0;
box-shadow: 0px 5px 5px -5px #000000;
}
#box {
width: 100%;
height: 100%;
position:relative;
background: yellow;
}
<div id="bg">
<div id="box"></div>
</div>
try this for bottom positioned box-shadow
.your_class {
box-shadow: 0 8px 6px -6px black;
}
You can also read https://developer.mozilla.org/en/docs/Web/CSS/box-shadow to understand how the box-shadow works
#bg {
text-align: center;
width: 200px;
height: 200px;
padding: 50px;
background: #eeeeee;
}
#box {
width: 100%;
height: 100%;
border-bottom: 2px solid #ccc;
background: yellow;
}
<div id="bg">
<div id="box"></div>
</div>
There is no readily available way to do precisely what you seek, at least not using a single box-shadow. Remember, the CSS box-shadow property accepts multiple comma-delimited entries, so this is your best bet if you're committed to using them. In the example below, I'm simply using two copies of the same box-shadow value with one difference: I've offset the first horizontally toward the left by 2.5px and the other toward the right by positive 2.5px. Additionally, I've added opacity to the color (due to mitigate the darkening effect of overlapping shadows).
#bg {
text-align: center;
width: 200px;
height: 200px;
padding: 50px;
background: #EEE;
}
#box {
width: 100%;
height: 100%;
box-shadow: -2.5px 5px 5px -3px rgba(0, 0, 0, 0.50),
2.5px 5px 5px -3px rgba(0, 0, 0, 0.5);
background-color: Yellow;
}
<div id="bg">
<div id="box"></div>
</div>
Try this
#bg {
text-align: center;
width: 200px;
height: 200px;
padding: 50px;
background: #eeeeee;
}
#box:after {
content:'';
display:block;
position:absolute;
z-index:0;
bottom:0px;
background-image: -webkit-gradient(
linear,
left top,
left bottom,
color-stop(0, #9C9C9C),
color-stop(0.22, #EEEEEE)
);
background-image: -o-linear-gradient(bottom, #9C9C9C 0%, #EEEEEE 22%);
background-image: -moz-linear-gradient(bottom, #9C9C9C 0%, #EEEEEE 22%);
background-image: -webkit-linear-gradient(bottom, #9C9C9C 0%, #EEEEEE 22%);
background-image: -ms-linear-gradient(bottom, #9C9C9C 0%, #EEEEEE 22%);
background-image: linear-gradient(to bottom, #9C9C9C 0%, #EEEEEE 22%);
height:10px;
width:100%;
}
#box {
width: 100%;
height: 100%;
position:relative;
background: yellow;
}
https://jsfiddle.net/Lfa4z5b4/
Related
I want to make a card look like this, the border or the sides of the card are semi-circular, is it possible to make it with css? if yes, how? Thank you in advance
.wrapper {
}
.content-card {
width: 315px;
height: 131px;
left: 0px;
top: 0px;
background: #FFFFFF;
box-shadow: 4px 8px 12px rgba(0, 0, 0, 0.12);
border-radius: 8px;
}
<div class="wrapper">
<div class="content-card">
</div>
</div>
Multiple background can do it:
.content-card {
width: 300px;
height: 150px;
background:
radial-gradient(8px at left ,#0000 98%,#fff) left ,
radial-gradient(8px at right,#0000 98%,#fff) right;
background-size: 50.5% 25px;
background-repeat:repeat-y;
filter: drop-shadow(4px 8px 12px rgba(0, 0, 0, 0.12));
border-radius: 8px;
}
body {
background: pink;
}
<div class="content-card">
</div>
The old way - border-image
It permits you to use the willing image for borders, it was widely use for this kind of cases. You can have repeat option on it to allow different box's sizes with the same style.
The mozilla doc is quite explicit with good examples of it : https://developer.mozilla.org/en-US/docs/Web/CSS/border-image
The recent way - without image
You have the possibility to use pseudo-element :after and :before and stylize those elements with a repeated background using radial-gradient.
body {
background-color: #ffaaaa;
}
.ticket {
position: relative;
width: 300px;
height: 170px;
margin: 10px;
border-radius: 10px;
background: white;
box-shadow: 4px 8px 12px rgba(0, 0, 0, 0.12);
}
.ticket:before,
.ticket:after {
content: '';
position: absolute;
top: 5px;
width: 6px;
height: 160px;
}
.ticket:before {
left: -5px;
background: radial-gradient(circle, transparent, transparent 50%, #FBFBFB 50%, #FBFBFB 100%) -7px -8px/16px 16px repeat-y;
}
.ticket:after {
left: 300px;
background: radial-gradient(circle, transparent, transparent 50%, #FBFBFB 0%, #FBFBFB 100% ) -3px -7px / 16px 16px repeat-y;
}
<div class="ticket"></div>
I'm trying to create a background for a banner using css where one side has a color and on the other side has another one with a 45° cut like this
I've been able to recreate the above image except for the drop shadow that doesn't stay in the right position.
Any advice would be greatly appreciated.
This is my code code:
#container {
height: 100px;
width: 400px;
overflow: hidden;
background-color: #2962ff;
}
#triangle-topleft {
width: 0;
height: 0;
border-top: 100px solid #2196f3;
border-right: 400px solid transparent;
-webkit-box-shadow: 5px 5px 20px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 5px 5px 20px 0px rgba(0,0,0,0.75);
box-shadow: 5px 5px 20px 0px rgba(0,0,0,0.75);
}
<div id="container">
<div id="triangle-topleft"></div>
</div>
The CSS triangle trick with border can not be used for this, as a shadow will still be applied to the box, and not only to the triangle.
You will have to create a pseudo element, rotate it and THEN apply shadow to it.
#container {
position: relative;
height: 200px;
width: 200px;
overflow: hidden;
background-color: grey;
}
#container:before {
content: '';
position: absolute;
left: 20%;
width: 100%;
height: 200%;
background-color: rgb(255, 255, 255); /* fallback */
background-color: rgba(255, 255, 255, 0.5);
top: 0;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
transform: rotate(45deg);
box-shadow: inset 0 0 20px 10px #333;
}
<div id="container"></div>
Basically you create a rectangle which is larger than the parent, then rotate it and apply a shadow. You can tweak the colors and rotation-degree for your needs
Demo: http://jsfiddle.net/b5TnZ/2032/
You can add multiple color stops in Linear Gradients. Use two color set.
Gradient generated using Shapy
.canvas {
display: flex;
height: 100vh;
align-items: center;
justify-content: center;
min-height: 100%;
min-width: 100%;
}
.gradient-canvas {
max-height: 100%;
max-width: 100%;
width: 100%;
height: 100%;
background: linear-gradient(127deg, rgb(31, 163, 209) 0%, rgb(31, 163, 209) 50%, rgb(25, 64, 208) 0%, rgb(46, 101, 223) 52%) 50% 50% / 100% 100% no-repeat;
}
<div class="canvas"><div class="gradient-canvas"></div></div>
You can try gradient like below:
#container {
height: 150px;
background:
linear-gradient(135deg,#2962ff 49.8%,rgba(0,0,0,0.75) 50%, #2196f3 calc(50% + 10px));
background-color:#2196f3;
}
<div id="container">
</div>
And simply replace the deg with to bottom right if you want the diagonal result:
#container {
height: 150px;
width:50%;
background:
linear-gradient(to bottom right,#2962ff 50%,rgba(0,0,0,0.75) 50%, #2196f3 calc(50% + 10px));
background-color:#2196f3;
}
<div id="container">
</div>
I don't know if this is duplicated or not, but I searched but couldn't find anything.
I'm trying to do a div with a half circle in the middle of the top border like the picture bellow:
Th black square is a div (intended to be a modal) and in the middle the border is cut with a circle. The red part is the page background (can be anything... images, text...).
How can I do this in html/css? I'm trying to avoid images to do this!!
Thank you
You can try this...
body{
background-color:#333;
passing:0px;
height:0px;
}
#app{
background:#333 url('https://source.unsplash.com/random') no-repeat;
background-size:cover;
width:360px;
height:560px;
position:relative;
overflow:hidden;
}
.app-bar{
width:100%;
height:50px;
position:absolute;
bottom:0px;
left:0;
}
.app-bar .bar{
line-height:50px;
position:relative;
width:100%;
height:50px;
background-image: radial-gradient(circle 35px at 315px 0, transparent 700px, #f44336 50px);
}
.app-bar .bar i{
color:#FFF;
display:block;
line-height:50px;
float:left;
width:50px;
text-align:center;
cursor:pointer;
margin-top:0px;
}
.app-bar .bar i:hover{
background-color:rgba(0,0,0,.1);
}
.app-bar .bar button{
padding:0px;
box-sizing:border;
text-align:center;
margin:0px;
bordeR:0px;
outline:0px;
width:60px;
height:60px;
line-height:60px;
cursor:pointer;
color:#FFFFFF;
display:block;
border-radius:50%;
position:absolute;
top:-30px;
left:100%;
margin-left:-75px;
background-color:#f44336;
transition: all .2s ease;
}
.app-bar .bar button span{
line-height:60px;
font-size:30px;
}
.app-bar .bar button:hover{
transform:rotate(45deg);
transition: all .2s ease;
}
<div id="app">
<div class="app-bar">
<div class="bar">
<i class="material-icons">menu</i>
<i class="material-icons">search</i>
<button class="button">
<span class="material-icons">add</span>
</button>
</div>
</div>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/material-design-icons/3.0.1/iconfont/material-icons.min.css" >
One way of doing it:
* {margin: 0; padding: 0; box-sizing: border-box}
html, body {height: 100%}
body {
display: flex;
justify-content: center;
align-items: center;
background: #f00;
}
.black {
display: flex;
justify-content: center;
width: 200px;
height: 200px;
background: #000;
}
.white {
position: relative;
top: -25px;
width: 50px;
height: 50px;
border: 2px solid #f00;
border-radius: 50%;
background: #fff;
}
<div class="black">
<div class="white"></div>
</div>
And the "starter kit" solution you'd like to have:
* {margin: 0; padding: 0; box-sizing: border-box}
html, body {height: 100%}
body {
display: flex;
justify-content: center;
align-items: center;
background: linear-gradient(to bottom left, Navy, Tomato, Skyblue);
background-repeat: no-repeat;
background-attachment: fixed;
}
.outer {
display: flex;
flex-direction: column;
justify-content: space-evenly;
align-items: center;
width: 275px;
height: 550px;
background: linear-gradient(Navy 33.33%, Tomato 66.66%, Skyblue 100%);
box-shadow: 0 15px 15px #000;
}
.outer > span {color:#fff}
.outer > .inner {
display: flex;
flex-direction: column;
justify-content: space-evenly;
align-items: center;
position: relative;
padding-top: 20px;
width: 225px;
height: 275px;
border-radius: 5px;
background: #fff;
box-shadow: 0 10px 10px #000;
}
.outer > .inner > #user {
display: block;
position: absolute;
top: -35px;
width: 70px;
height: 70px;
border: 2px solid #fff;
border-radius: 50%;
background: Navy;
box-shadow: 0 0 0 10px Navy;
}
.outer > .inner > input[type=text],
.outer > .inner > #sign_in {
width: 80%;
padding: 5px;
}
.outer > .inner > #sign_in {
display: block;
padding: 10px 0;
color: #fff;
text-align: center;
text-decoration: none;
text-shadow: 1px 1px 1px #000;
background: Tomato;
box-shadow: 0 5px 5px #000;
}
<div class="outer">
<span>My Account</span>
<div class="inner">
<img src="http://www.ecovadis.com/wp-content/themes/ecovadis/images/Icon-user.png" alt="User" id="user">
<input type="text" placeholder="Username">
<input type="text" placeholder="Password">
Sign in
</div>
<span></span> <!-- just to make things easier -->
</div>
You can go on from here.
Thank you for all the help.
For my problem I found a solution in this post
here
and I adapted.
So for anyone that needs also the solution:
#wrapper {
width: 500px;
height:400px;
background: transparent;
border: 0;
/* Define half of half semi-cicle on the top for all */
background:
radial-gradient(circle at 0 100%, transparent 0, yellow 0) bottom left,
radial-gradient(circle at 100% 100%, transparent 0, yellow 0) bottom right,
radial-gradient(circle at 0 0, transparent 25%, yellow 15px) top right,
radial-gradient(circle at 100% 0, transparent 25%, yellow 15px) top left;
/*Define top half of half circle background for specific Safari 5.1- 6.0*/
background:
-webkit-radial-gradient(circle at 0 100%, transparent 0, yellow 0) bottom left,
-webkit-radial-gradient(circle at 100% 100%, transparent 0, yellow 0) bottom right,
-webkit-radial-gradient(circle at 0 0, transparent 25%, yellow 15px) top right,
-webkit-radial-gradient(circle at 100% 0, transparent 25%, yellow 15px) top left;
/*Define top half of half circle background for specific Opera 11.6-12.0*/
background:
-o-radial-gradient(circle at 0 100%, transparent 0, yellow 0) bottom left,
-o-radial-gradient(circle at 100% 100%, transparent 0, yellow 0) bottom right,
-o-radial-gradient(circle at 0 0, transparent 25%, yellow 15px) top right,
-o-radial-gradient(circle at 100% 0, transparent 25%, yellow 15px) top left;
/*Define top half of half circle background for specific Firefox 3.6-15*/
background:
-moz-radial-gradient(circle at 0 100%, transparent 0, yellow 0) bottom left,
-moz-radial-gradient(circle at 100% 100%, transparent 0, yellow 0) bottom right,
-moz-radial-gradient(circle at 0 0, transparent 25%, yellow 15px) top right,
-moz-radial-gradient(circle at 100% 0, transparent 25%, yellow 15px) top left;
/*repeat half of half circle*/
background-size: 51% 51%;
background-repeat: no-repeat;
border: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#content{
padding-top: 25%;
word-wrap: break-word;
}
<div id="wrapper" class="half-circle">
<div id="content">asdasdasdasdasdasdasdasdasdasdasdasdasdasdsdasdasdasdasdasdasdasdasdasdasdasdasdasdassdasdadasasdasdasdasdasd</div>
</div>
Below is the image I am trying for, I managed to get a square using CSS, but I am trying for horizontal and vertical line in a square.
.hub{
width: 119px;
height: 101px;
background: #b5adad;
}
<div class="hub"></div>
There are many ways to do this and one would be to use gradients like below: (the image in question was actually a rectangle.)
The approach is very simple - we use 2 linear gradients to create two thin solid colored lines and then position the images such that they match our needs. Linear gradients are used even though it creates only a solid color because it is easier to control size and position of an image than background color.
div {
height: 100px;
width: 200px;
border: 1px solid red;
background-image: linear-gradient(to bottom, red, red), linear-gradient(to right, red, red);
background-repeat: no-repeat;
background-size: 1px 100%, 100% 1px;
background-position: 20px 0px, 0px 10px;
}
<div></div>
We can also create an output which has a fade-out or shadow effect like in the image in question:
div {
height: 100px;
width: 200px;
border: 1px solid;
background-color: gray;
background-image: linear-gradient(to bottom, black, black), linear-gradient(to right, red, transparent), linear-gradient(to right, black, black), linear-gradient(to bottom, red, transparent);
background-repeat: no-repeat;
background-size: 1px 100%, 1px 100%, 100% 1px, 100% 1px;
background-position: 20px 0px, 21px 0px, 0px 10px, 0px 11px;
box-shadow: inset 0px 0px 3px red;
}
<div></div>
Another way is to use :before and :after pseudo-elements:
.hub{
width: 119px;
height: 101px;
background: #b5adad;
position: relative;
padding: 18px 0 0 18px;
}
.hub:after, .hub:before {
content: " ";
background: black;
display: block;
position: absolute;
}
.hub:after {
width: 1px;
height: 100%;
left: 15px;
top: 0;
}
.hub:before {
width: 100%;
height: 1px;
top: 15px;
left: 0;
}
<div class="hub">Lorem ipsum dolor amet</div>
I want to create a button bar on top of the page, with div containers that contain images to use them as flat button. My problem is that I cannot get the alignment correctly.
Is there an additional way to highlight the last clicked button, so that you can see which button on the buttonbar is active without using javascript?
Here is my first approach:
<html>
<head>
<title>
</title>
<style>
#top {
position: fixed;
background-color: #AAA;
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#fff), to(transparent));
background-image: -webkit-linear-gradient(top, #fff, transparent);
background-image: -moz-linear-gradient(top, #fff, transparent);
background-image: -o-linear-gradient(top, #fff, transparent);
background-image: linear-gradient(to bottom, #fff, transparent);
left: 0px;
top: 0px;
width: 100%;
height: 60px;
padding: 0px;
border: thin solid rgba(0,0,0,0.6);
color: #444444;
font-family: Droid sans, Arial, Helvetica, sans-serif;
font-size: 12px;
cursor: pointer;
-webkit-box-shadow: rgba(0,0,0,0.5) 3px 3px 10px;
-moz-box-shadow: rgba(0,0,0,0.5) 3px 3px 10px;
box-shadow: rgba(0,0,0,0.5) 3px 3px 10px;
}
.flatBtn2 {
height: 50px;
width: 50px;
margin-left: 5px;
margin-top: 5px;
float: left;
display: inline;
}
.flatBtn2:hover {
background-color: #eee;
height: 50px;
width: 50px;
margin-left: 5px;
margin-top: 5px;
float: left;
display: inline;
}
.buttonBar {
float:left;
}
</style>
</head>
<body>
<div id="top">
<div id="selectReiter" style="display:inline" class="buttonBar">
<div id="firstButton" class="flatBtn2" />
<div id="secondButton" class="flatBtn2" />
<div id="thirdButton" class="flatBtn2" />
</div>
</div>
</body>
</html>
#top {
position: fixed;
background-color: #AAA;
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#fff), to(transparent));
background-image: -webkit-linear-gradient(top, #fff, transparent);
background-image: -moz-linear-gradient(top, #fff, transparent);
background-image: -o-linear-gradient(top, #fff, transparent);
background-image: linear-gradient(to bottom, #fff, transparent);
left: 0px;
top: 0px;
width: 100%;
height: 60px;
padding: 0px;
border: thin solid rgba(0, 0, 0, 0.6);
color: #444444;
font-family: Droid sans, Arial, Helvetica, sans-serif;
font-size: 12px;
cursor: pointer;
-webkit-box-shadow: rgba(0, 0, 0, 0.5) 3px 3px 10px;
-moz-box-shadow: rgba(0, 0, 0, 0.5) 3px 3px 10px;
box-shadow: rgba(0, 0, 0, 0.5) 3px 3px 10px;
}
.flatBtn2 {
height: 50px;
width: 50px;
margin-left: 5px;
margin-top: 5px;
float: left;
display: inline;
background-color: transparent;
border: none;
}
.flatBtn2:hover {
background-color: #eee;
height: 50px;
width: 50px;
margin-left: 5px;
margin-top: 5px;
float: left;
display: inline;
}
.flatBtn2:focus {
background-color: #eee;
}
.buttonBar {
float: left;
}
<div id="top">
<div id="selectReiter" style="display:inline" class="buttonBar">
<button id="firstButton" class="flatBtn2" >Button 1</button>
<button id="secondButton" class="flatBtn2" >Button 2</button>
<a id="thirdButton" href="#" class="flatBtn2">A 3</a>
</div>
</div>
First of all if you want to use button, then you should you the <button> tag and add the background image through css. You can also manipulate the states in css, what you are seacrhing for is :focus and :active, so you have two rules for your buttons. The normal button rule with the main background-image and an other rule button:focus, button:active where you can load an other image or do something else.
See fiddle for a working example. I added the needed styles at the end of your css.
Hope this helps!