I am trying to make slanted box shadow on both sides of a div, which I have added here as an image.
The red part is indicating here shadow. actually color is not solid, it should gradually decrease when it is moving to outside from border.
Here is my contribution hope it gives you a baseline.
.box {
width: 150px;
height: 200px;
position: relative;
padding-left: 25px;
padding-right: 25px;
}
.box-content {
display: flex;
align-items: center;
justify-content: center;
z-index: 2;
background-color: white;
border: 2px solid black;
width: 100%;
height: 100%;
position: relative;
}
.box::before {
content: '';
display: block;
border-top: 0;
border-bottom: 180px solid transparent;
border-right: 25px solid red;
position: absolute;
left: 0;
bottom: 0;
}
.box::after {
content: '';
display: block;
border-top: 0;
border-bottom: 180px solid transparent;
border-left: 25px solid red;
position: absolute;
right: -4px;
bottom: 0;
}
<div class="box">
<div class="box-content">
Box
</div>
</div>
Try this:
div{
width: 200px;
height: 200px;
border:1px solid black;
background: white;
}
div:before{
content:' ';
display:block;
width: 200px;
height:200px;
background: linear-gradient(transparent, black);
position: fixed;
transform: matrix3d(1.1,0,0.00,0,0.00,0.71,0.71,0.0007,0,-0.71,0.71,0,0,37,0,1); z-index: -1;
}
<div>Hello</div>
Using transform: skew() applied to the div's before and after
jsFiddle 1
code:
#test {
width: 150px;
height: 220px;
line-height: 220px;
background-color: white;
border: 2px black solid;
text-align: center;
position: relative;
margin: 10px 150px;
}
#test:before, #test:after {
width: 150px;
height: 200px;
position: absolute;
bottom: 0;
left: -11px;
z-index: -1;
content: " ";
display: block;
background-color: red;
transform: skew(5deg, 0);
}
#test:after {
transform: skew(-5deg, 0);
left: 11px;
}
<div id="test">Box</div>
EDIT : to give the shadow effect some real blur with gradient and transparency, we could make use of linear-gradient background with two rgba() values, as well as CSS blur() (1) filter.
jsFiddle 2
code:
#test {
width: 150px;
height: 220px;
line-height: 220px;
background-color: white;
border: 2px black solid;
text-align: center;
position: relative;
margin: 10px 150px;
}
#test:before, #test:after {
width: 150px;
height: 200px;
position: absolute;
bottom: 0;
left: -11px;
z-index: -1;
content: " ";
display: block;
background: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.7));
transform: skew(5deg, 0);
filter: blur(2px);
}
#test:after {
transform: skew(-5deg, 0);
left: 11px;
}
<div id="test">Box</div>
Notes:
(1) browser support for CSS filter
Related
This question already has answers here:
Transparent arrow/triangle indented over an image
(4 answers)
Closed 2 years ago.
I want to change the button on my website.
like this.
But I don't know how to change the bottom style of this button.
I heard we can do this using '::after' or '::before'.
Something like this is one of the 100 options
.my-special-thing {
position: relative;
padding: 20px 30px;
background-color: orange;
display: inline-block;
}
.my-special-thing:before {
position: absolute;
right: 30px;
bottom: -10px;
width: 20px;
height: 20px;
content: '';
display: block;
background-color: white;
transform: rotate(45deg);
}
<div class="my-special-thing">Post a job</div>
Yes , this can be achieved using before & after , please check the code below
.Box {
width: 200px;
height: 50px;
background-color: #F7E6D2;
display:flex;
justify-content: center;
align-items:center;
}
.Box::before {
bottom: 0;
left: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-color: rgba(0, 0, 0, 0);
border-bottom-color: #F4F4F5;
border-width: 11px;
margin-left: -11px;
}
.Box::after{
bottom: 0;
left: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-color: rgba(255, 255, 255, 0);
border-bottom-color: #ffffff;
border-width: 10px;
margin-left: -10px;
}
<section id="Items">
<div class="Box">
<h3>Case</h3>
</div>
</section>
I want to place my nav in 4 different places. Top, Right, Bottom, And middle. But I cant seem to get it to work. And when i for example mean Right, it should still be in the center of top and bottom. I donät know if you understand but i don't really know how to describe it better.
#navOne {
display: block;
text-align: center;
padding-top: 1em;
}
#navTwo {
display: block;
position: relative;
float: right;
margin-top: 43vh;
transform: rotate(90deg);
}
#navThree {
display: block;
position: absolute;
text-align: center;
margin-left: 50%;
transform: translateX(-50%);
margin-top: 86vh;
}
#navFour {
display: block;
position: relative;
transform: rotate(-90deg);
float: left;
margin-top: 42vh;
margin-left: 0.5em;
}
<p id="navOne" class="navs">About me</p>
<p id="navTwo" class="navs">Portfolio</p>
<p id="navThree" class="navs">Skills</p>
<p id="navFour" class="navs">Contact</p>
I add the following CSS and Found that none of your link is perfectly centered! here is the code:
body {
margin: 0;
padding: 0;
}
.box {
height: 50vh;
width: 100vw;
position: absolute;
border: 1px solid red;
top: 0;
box-sizing: border-box;
}
.box.two {
height: 100vh;
width: 50vw;
position: absolute;
border: 1px solid rgb(255, 0, 64);
top: 0;
}
a {
outline: 1px solid green;
}
The image is the outcome of my code which you see. So I'm rewriting the code for you.
body {
margin: 0;
padding: 0;
}
.navs {
text-align: center;
margin: 0;
}
.navtop {
margin-top: 15px;
}
.navright {
position: absolute;
top: 50%;
right: 0;
transform: translateY(-50%) rotate(90deg);
}
.navbottom {
position: absolute;
bottom: 0;
left: 0;
right: 0;
margin-bottom: 15px;
}
.navleft {
position: absolute;
top: 50%;
left: 0;
transform: translateY(-50%) rotate(-90deg);
}
/* below code is for checking every thing is perfectly centered*/
.box {
height: 50vh;
width: 100vw;
position: absolute;
border: 1px solid red;
top: 0;
box-sizing: border-box;
}
.box.two {
height: 100vh;
width: 50vw;
position: absolute;
border: 1px solid rgb(255, 0, 64);
top: 0;
}
a {
outline: 1px solid green;
}
<p id="navOne" class="navs navtop">About me</p>
<p id="navTwo" class="navs navright">Portfolio</p>
<p id="navThree" class="navs navbottom">Skills</p>
<p id="navFour" class="navs navleft">Contact</p>
<!-- below html is for testing purpose -->
<div class="box"></div>
<div class="box two "></div>
I am trying to create a ribbon at the beginning of a rectangle. However, I cannot figure out how to make it appear BEHIND the rectangle.
Please see this codepen: http://codepen.io/gosusheep/pen/aOqOBy
The part for creating the ribbon and putting it behind the rectangle is here:
.rectangle::before{
content: "";
width: 0;
height: 0;
display: block;
position: absolute;
z-index: -1;
border-left: 25px solid transparent;
border-right: 25px solid $blue;
border-top: 25px solid $blue;
border-bottom: 25px solid $blue;
left: -30px;
top: 10%;
}
Even with position: absolute, and z-index: -1, it appears ON TOP of the div.
Can anyone help with this?
What is happening here is that apparently, the property transform: translateX(-50%); it's "overriding" in some way the z-index. My solution is just center rectangle otherwise, for example:
.rectangle{
margin: 0 auto;
}
DEMO
The reason for your problem is not because children cannot be positioned behind their parent but because you are using a transform on the parent. Using transforms affect the stacking context like mentioned in this answer by BoltClock.
One solution would be to avoid the transform totally and use left: calc(50% - 100px) instead to position the ribbon at the center (like in the below snippet). (50% - 100px) is used as the value because 100px is half of the box width (50% is the center point of the parent).
.rectangle {
width: 200px;
height: 50px;
background-color: #8080ff;
position: relative;
left: calc(50% - 100px); /* newly added */
border: 1px #6666ff solid;
}
ul {
list-style: none;
}
li {
display: inline;
}
li + li::before {
content: " | ";
}
.container {
width: 100%;
position: relative;
}
.rectangle {
width: 200px;
height: 50px;
background-color: #8080ff;
position: relative;
left: calc(50% - 100px); /* newly added */
border: 1px #6666ff solid;
}
.rectangle::before {
content: "";
width: 0;
height: 0;
display: block;
position: absolute;
z-index: -1;
border-left: 25px solid transparent;
border-right: 25px solid #8080ff;
border-top: 25px solid #8080ff;
border-bottom: 25px solid #8080ff;
left: -30px;
top: 10%;
}
<p>put a pipe between nav elements</p>
<nav>
<ul>
<li>banana</li>
<li>woof</li>
<li>quack</li>
</ul>
</nav>
<p>Ribbon on the end of a rectangle</p>
<div class='container'>
<div class='rectangle'></div>
</div>
If in case you can't use the above solution, then you could follow the approach described below.
Assuming you don't have any other use for the ::after pseudo-element, you could use that to create the rectangle and give it a z-index higher than the ::before pseudo-element to make it appear behind the rectangle.
/* Modified */
.rectangle {
width: 200px;
height: 50px;
position: relative;
left: 50%;
transform: translateX(-50%);
}
/* Added */
.rectangle::after {
content: "";
width: 100%;
height: 100%;
top: 0px;
left: 0px;
display: block;
position: absolute;
background-color: #8080ff;
border: 1px #6666ff solid;
z-index: -1;
}
.rectangle{
padding: 4px;
box-sizing: border-box;
}
Below is a sample snippet:
ul {
list-style: none;
}
li {
display: inline;
}
li + li::before {
content: " | ";
}
.container {
width: 100%;
position: relative;
}
.rectangle::before {
content: "";
width: 0;
height: 0;
display: block;
position: absolute;
z-index: -2;
border-left: 25px solid transparent;
border-right: 25px solid #8080ff;
border-top: 25px solid #8080ff;
border-bottom: 25px solid #8080ff;
left: -30px;
top: 10%;
}
/* Modified */
.rectangle {
width: 200px;
height: 50px;
position: relative;
left: 50%;
transform: translateX(-50%);
}
/* Added */
.rectangle::after {
content: "";
width: 100%;
height: 100%;
top: 0px;
left: 0px;
display: block;
position: absolute;
background-color: #8080ff;
border: 1px #6666ff solid;
z-index: -1;
}
.rectangle{
padding: 4px;
box-sizing: border-box;
}
<p>put a pipe between nav elements</p>
<nav>
<ul>
<li>banana</li>
<li>woof</li>
<li>quack</li>
</ul>
</nav>
<p>Ribbon on the end of a rectangle</p>
<div class='container'>
<div class='rectangle'>
Some content
</div>
</div>
Solution here, look closely at z-indexes and positions
.container{
position: relative;
width: 100%;
z-index: 1;
}
.rectangle{
width: 200px;
height: 50px;
background-color: $blue;
position: absolute;
left: 50%;
border: 1px darken($blue,5%) solid;
}
.rectangle::after{
content: "";
width: 0;
height: 0;
border-left: 25px solid transparent;
border-right: 25px solid $blue;
border-top: 25px solid $blue;
border-bottom: 25px solid $blue;
left: -30px;
top: 10px;
position: absolute;
z-index: -1;
}
And your codepen edited http://codepen.io/anon/pen/mJXeed working now
I was trying to customize ionic lists and tabs but since I am not too experienced in css does anyone know how to get these layouts ? :
List picture:
TABS picture:
You could use a border trick with some pseudo elements for this:
.onecorner,
.twocorners {
height: 50px;
width: 300px;
line-height: 50px;
text-align: center;
background: lightgray;
margin-left: 25px;
margin-right: 25px;
position: relative;
}
.onecorner:after{
content: "";
position: absolute;
top: 0;
left: 100%;
height:100%;
width:25px;
background:inherit;
}
.onecorner:before,
.twocorners:before {
content: "";
position: absolute;
top: 0;
left: 0;
transform: translateX(-100%);
width: 0;
height: 25px;
border-top: 25px solid transparent;
border-right: 25px solid lightgray;
}
.twocorners:after {
content: "";
position: absolute;
top: 0;
right: 0;
transform: translateX(100%);
width: 0;
height: 25px;
border-bottom: 25px solid transparent;
border-left: 25px solid lightgray;
}
<div class="onecorner">tab 1</div>
<br/>
<div class="twocorners">tab 2</div>
I have two boxes one on top and one on left.
I'm using :after attribute to add line (border) after div.
First thing I want to do is to "join" both red borders.Right now there is empty gap between them, but if I change #toolbar::after left to '15px' I get that unwanted green line between red lines - can this be fixed?
Another thing is hovering over sidebar. After I move mouse cursor over sidebar it is moving to left:0, but border around toolbar isn't moving. Can I modify toolbar border after I hover over sidebar?
Below is sample code that illustrates my problem
html {
background: #e6e6e6;
}
#sidebar, #toolbar {
position: fixed;
top: 0;
left: 0;
}
#toolbar {
z-index: 102;
height: 50px;
right: 0;
text-shadow: 0 -1px 0 #000000;
background: #222222;
}
#sidebar {
z-index: 103;
bottom: 0;
width: 80px;
margin-top: 50px;
background: black;
left: -60px;
transition: all 0.2s ease;
transform: translateZ(0);
}
#sidebar:hover {
left: 0;
}
#sidebar::after {
content:'';
bottom: 0;
width: 4px;
position: absolute;
right: 0px;
top: 0;
display: block;
border-right: 1px solid green;
background: red;
-webkit-box-sizing: initial;
;
}
#toolbar::after {
content:'';
right: 0;
height: 4px;
position: absolute;
left: 20px;
bottom: 0;
display: block;
border-bottom: 1px solid green;
background: red;
-webkit-box-sizing: initial;
;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<div id="toolbar"></div>
<div id="sidebar"></div>
You can use box-shadow instead of a border box-shadow: 5px 1px 0px 0px green;
Note :- I have changed the html structure for the pseudo element to move to left when hovered on sidebar
html {
background: #e6e6e6;
}
#sidebar,
#toolbar {
position: fixed;
top: 0;
left: 0;
}
#toolbar {
z-index: 102;
height: 50px;
right: 0;
text-shadow: 0 -1px 0 #000000;
background: #222222;
}
#sidebar {
z-index: 103;
bottom: 0;
width: 80px;
margin-top: 50px;
background: black;
left: -60px;
transition: all 0.2s ease;
transform: translateZ(0);
}
#sidebar:hover {
left: 0;
}
#sidebar::after {
content: '';
bottom: 0;
width: 4px;
position: absolute;
right: 0px;
top: 0;
display: block;
border-right: 1px solid green;
background: red;
-webkit-box-sizing: initial;
;
}
#toolbar::after {
content: '';
right: 0;
height: 4px;
position: absolute;
left: 15px;
bottom: 0;
display: block;
background: red;
-webkit-box-sizing: initial;
box-shadow: 5px 1px 0px 0px green;
transition: all 0.2s ease;
}
#sidebar:hover + #toolbar::after {
left: 75px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
<div id="sidebar"></div>
<div id="toolbar"></div>