I'm not an expert with CSS and I'm gonna be struggled in order to achieve the following shape for my div:
And then I would like to insert text in the center.
How can I obtain this shape ?
Below here, some my attempts:
<div class="triangle-down-white" style="height:400px;">
try
</div>
and css
.triangle-down-white {
width: 100%;
height: 0;
padding-left:50%;
padding-top: 4%;
overflow: hidden;
background: rgba(140, 140, 140, 0.33);
}
.triangle-down-white:before,
.triangle-down-white:after {
content: "";
display: block;
height: 122px;
width: 122px;
margin-left:-1000px;
border-left: 1000px solid transparent;
border-right: 1000px solid transparent;
border-top: 100px solid rgba(140, 140, 140, 0.33);
}
.triangle-down-white:before
{ /* hide arrow tails background */
border-top: 100px solid white;
}
UPDATE
I added the new style chevron but the text appear behind the div. I'm using bootstrap and the html code is the following:
<div class="row">
<div class="col-sm-12" id="chevron">
<p>asdasdasdasasdaasdsadasadsadsasd</p>
</div>
</div>
The rest of the code is completely the standard one for bootstrap.
SOLVED
I added z-index: -1 at the new element.
Taken from this website here is the chevron shape you desire:
#chevron {
position: relative;
text-align: center;
padding: 12px;
margin-bottom: 6px;
height: 60px;
width: 200px;
}
#chevron:before {
content: '';
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 51%;
background: red;
-webkit-transform: skew(0deg, 6deg);
-moz-transform: skew(0deg, 6deg);
-ms-transform: skew(0deg, 6deg);
-o-transform: skew(0deg, 6deg);
transform: skew(0deg, 6deg);
}
#chevron:after {
content: '';
position: absolute;
top: 0;
right: 0;
height: 100%;
width: 50%;
background: red;
-webkit-transform: skew(0deg, -6deg);
-moz-transform: skew(0deg, -6deg);
-ms-transform: skew(0deg, -6deg);
-o-transform: skew(0deg, -6deg);
transform: skew(0deg, -6deg);
}
p{
position: relative;
z-index: 1;
}
<div id="chevron"><p>Hello</p></div>
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
View Image
Look at the shadow at the bottom of the above popup how do I get this type of shadow
body{
background: rgba(135,206,250, 0.5);
}
.card {
width: 500px;
height: 250px;
background: white;
}
<div class="card">
</div>
body{
background: rgba(135,206,250, 0.5);
}
.card {
width: 500px;
height: 250px;
background: white;
}
.shadow
{
position: relative;
}
.shadow:before, .shadow:after
{
position: absolute;
z-index: -1;
content: "";
bottom: 25px;
left: 10px;
width: 50%;
top: 80%;
-webkit-box-shadow: 0 35px 20px #989898;
-moz-box-shadow: 0 35px 20px #989898;
box-shadow: 0 35px 20px #989898 ;
-webkit-transform: rotate(-10deg);
-moz-transform: rotate(-10deg);
-o-transform: rotate(-10deg);
-ms-transform: rotate(-10deg);
transform: rotate(-10deg);
}
.shadow:after
{
-webkit-transform: rotate(10deg);
-moz-transform: rotate(10deg);
-o-transform: rotate(10deg);
-ms-transform: rotate(10deg);
transform: rotate(10deg);
right: 10px;
left: auto;
}
<!DOCTYPE html>
<html>
<body>
<div class="card shadow">
</div>
</body>
</html>
You have to use css pseudo element along with transform: rotate
Try following snippet.
body {
background: #ccc
}
.box h3 {
text-align: center;
position: relative;
top: 80px;
}
.box {
width: 70%;
height: 200px;
background: #FFF;
margin: 40px auto;
}
.shadow {
position: relative;
}
.shadow:before,
.shadow:after {
z-index: -1;
position: absolute;
content: "";
bottom: 15px;
left: 10px;
width: 50%;
top: 80%;
max-width: 300px;
background: #777;
-webkit-box-shadow: 0 15px 10px #777;
-moz-box-shadow: 0 15px 10px #777;
box-shadow: 0 15px 10px #777;
-webkit-transform: rotate(-3deg);
-moz-transform: rotate(-3deg);
-o-transform: rotate(-3deg);
-ms-transform: rotate(-3deg);
transform: rotate(-3deg);
}
.shadow:after {
-webkit-transform: rotate(3deg);
-moz-transform: rotate(3deg);
-o-transform: rotate(3deg);
-ms-transform: rotate(3deg);
transform: rotate(3deg);
right: 10px;
left: auto;
}
<div class="box shadow">
<h3>test of the week?</h3>
</div>
Hi Iam trying to create shadow to box inside another box but not getting what I want
<div class="box effect2">
<div class="box effect2">
box inside box
<div>
<div>
CSS Styles
.box {
width:70%;
height:200px;
background:#FFF;
margin:40px auto;
}
.effect2
{
position: relative;
}
.effect2:before, .effect2:after
{
z-index: -1;
position: absolute;
content: "";
bottom: 15px;
left: 10px;
width: 50%;
top: 80%;
max-width:300px;
background: #777;
-webkit-box-shadow: 0 15px 10px #777;
-moz-box-shadow: 0 15px 10px #777;
box-shadow: 0 15px 10px #777;
-webkit-transform: rotate(-3deg);
-moz-transform: rotate(-3deg);
-o-transform: rotate(-3deg);
-ms-transform: rotate(-3deg);
transform: rotate(-3deg);
}
.effect2:after
{
-webkit-transform: rotate(3deg);
-moz-transform: rotate(3deg);
-o-transform: rotate(3deg);
-ms-transform: rotate(3deg);
transform: rotate(3deg);
right: 10px;
left: auto;
}
I tried this code but not successful. Please tell me if I am doing anything wrong?
I have taken code reference from the css tricks website
Turning my comment into an answer. Both shadows are there, you have the z-index set to -1, so the shadows fall under everything.
.box {
width: 70%;
height: 200px;
background: #FFF;
margin: 40px auto;
}
.effect2, .effect3 {
position: relative;
}
.effect2:before,
.effect2:after {
z-index: -1;
position: absolute;
content: "";
bottom: 15px;
left: 10px;
width: 50%;
top: 80%;
max-width: 300px;
background: #777;
-webkit-box-shadow: 0 15px 10px #777;
-moz-box-shadow: 0 15px 10px #777;
box-shadow: 0 15px 10px #777;
-webkit-transform: rotate(-3deg);
-moz-transform: rotate(-3deg);
-o-transform: rotate(-3deg);
-ms-transform: rotate(-3deg);
transform: rotate(-3deg);
}
.effect2:after {
-webkit-transform: rotate(3deg);
-moz-transform: rotate(3deg);
-o-transform: rotate(3deg);
-ms-transform: rotate(3deg);
transform: rotate(3deg);
right: 10px;
left: auto;
}
.effect3:before,
.effect3:after {
z-index: -1;
position: absolute;
content: "";
bottom: 15px;
left: 10px;
width: 50%;
top: 80%;
max-width: 300px;
background: #cc0000;
-webkit-box-shadow: 0 15px 10px #cc0000;
-moz-box-shadow: 0 15px 10px #cc0000;
box-shadow: 0 15px 10px #cc0000;
-webkit-transform: rotate(-3deg);
-moz-transform: rotate(-3deg);
-o-transform: rotate(-3deg);
-ms-transform: rotate(-3deg);
transform: rotate(-3deg);
}
<div class="box effect2">
<div class="box effect3">
box inside box
</div>
</div>
I added another class to the inside box so you can see what's happening. Also, you will have a difficult time setting this style of drop shadow to a child and parent element because of the z-indexes.
EDIT***
Here's the solution you're looking for. I had to add another element:
.box1 {
background: #fff;
width: 400px;
height: 400px;
position: relative;
}
.wrap {
position: relative;
z-index: 5;
}
.box2 {
background: #ccc;
width: 200px;
height: 200px;
margin: 10px;
position: absolute;
}
.effect1:before,
.effect1:after {
z-index: -1;
position: absolute;
content: "";
bottom: 15px;
left: 10px;
width: 50%;
top: 80%;
max-width: 300px;
background: #777;
box-shadow: 0 15px 10px #777;
transform: rotate(-3deg);
}
.effect1:after {
transform: rotate(3deg);
right: 10px;
left: auto;
}
.effect2:before,
.effect2:after {
z-index: -1;
position: absolute;
content: "";
bottom: 15px;
left: 10px;
width: 50%;
top: 80%;
max-width: 300px;
background: #777;
box-shadow: 0 15px 10px #777;
transform: rotate(-3deg);
}
.effect2:after {
transform: rotate(3deg);
right: 10px;
left: auto;
}
<div class="box1 effect1">
<div class="wrap">
<div class="box2 effect2">my box</div>
</div>
</div>
Solution Fiddle: https://jsfiddle.net/9nqcx28a/8/
This is my HTML code:
<style>
#myelement
{
position: relative;
overflow: hidden;
-webkit-transform: rotate(30deg);
-moz-transform: rotate(30deg);
-ms-transform: rotate(30deg);
-o-transform: rotate(30deg);
transform: rotate(30deg);
border:#000000 solid 2px;
width:500px;
height:500px;
}
#myelement:before
{
content: "";
position: absolute;
width: 200%;
height: 200%;
top: 0%;
left: 0%;
z-index: -1;
-webkit-transform: rotate(-30deg);
-moz-transform: rotate(-30deg);
-ms-transform: rotate(-30deg);
-o-transform: rotate(-30deg);
transform: rotate(-30deg);
background: url(image.jpg) 0 0 no-repeat;
}
</style>
<div id="myelement"></div>
This is image.jpg file:
This is output of browser:
Here, background image is fixed and container is rotating. I want to make reverse. i,e Container will be fixed and background will rotate.
If I understood your question properly, you only need to apply transform: rotate on the pseudo-element which has the background and nothing on the container (like in the below snippet).
#myelement {
position: relative;
overflow: hidden;
border: #000000 solid 2px;
width: 100px;
height: 100px;
}
#myelement:before {
content: "";
position: absolute;
width: 100%;
height: 100%;
top: 0%;
left: 0%;
z-index: -1;
transform: rotate(30deg);
background: url(http://i.stack.imgur.com/lndoe.jpg) 0 0 no-repeat;
}
<div id="myelement"></div>
I want to create something like this via CSS.
Just want to use only CSS to create this custom shape with border radius. Any ideas please?
You can overlap a few div tags and use the skew effect.
HTML
<div class="container">
<div class="shape shape1"></div>
<div class="shape shape2"></div>
<div class="shape shape3"></div>
</div>
CSS
.container {
position: relative;
padding: 30px;
}
.shape {
position: absolute;
text-align: center;
padding: 12px;
height: 60px;
width: 200px;
}
.shape:after {
border-radius: 5px;
content: '';
position: absolute;
height: 100%;
width: 100%;
background: green;
top: 0;
left: 0;
}
.shape1:after {
-webkit-transform: skew(-5deg, -3deg);
-moz-transform: skew(-5deg, -3deg);
-ms-transform: skew(-5deg, -3deg);
-o-transform: skew(-5deg, -3deg);
transform: skew(-5deg, -3deg);
}
.shape2:after {
-webkit-transform: skew(0deg, -1deg);
-moz-transform: skew(0deg, -1deg);
-ms-transform: skew(0deg, -1deg);
-o-transform: skew(0deg, -1deg);
transform: skew(0deg, -1deg);
top: 4px;
left: 3px;
}
.shape3:after {
-webkit-transform: skew(3deg, -2deg);
-moz-transform: skew(2deg, -2deg);
-ms-transform: skew(2deg, -2deg);
-o-transform: skew(2deg, -2deg);
transform: skew(2deg, -2deg);
top: 2px;
left: -5px;
}
.set2 {
margin-top: 80px;
}
.set2 .shape2:after {
background: red;
}
.set2 .shape3:after {
background: blue;
}
Here's a jsFiddle
You may want to look into CSS3 2D Transforms. It's possible to do similar things, but there are limitations as well. I tried to do something similar to the referenced shape :)
// CSS
#shape {
position: relative;
text-align: center;
padding: 12px;
margin-bottom: 6px;
height: 60px;
width: 200px;
margin:30px;
}
#shape:after {
border-radius: 5px;
content: '';
position: absolute;
top: 0;
right: 0;
height: 100%;
width: 100%;
background: green;
-webkit-transform: skew(-5deg, -3deg);
-moz-transform: skew(-5deg, -3deg);
-ms-transform: skew(-5deg, -3deg);
-o-transform: skew(-5deg, -3deg);
transform: skew(-5deg, -3deg);
}
// HTML
<div id="shape"></div>
Check the jsFiddle
I have the following code:
http://jsfiddle.net/cosoroaba/nCEwv/
HTML:
<div id="square">
<div class="corner-wrapper">
<div id="ctr"></div>
</div>
</div>
CSS:
#square {
border: 1px solid #CCCCCC;
display: block;
height: 400px;
line-height: 400px;
margin: 50px auto;
overflow: hidden;
position: relative;
text-align: center;
width: 400px;
}
.corner-wrapper{
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
clip: rect(0px, 141.421px, 70.7107px, 0px);
height: 141.421px;
position: absolute;
right: -20.7107px;
top: -20.7107px;
width: 141.421px;
}
#ctr{
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
left: 20.7107px;
top: 20.7107px;
background-color: blue;
display: block;
height: 100px;
position: absolute;
width: 100px;
}
#ctr:hover{
background-color: green;
}
#ctr:active{
background-color: red;
}
I'm rotating the wrapper in one direction and the content in the opposite direction, then cutting the wrapper in half using clip, to achieve a "triangle"-div
which works well on FF,Chrome and Opera
but there is this issue in IE9 http://www.screenr.com/ikos
hover is triggered on the content in IE9 even if it would be hidden by the wrapper
I'd refactor your code, there's a lot of unnecessary transformations going on, and if you change the size of your container your have to recalculate everything. I haven't checked in IE9 but this should work:
<div id="square">
<div id="ctr"></div>
</div>
CSS
#square {
border: 1px solid #CCCCCC;
display: block;
height: 400px;
line-height: 400px;
margin: 50px auto;
overflow: hidden;
position: relative;
text-align: center;
width: 400px;
}
#ctr{
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-transform-origin: 0 0;
-moz-transform-origin: 0 0;
-ms-transform-origin: 0 0;
-o-transform-origin: 0 0;
transform-origin: 0 0;
right: 0;
top: 0;
background-color: blue;
display: block;
height: 150px;
position: absolute;
width: 100px;
}
#ctr:hover{
background-color: green;
}
#ctr:active{
background-color: red;
}
jsfiddle:
http://jsfiddle.net/exKJK/