Transparent trapezoidal buttons with border and centered text - html

I'm designing a site where trapezoids are crucial. I'm using the following code to achieve the effect I'm looking for, but am having issues with it: http://jsfiddle.net/9n9uh6f6/9/
The biggest problems are the mouseover area (because I'm using perspective transforms, the clickable area is skewed) and centering text within the shape.
Other than using perspective transforms, how can I make a shape that does the following:
Trapezoid with a colored border and transparent interior.
Trapezoid that can change color when a user hovers over it.
Trapezoid that houses text in the center of the shape.
Here's the CSS I'm using:
.prodcaptions {
width:136px;
height: 85px;
position:relative;
left:10%;
text-transform:uppercase;
text-align:center;
letter-spacing: 1.6px;
color: #000;
}
.prodcaptions:before {
content:"";
position:absolute;
border-radius:1px;
box-shadow:0 0 0 3px #27628e;
top:-5%;
bottom:-11%;
left:-1%;
right:-5%;
-webkit-transform:perspective(40em) rotateX(-45deg);
transform:perspective(40em) rotateX(-45deg);
}
.prodcaptions a {
z-index:999;
position:relative;
height: 85px;
display: block;
padding-top: 25px;
}

For this case, it would be better to use a skew transform to produce the shape than a rotation with perspective.
We can achieve the shape by using two pseudo-elements skewed in opposite directions and then position one at the left corner and the other at the right corner. Since only the pseudo-elements are skewed and not the main container, the text remains in its expected place (at center-middle).
This shape can (a) support dynamic width (b) have a colored border with transparent background (c) have the text in the center of the shape and (d) support change of background color when hovered on.
.trapezoid {
display: inline-block;
position: relative;
height: 100px;
width: auto;
color: #27628e;
border-top: 2px solid #27628e;
border-bottom: 2px solid #27628e;
line-height: 100px;
text-align: center;
white-space: nowrap;
text-transform: uppercase;
letter-spacing: 1.6px;
margin: 15px 250px; /* Just for demo */
}
.trapezoid:after,
.trapezoid:before {
position: absolute;
content: '';
top: -2px;
height: 100%;
width: 50%;
z-index: -1;
}
.trapezoid:before {
left: 0px;
border-left: 2px solid #27628e;
border-top: 2px solid #27628e;
transform-origin: left bottom;
transform: skew(10deg);
}
.trapezoid:after {
right: 0px;
border-right: 2px solid #27628e;
border-top: 2px solid #27628e;
transform-origin: right bottom;
transform: skew(-10deg);
}
.trapezoid:hover,
.trapezoid:hover:after,
.trapezoid:hover:before {
background: #27628e;
color: white;
}
/* Just for demo */
body {
background: linear-gradient(90deg, aliceblue, powderblue);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
Click Me!!!
You could also create the same shape using SVG and the angled sides look a tad more smoother while using SVG. The below snippet currently works only for a fixed size container. It should not be an issue as the code in question also has fixed dimensions.
.vector {
position: relative;
height: 100px;
width: -webkit-calc(100px * 1.36);
width: calc(100px * 1.36);
line-height: 100px;
margin: 0px auto; /* Just for demo */
}
svg {
height: 100%;
width: 100%:
}
polygon {
fill: transparent;
stroke-width: 2;
stroke: steelblue;
}
.vector a {
position: absolute;
display: block;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
text-decoration: none;
text-transform: uppercase;
letter-spacing: 1.6px;
color: steelblue;
text-align: center;
white-space: nowrap;
}
.vector:hover polygon {
fill: steelblue;
}
.vector:hover a {
color: white;
}
/* Just for demo */
body{
background: linear-gradient(90deg, aliceblue, powderblue);
}
<div class='vector'>
<svg viewBox='0 0 136 100' preserveaspectratio='none'>
<polygon points='1,2 18,98 118,98 135,2' />
</svg>
<a href='#'>Click Me!!!</a>
</div>

Related

How do I make a post heading decoration

I am trying to recreate the decorative line under the heading. Is there anyway that I can do this using just HTML and CSS? Does anyone have any experience in doing something similar?
I thought about doing something like this:
<p>———•———</p>
unfortunately the outcome is not as expected.
I would use a bottom border for the line and then a pseudo element for the dot.
The dot uses use border-radius to make the element spherical. Then we use background-color to make it white and set the border color to the same color as the background, allowing us to mask out parts of the bottom border.
body {
background-color: salmon;
}
h2 {
margin: 1rem 0 0.5rem;
padding-bottom: 0.5rem;
font: 2rem/1.25 Arial, sans-serif;
color: white;
border-bottom: 1px solid white;
text-align: center;
position: relative;
}
h2::after {
content: '';
position: absolute;
z-index: 5;
transform: translateX( -50% );
bottom: -13px; /* border thickness + half height */
left: 50%;
width: 6px;
height: 6px;
background-color: white;
border: 10px solid salmon;
border-radius: 50%;
}
<h2>Portfolio</h2>
One caveat with this approach is that you will need sufficient space between the dot and the text above, otherwise, the border thickness of the dot that is used to mask out the bottom border will overlay/mask your text. See example below:
body {
background-color: salmon;
}
h2 {
margin: 1rem 0 0.5rem;
padding-bottom: 0.5rem;
font: 2rem/1.25 Arial, sans-serif;
color: white;
border-bottom: 1px solid white;
text-align: center;
position: relative;
}
h2::after {
content: '';
position: absolute;
z-index: 5;
transform: translateX( -50% );
bottom: -23px; /* border thickness + half height */
left: 50%;
width: 6px;
height: 6px;
background-color: white;
border: 20px solid gold;
border-radius: 50%;
}
<h2>Portfolio</h2>
You could also do something similar but make the content of the pseudo element a bullet •.

Can we create a half moon like arc in css

I am trying to create image arc like below. I am able to make semicircle but I am not sure how to make the center more thick and outer side thinner of an arc.
Or should I use a image of the arc.
Arc style:
This is very easily done using a pseudo element.
To make it thinner at its end's one set the border width to 0 on all side but the right.
body {
background: black;
}
div {
position: relative;
display: inline-block;
font-size: 30px;
color: lightgreen;
margin: 40px;
}
div::after {
content: '';
position: absolute;
right: -20px;
top: -30px;
height: 100px;
width: 80px;
border-radius: 50%;
border: 0 solid lightgreen;
border-width: 0 5px 0 0;
}
<div>JK</div>
If you're trying to draw your arc with CSS (and you aren't supporting certain legacy browsers), you can achieve the effect by manipulating the border of an element as in this prototype example…
.arc {
height: 100px;
width: 80px;
border: 0 solid #f00;
border-right-width: 5px;
border-radius: 50%;
position: relative;
}
.arc>span {
position: absolute;
top: 50%;
right: 15px;
transform: translateY( -50%);
color: #f00;
text-transform: uppercase;
font-weight: bold;
font-family: 'Arial', sans-serif;
font-size: 30px;
}
<div class="arc"><span>Foo</span></div>
Which has the added advantage of not obscuring the background of the element behind it with a solid color, too.
html{
background:black;
}
#moon {
color:lightgreen;
line-height: 110px;
text-align:center;
font-size:30px;
width: 90px;
height: 120px;
border-radius: 50%;
border-right:6px solid lightgreen;
}
<div id="moon">
JK
</div>

semi-transparent rectangle behind css arrow

I'm quite new to coding so it's probably something really easy that I'm trying to do but can't get it to work.
I've made some arrows with css borders. Now I want to do a rectangle that is semi transparent behind each arrow.
Something like this
But with rectangles instead of the circle.
This is the code I've got so far :
<div id="arrow"></div>
#arrow {
display: block;
border-right: 2px solid; border-bottom: 2px solid;
width: 30px; height: 30px;
transform: rotate(-45deg);
border-color:black;
margin:auto;
display:block;
position:relative;
}
super easy way:
HTML:
<div id="arrowBox">
<div id="arrow"></div>
</div>
CSS:
#arrow {
display: block;
border-right: 2px solid; border-bottom: 2px solid;
width: 30px; height: 30px;
transform: rotate(-45deg);
border-color:black;
margin:auto;
display:block;
position:relative;
}
#arrowBox{
background:rgba(0,0,0,0.5);
display:inline-block;
padding:10px 15px 10px 0;
}
adjust padding to change the size of the box.
Instead of using the div as your arrow, try using the div as your rectangle (or circle if desired). You'll need background-color: rgba(0,0,0,0.4) or similar to get the "translucent black" effect.
Once that's done, put your arrow styles in the ::before pseudo-element. Use positioning to get it in the right place, but it should be pretty easy to get the arrow to appear. Don't forget content:'' to make the pseudo-element appear.
set css property to your rectangle div or any shape as,
{ opacity: 0.5;}
You can user pseudo-elements to add the box with no additional markup. As already suggested, use rgba to define the background color.
I made a fiddle with an example showing the result, with 4 arrows in different directions on different background colors: https://jsfiddle.net/7f6tg9s3/4/
Here is the arrows part:
.arrow {
display: inline-block;
position:relative;
width: 30px;
height: 30px;
}
.arrow::before {
content: ' ';
display: block;
background-color: rgba(0, 0, 0, 0.3);
position: relative;
width: 30px;
height: 30px;
margin-right: -30px;
margin-bottom: -30px;
z-index: 1;
}
.arrow::after {
content: ' ';
display: block;
box-sizing: border-box;
position: relative;
border-right: 2px solid;
border-bottom: 2px solid;
width: calc(25px / 1.41421);
height: calc(25px / 1.41421);
border-color: #fff;
z-index: 2;
}
.arrow.right::after {
transform: rotate(-45deg);
top: 6px;
left: 2px;
}
.arrow.left::after {
transform: rotate(135deg);
top: 6px;
left: 12px;
}
.arrow.up::after {
transform: rotate(-135deg);
top: 12px;
left: 7px;
}
.arrow.down::after {
transform: rotate(45deg);
top: 2px;
left: 7px;
}

Link with border and down triangle transparent

I can't find what I need. I have this code
<hgroup id="subheader">
<h1>lorem ipsum</h1>
<h2>ipsum lorem</h2>
read More
</hgroup>
I want the link to have a border with a down triangle at the bottom. But it has to be transparent, because it goes in front of an image. Is that possible?
The shape given in question is a bit complex to achieve with full transparency because of the area cut by the arrow having to be transparent too. Because of this, the techniques that are generally used for creating such tool-tip like shapes cannot be used as-is here. However, there is a still a way to achieve it using CSS and it is as follows:
Use the parent hgroup for the shape with borders on top, left and right and add border-radius. Don't add any border to the bottom because then cutting the space for the arrow would be tough.
Use two pseudo elements (:before and :after) which have the same height as the parent but lesser width such that they produce a tiny gap when positioned absolutely with respect to parent. Add border-bottom alone to these pseudo-elements.
Add a pseudo-element for the arrow on the arrow-down element (a) and create the arrow using rotate(45deg) transforms instead of using the border trick. The transform method is very helpful for creating transparent arrows. Position this arrow again absolutely with respect to the parent.
As we are dealing with transforms, triangle shapes etc the position values need to be calculated based on Math theorems.
* {
box-sizing: border-box;
}
.container {
height: 300px;
width: 500px;
background: url(http://lorempixel.com/500/300/nature/2);
padding: 10px;
}
#subheader {
position: relative;
width: 400px;
height: auto;
border: 1px solid black;
border-bottom: none;
border-radius: 12px;
padding: 10px;
}
.arrow-down{
display: inline-block;
}
.arrow-down:after {
position: absolute;
content: '';
bottom: -10px; /* half the height of the element */
left: 50px; /* some aribitrary position */
height: 20px;
width: 20px;
transform: rotate(45deg);
transform-origin: 50% 50%; /* rotate around center which is at 60px from left */
border-right: 1px solid black;
border-bottom: 1px solid black;
}
#subheader:after {
position: absolute;
content: '';
left: 74px; /* center point of arrow + 1/2 of hypotenuse */
height: 100%;
width: calc(100% - 74px); /* 100% - value of left */
bottom: 0px;
border-bottom: 1px solid black;
border-bottom-right-radius: inherit; /* same border-radius as parent */
}
#subheader:before {
position: absolute;
content: '';
height: 100%;
width: 46px; /* center point of arrow - 1/2 of hypotenuse */
left: 0px;
bottom: 0px;
border-bottom: 1px solid black;
border-bottom-left-radius: inherit; /* same border-radius as parent */
}
<div class='container'>
<hgroup id="subheader">
<h1>lorem ipsum</h1>
<h2>ipsum lorem</h2>
Read More
</hgroup>
</div>
Here is a working version of what you're after.
HTML
<div style="display:none" class="tri-down">Your Content will go into this fancy tri-down</div>
CSS --- I ADDED a background img to show that its transparent as you said that you were going to be having an image behind it.
body {
background: #333 url("http://a2.files.readwrite.com/image/upload/c_fit,cs_srgb,dpr_1.0,q_80,w_620/MTIyMzI3NDY5NDAyMzg1Njg5.jpg") fixed;
}
.tri-down {
/* Styling block element, not required */
position: relative;
margin-bottom: 2em;
padding: 1em;
width: 75%;
border: 1px solid #999;
background: #f3f3f3;
border-radius:5px;
opacity: 0.5;
/*you may want to set the z-index level of your tri-down box.
z-index: 100;
*/
}
/* Required for Down Triangle */
.tri-down:before, .tri-down:after {
content: "";
position: absolute;
width: 0;
height: 0;
border-style: solid;
border-color: transparent;
border-bottom: 0;
}
/* Stroke */
.tri-down:before {
bottom: -16px;
left: 21px;
/* If 1px darken stroke slightly */
border-top-color: #777;
border-width: 16px;
}
/* Fill */
.tri-down:after {
bottom: -15px;
left: 22px;
border-top-color: #f3f3f3;
border-width: 15px;
}
JSFIDDLE HERE
http://jsfiddle.net/LZoesch/dk43s2qz/
You will want to hide the DIV that is going to house your content. I added it to the above HTML code.
style="display:none"
Then you want to call the link on click and toggle the div class tri-down on/off
<script type="text/javascript">
$(function(){
$('#').click(function(){
$('#').toggle();
$('#').toggle();
});
});
</script>
Here is your orignal code.
<hgroup id="subheader">
<h1>lorem ipsum</h1>
<h2>ipsum lorem</h2>
read More
</hgroup>
If you dont want to set the opacity if your div, you can also try this below.
body {
background: url(http://a2.files.readwrite.com/image/upload/c_fit,cs_srgb,dpr_1.0,q_80,w_620/MTIyMzI3NDY5NDAyMzg1Njg5.jpg);
font-family: sans-serif;
text-align: center;
}
body > div {
color: #000;
margin: 50px;
padding: 15px;
position: relative;
}
.tri-down {
border: 5px solid #000;
content: "";
position: absolute;
}
you can try this one:
.tri-down {
/* Styling block element, not required */
position: relative;
margin-bottom: 2em;
padding: 1em;
border: 1px solid #999;
background: #f3f3f3;
border-radius:5px;
}
/* Required for Down Triangle */
.tri-down:before, .tri-down:after {
content: "";
position: absolute;
width: 0;
height: 0;
border-style: solid;
border-color: transparent;
border-bottom: 0;
}
/* Stroke */
.tri-down:before {
bottom: -16px;
left: 21px;
/* If 1px darken stroke slightly */
border-top-color: #777;
border-width: 16px;
}
/* Fill */
.tri-down:after {
bottom: -15px;
left: 22px;
border-top-color: #f3f3f3;
border-width: 15px;
}
DEMO
You may need to overlay two images and absolutely position them. Like something along the lines of:
body{
padding:2em;
}
#subheader h1{
font-size:1.5em;
margin-top:0;
}
#subheader h2{font-size:1.2em;}
#subheader
{
position: relative;
max-width:300px;
min-height:1.5em;
padding: 20px;
background: #FFFFFF;
border: #dedede solid 2px;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
}
#subheader:after
{
content: "";
position: absolute;
bottom: -19px;
height:13px;
widht:12px;
left: 10%;
border-style: solid;
border-width: 20px 13px 0;
border-color: #FFFFFF transparent;
display: block;
width: 0;
z-index: 1;
}
#subheader:before
{
content: "";
position: absolute;
bottom: -22.5px;
left: calc(10.5% - 3px) ;
border-style: solid;
border-width: 23px 15px 0px;
border-color: #dedede transparent;
display: block;
width: 0;
z-index: 0;}
Like in this pen

How to do the below mentioned shape in css

I need a weird shaped div and I've read around the web for shaping divs but I haven't found what I need :
Please note: It can't be just a border, as there is supposed to be text inside it.
You can use skewX() and a pseudo element to make a your shape responsive :
DEMO
HTML :
<div>TEST</div>
CSS :
div{
line-height:50px;
color:#fff;
text-align:center;
background:#344769;
width:20%;
position:relative;
}
div:after{
content:'';
position:absolute;
width:100%;
height:100%;
left:0;
background:#344769;
z-index:-1;
-ms-transform-origin: 0 100%;
-webkit-transform-origin:0 100%;
transform-origin: 0 100% ;
-ms-transform: skewX(-30deg);
-webkit-transform: skewX(-30deg);
transform: skewX(-30deg) ;
}
If you want to have a really custom shape, you may have a better try with SVG shapes. It allows you to draw polygons, and is used, for example, to display maps on some websites.
As for the illustration you added after editing your answer, you may want to play simply with triangles by separating your shape into the rectangle with text and a triangle on the right.
Example (see also on JsFiddle):
HTML:
<div class="shape">
<span class="text">Test</span>
<span class="triangle"></span>
</div>
CSS:
.shape {
height: 40px;
line-height: 40px;
overflow: hidden;
}
.text {
background: navy;
color: white;
float: left;
padding-left: 20px;
text-align: center;
width: 150px;
}
.triangle {
float: left;
height: 0;
width: 0;
margin-top: -40px;
border-top: 40px solid transparent;
border-bottom: 40px solid transparent;
border-left: 20px solid navy;
}
you can achieve this effect by using linear-gradient.
Have a look at the DEMO First.
div{
width: 200px;
height: 50px;
line-height: 50px;
font-size: 2em;
color:#ffffff;
background: linear-gradient(-250deg, #333 0%, #333 90%, transparent 90%, transparent 100%);
text-align:center;
}
You can use the :after pseudo-element in css to achieve this.
I've created a jsFiddle to demonstrate this: http://jsfiddle.net/49BRA/
CSS:
div {
display: block;
width: 200px;
height: 50px;
background-color: #CCC;
margin: 0;
padding: 0;
line-height: 1em;
position: relative;
font-size: 2em;
line-height: 50px;
text-align: center;
}
div:after {
display: inline-block;
content: "";
height: 0;
width: 0;
border: 25px solid #CCC;
border-bottom: 25px solid transparent;
border-right: 25px solid transparent;
position: absolute;
right: -50px;
}
HTML:
<div>TEST</div>
I hope this works for you.
Cheers!
Please use this code for getting the shape you want:
<span style="display: inline-block; width: 20em; height: 20em">
<span style="position: relative; display: inline-block; width: 20em; height: 20em">
<i style="position: absolute;display:inline-block;width:14.6em;height:5.4em;background-color:#007BFF;left:0em;top:0em"></i>
<i style="position: absolute;display:inline-block;width:0;height:0;line-height:0;border:2.7em solid transparent;border-left:2.7em solid #007BFF;border-top:2.7em solid #007BFF;left:14.6em;top:0em"></i>
</span>
</span>