How can I create div with a pointed top with CSS - html

I've see a lot of threads remotely related that basically suggest CSS triangles in the ::after or ::before pseudos, but none have really panned out. I'm throwing this out to see if anyone has any ideas.
I'm looking to create a div with a pointed or pitched top that still maintains a uniform border and box-shadow with the rest of the div.
See link for an image of what I'm trying to create:

If you dont want to use a image you could do something like this. But working with an image is lot easier in this case.
body {
background-color: #CCC;
}
.wrapper {
}
.outer {
width: 0;
height: 0;
border-style: solid;
border-width: 0 205px 32px 205px;
border-color: transparent transparent #ffffff transparent;
position: absolute;
}
.inner {
width: 0;
height: 0;
border-style: solid;
border-width: 0 200px 32px 200px;
border-color: transparent transparent #ea2225 transparent;
margin-left: -200px;
margin-top: 5px;
position: absolute;
}
.fix {
background-color: #FFF;
height: 10px;
width: 410px;
position: absolute;
margin-top: 32px;
}
.red {
width: 396px;
height: 300px;
background-color: #ea2225;
margin-top: 37px;
position: absolute;
border-left: 7px solid #FFF;
border-right: 7px solid #FFF;
border-bottom: 6px solid #FFF;
-webkit-box-shadow: 3px 5px 5px 0px rgba(48,48,48,1);
-moz-box-shadow: 3px 5px 5px 0px rgba(48,48,48,1);
box-shadow: 3px 5px 5px 0px rgba(48,48,48,1);
}
<div class="wrapper">
<div class="fix"></div>
<div class="outer">
<div class="inner">
</div>
</div>
</div>
<div class="red"></div>
See http://jsfiddle.net/0csqog8s/

this should get you started:
Update
This is an updated fiddle which is much better presented.
.first {
display: inline-block;
width: 3em;
height: 3em
}
.second {
position: relative;
display: inline-block;
width: 3em;
height: 3em
}
.third {
position: absolute;
display: inline-block;
width: 0;
height: 0;
line-height: 0;
border: 1.5em solid transparent;
margin-top: -1em;
border-bottom: 1em solid #007BFF;
left: 0em;
top: 0em
}
.forth {
position: absolute;
display: inline-block;
width: 0;
height: 0;
line-height: 0;
border: 1.5em solid #007BFF;
border-bottom: 1.5em solid #007BFF;
left: 0em;
top: 1.5em
}
<span class="first"><span class="second"><i class="third"></i><i class="forth"></i></span></span>

Related

How to use a drop-shadow effects in IE on a div with after and befor pseudo elements?

I have a wizard with divs with two arrows with this html
.container {
padding: 10px 20px;
display: flex;
}
div.arrow {
width: 261.5px;
height: 50px;
background-color: #d3d3d3;
position: relative;
margin-right: 30px;
text-align: center;
line-height: 50px;
}
.current {
filter: drop-shadow(2px 3px 7px grey);
}
div.arrow::after {
content: "";
position: absolute;
top: 0;
border: 0 solid #d3d3d3;
border-width: 25px 10px;
width: 0;
height: 0;
left: 100%;
border-color: transparent transparent transparent #d3d3d3;
}
div.arrow::before {
content: "";
position: absolute;
top: 0;
border: 0 solid #d3d3d3;
border-width: 25px 10px;
width: 0;
height: 0;
left: -20px;
border-left-color: transparent;
}
<div class="container">
<div class="arrow">Previous status</div>
<div class="arrow current">Current status</div>
</div>
I have a class called "current" where I applied a drop-shadow effect. It works fine but IE doesn't support it and I can't find a solution for solving this issue. Any help to solve this problem? I can't edit the existing css...
Here a codepen: https://codepen.io/andy_888/pen/bGdKxjv
Thank you

CSS Speech bubble arrow not responsivne

I'm trying to create speech bubbles like below using Viewport Sized Typography
Everything works. It's not ideal but works... only problem is that the "arrow" wont stay at its place when resizing window it moves either inside or outside of bubble after resize
Here is my code so far:
.speechBubble {
position: relative;
display: inline-block;
text-align: center;
color: #FFFFFF;
text-shadow: 0 0 3vw yellow;
background-color: #000000;
border: 3px solid #FFF;
-webkit-border-radius: 58px;
-moz-border-radius: 58px;
border-radius: 50%;
padding: 0px 100px 0px 100px;
-webkit-box-shadow: 2px 2px 4px #888;
-moz-box-shadow: 2px 2px 4px #888;
box-shadow: 2px 2px 4px #888;
max-width: 30vw;
}
.speechBubble:before {
content: '';
position: absolute;
border-style: solid;
border-width: 3vw 11.3vw 2vw 0;
border-color: transparent #FFFFFF;
display: block;
width: 0;
z-index: 0;
left: 4.5vw;
top: -30px;
display: block;
transform: rotate(53deg);
}
.speechBubble:after {
content: '';
position: absolute;
border-style: solid;
border-width: 3vw 11.3vw 2vw 0;
border-color: transparent #000000;
display: block;
width: 0;
z-index: 1;
left: 5vw;
top: -25px;
transform: rotate(53deg);
display: block;
}
.speechBubbleContent {
position: relative;
width: 80%;
margin: 0 auto;
text-transform: uppercase;
padding: 30px;
line-height: 3.7vw;
font-size: 3.7vw;
max-width: 40vw;
}
<div class="speechBubble">
<div class="speechBubbleContent">Some realy really really long text</div>
</div>

How to get 'div' shaped as a flag with CSS

I want to add a label on some of my elements on a website and design for a label that is a flag with an inverted V-shaped cut at the bottom.
So far I have this:
HTML
<div class="css-shapes"></div>
CSS
.css-shapes{
border-left: 99px solid #f00fff;
border-right: 99px solid #f00fff;
border-bottom: 39px solid transparent;
}
http://jsfiddle.net/yhexkm4u/2/
However, I need the background to be white and border around this shape in purple and 1px. I was trying to fit the same shape just in white inside of this one, but everything got messy and didn't go as expected.
Maybe it is a wrong approach, but I want to end up with labels that would look something like this:
With CSS:
You can use CSS transforms on pseudo elements to create the background with a transparent inverted triangle at the bottom:
body{background:url('http://lorempixel.com/image_output/food-q-c-640-480-1.jpg');background-size:cover;}
p{
position: relative;
width: 150px; height: 150px;
overflow: hidden;
border-top:3px solid #EF0EFE;
}
p:before, p:after{
content: '';
position: absolute;
top: -3px;
height: 100%; width: 50%;
z-index: -1;
border:2px solid #EF0EFE;
box-sizing:border-box;
}
p:before{
left: 0;
transform-origin: 0 0;
transform: skewY(-20deg);
border-width:0 0 4px 3px;
}
p:after{
right: 0;
transform-origin: 100% 0;
transform: skewY(20deg);
border-width:0 3px 4px 0;
}
<p>Some text ... </p>
Note that you will need to add vendor prefixes on the transform and transform-origin properties to maximize browser support. See canIuse for more information.
With SVG
Another approach is to use an inline SVG with the polygon element:
body{background: url('http://lorempixel.com/image_output/food-q-c-640-480-1.jpg');background-size: cover;}
div{position: relative;width: 100px; height: 150px;}
svg{position: absolute;width: 100%;height: 100%;z-index: -1;}
<div>
<svg viewbox="-1.5 -1.5 103 153">
<polygon points="100 0, 100 100, 50 85, 0 100, 0 0" fill="transparent" stroke-width="3" stroke="#ef0efe"/>
</svg>
<p>Some text ... </p>
</div>
Here is a slightly different method using pseudo-elements and transform rotations to create an outlined banner like this:
This angled shape is created with position: absolute pseudo-elements, :before and :after:
The excess is cut off with overflow: hidden on the parent to form our banner:
The outline is created with box-shadow and the two angles are prevented from overlapping by pulling / pushing the x-axis by 46px — box-shadow: 46px 0 0 3px #000
Full Example
div {
height: 100px;
width: 100px;
margin: 100px auto;
position: relative;
overflow: hidden;
border: solid 3px #000;
border-bottom: none;
text-align: center;
}
div:before,
div:after {
content: '';
display: block;
height: 100%;
width: 200%;
transform: rotate(20deg);
box-shadow: 46px 0 0 3px #000;
position: absolute;
top: 1px;
right: -120%;
}
div:after {
transform: rotate(-20deg);
left: -120%;
box-shadow: -46px 0 0 3px #000;
}
<div>Text</div>
STOLEN FROM CSS-SHAPES
#flag {
width: 110px;
height: 56px;
padding-top: 15px;
position: relative;
background: red;
color: white;
font-size: 11px;
letter-spacing: 0.2em;
text-align: center;
text-transform: uppercase;
}
#flag:after {
content: "";
position: absolute;
left: 0;
bottom: 0;
width: 0;
height: 0;
border-bottom: 13px solid #eee;
border-left: 55px solid transparent;
border-right: 55px solid transparent;
}
DEMO:
#flag {
width: 110px;
height: 56px;
padding-top: 15px;
position: relative;
background: red;
color: white;
font-size: 11px;
letter-spacing: 0.2em;
text-align: center;
text-transform: uppercase;
}
#flag:after {
content: "";
position: absolute;
left: 0;
bottom: 0;
width: 0;
height: 0;
border-bottom: 13px solid #eee;
border-left: 55px solid transparent;
border-right: 55px solid transparent;
}
<div id="flag"></div>
My Approach
My approach uses skewed elements, and allows you to quickly position them to your needs.
div {
height: 100px;
width: 100px;
position: relative;
border-left: 10px solid tomato;
border-top: 10px solid tomato;
border-right: 10px solid tomato;
text-align: center;
line-height: 100px;
font-size: 30px;
}
div:before {
content: "";
position: absolute;
height: 50%;
width: 50%;
left: -10px; /*width of border*/
bottom: -30px;
z-index: -2;
-webkit-transform: skewY(-20deg);
transform: skewY(-20deg);
border-bottom: 10px solid tomato;
border-left: 10px solid tomato;
}
div:after {
content: "";
position: absolute;
height: 50%;
width: 50%;
right: -10px; /*width of border*/
bottom: -30px;
z-index: -2;
-webkit-transform: skewY(20deg);
transform: skewY(20deg);
border-bottom: 10px solid tomato;
border-right: 10px solid tomato;
}
div:hover, div:hover:before, div:hover:after{
background:lightgray;
}
<div>TEXT</div>
I've had a go at updating your CSS to create the effect you want:
.css-shapes {
height: 250px;
width: 0px;
border-left: 99px solid #f00fff;
border-right: 99px solid #f00fff;
border-bottom: 39px solid transparent;
position: relative
}
.n-shape {
height: 248px;
width: 0px;
border-left: 95px solid #ffffff;
border-right: 95px solid #ffffff;
border-bottom: 39px solid transparent;
position: absolute;
top: -6px;
right: -95px;
}
.top {
position: absolute;
top: 0px;
width: 198px;
height: 2px;
background-color: #f00fff;
left: -99px;
border-bottom: 1px solid #f00fff;
}
<div class="css-shapes">
<div class="n-shape"></div>
<div class="top"></div>
</div>
Fiddle: http://jsfiddle.net/dywhjwna/
Here is what I came up with.
Link Fiddle
It correspond to what you were looking for however I guess there should be a "better way" to it rather than playing with border.
HTML
<div id="text-div">
Text
</div>
<div id="pacman">
<div id="left-triangle"></div>
<div id="right-triangle"></div>
</div>
CSS
#text-div {
width: 118px;
height: 60px;
text-align: center;
border: 1px solid purple;
border-bottom: 0px;
line-height: 60px;
}
#pacman {
width: 0px;
height: 0px;
border-right: 60px solid purple;
border-top: 0px;
border-left: 60px solid purple;
border-bottom: 60px solid transparent;
}
#left-triangle{
position: relative;
left: -59px;
border-right: 58px solid transparent;
border-top: 0px;
border-left: 58px solid white;
border-bottom: 58px solid transparent;
}
#right-triangle{
position: relative;
top: -59px;
left: -57px;
border-right: 58px solid white;
border-top: 0px;
border-left: 58px solid transparent;
border-bottom: 58px solid transparent;
}
A quick workaround is to rotate it:
transform: rotate(90deg);
Fiddle
Another solution would be an SVG path, here's a fiddle!.
A better solution with text easily positioned in the middle, using a rectangle background and a triangle at the bottom.
.css-shapes{
position: relative;
height: 250px;
width: 150px;
background: #FFD05B;
color: #fff;
text-align: center;
line-height:225px;
font-size: 90px;
box-sizing: border-box;
}
.css-shapes:after{
content: '';
position:absolute;
left:0;
bottom: 0;
display: block;
width: 100%;
height:50px;
border-bottom: 25px solid #fff;
border-left: 75px solid transparent;
border-right: 75px solid transparent;
box-sizing: border-box;
}
<div class="css-shapes">1</div>

Ribbon in css3 that goes from side to side

I'm trying to achieve the results on this page http://www.andreapinchi.it/css3-ribbon/
The Side to side one of course but I can't seem to get the '3D' effect.
Please see
http://jsfiddle.net/vuvzcot6/
[html]
<div class="box">
<div class="ribbon both_ribbon">
<h2>Ribbon side to side</h2>
</div>
</div>
[css]
div.both_ribbon{
background: lime;
text-align: center;
color: #000;
padding: 10px 9px 10px 10px;
width: 100%;
margin-left: -10px;
}
div.both_ribbon::before{
display: block;
width: 10px;
height: 0px;
position: absolute;
bottom: -10px;
left: -11px;
content: "";
border-bottom: 10px solid transparent;
border-right: 10px solid rgb(0, 80, 116);
}
div.both_ribbon::after{
display: block;
width: 10px;
height: 0px;
position: absolute;
bottom: -10px;
right: -10px;
content: "";
border-bottom: 10px solid transparent;
border-left: 10px solid rgb(0, 80, 116);
}
.box {
width: 850px;
height: 800px;
background: #82caff;
}
Someone please guide me.
It looks like you're missing the ribbon CSS class, which is necessary for the other classes to work:
.ribbon{
color: #fff;
margin: 30px 0 50px;
position: relative;
text-transform: uppercase;
background: rgb(0, 164, 239);
border: 1px solid rgba(0,0,0,.3);
box-shadow: 0px 1px 3px rgba(0,0,0,.2);
padding: 10px 15px;
clear: both;
}

CSS :after without the elements background

I am trying to use the CSS :after on an element #text, but not have the #text's background continue show behind the after element as I need it to be transparent. I can't just change the background of the after element to #000 because this is just an example and I have other things that should show through it. My code is below.
HTML:
<div id="text">
<div class="news">This is some sample text.</div>
</div>
<div id="logo"></div>
CSS:
body {
background: #000;
margin: 0;
}
#logo {
position: relative;
float: left;
background: #FFFFFF;
width: 25%;
height: 80px;
line-height: 80px;
border: 1px solid #a0a4b0;
border-top: 0;
border-radius: 0 0 8px 8px;
text-align: center;
box-sizing: border-box;
}
#text {
position: relative;
background: #FFFFFF;
border: 1px solid #a0a4b0;
border-width: 0 1px 0 1px;
padding: 5px 30px 15px;
z-index: 100;
line-height: 1.1;
}
#text:after {
content: " ";
position: absolute;
bottom: -1px;
right: 1px;
width: 75%;
box-sizing: border-box;
height: 8px;
border: 1px solid #a0a4b0;
border-width: 1px 0 0 1px;
border-radius: 8px 0 0 0;
}
Fiddle Example
The pseudo element should be placed below the element itself. For the outer curve, an easy option is to use box-shadow:
#text:after {
content: " ";
position: absolute;
bottom: -8px; /* move below parent's background */
right: 1px;
width: 75%;
box-sizing: border-box;
height: 8px;
border: 1px solid #a0a4b0;
box-shadow: -4px -4px 0 4px #fff; /* white outside rounded corner */
border-width: 1px 0 0 1px;
border-radius: 8px 0 0 0;
}
Edited fiddle: http://jsfiddle.net/fzd9xd07/1/
Use This
#text:after {
content: url(http://www.smashingapps.com/wp-content/uploads/2009/06/create-a-slick-tabbed-content-area-using-css-and-jquery.jpg);
position: absolute;
bottom: -1px;
right: 1px;
width: 75%;
box-sizing: border-box;
height: 8px;
border: 1px solid #a0a4b0;
border-width: 1px 0 0 1px;
border-radius: 8px 0 0 0;
}