How to put text on a CSS Triangle - html

I must be missing a simple step. I have made a triangle in CSS and I'm trying to put text on top of the triangle. It works if I don't have the width:0; and height:0; but the triangle does not size right without it. The text is in there, but it wont show on the triangle. Can someone assist?
.log{ /*bottom*/
width:0; height:0;
top:73.2%; left:36.4%;
z-index:2;
background-color:#E3DFD2;
border-top:12vw solid black;
border-right:9vw solid transparent ;
border-left:9vw solid transparent;
transform-origin: -10% -10%;
transition:transform .2s .1s;
color:#FFFFFF;
}
.log:hover{
border-top:12vw solid white;
border-right:9vw solid transparent ;
border-left:9vw solid transparent;
opacity:.5;
color:#000000;
}
Here is the HTML
<a class="log" href="#"><p class="login">Member LogIn</p></a>
I want it to look something like this:

Maybe try something like this :
body{
background: red;
}
.log{
position: relative;
border-bottom:100px solid transparent ;
border-left:100px solid transparent;
border-top: 180px solid black;
border-right:100px solid transparent;
display: inline-block;
transition: all .25s ease;
}
.log:hover{
border-top-color: rgba(255, 255, 255, .5);
}
.log:hover .login{
color: #000;
}
.login{
position: absolute;
color: #fff;
left: -50%;
top: -90px;
display: block;
width: 200px;
height: 180px;
transform: translate(-50%,-50%);
text-align: center;
box-sizing: border-box;
padding: 30px 0;
transition: all .25s ease;
}
<a class="log" href="#">
<span class="login">Member<br>LogIn</span>
</a>

Try out this
.up {
width: 0px;
height: 0px;
border-style: inset;
border-width: 0 100px 173.2px 100px;
border-color: transparent transparent blue transparent;
float: left;
transform:rotate(180deg);
display:block
}
.up span {
text-align: center;
left: -47px;
top:25px;
position: relative;
width: 93px;
height: 93px;
margin: 0px;
transform:rotate(180deg);
display:block;
}
<a class="up" href="#">
<span>TEXT TEXT TEXT</span>
</a>

Related

Trying to create button using arrow

I am trying to create a button with an arrow same as the below image:
But when I do that using the below code it looks like this:
My Code:
.ms-btn,
.ms-btn:hover {
border: 2px solid #3E5B73;
color: #3E5B73;
font-size: 12px;
font-family: 'Ubuntu';
border-radius: 40px;
padding: 16px 28px;
position: relative;
background: transparent;
transition: 0.3s all linear;
}
.ms-btn:before {
content: url(../img/image-left.svg);
position: absolute;
left: -15px;
top: 23%;
/*background: #fff;*/
padding: 5px;
height: 24px;
display: flex;
transform: translateX(0px);
transition: 0.3s all linear;
}
<a class="ms-btn" href="">LEARN MORE</a>
Hope to see any solution for it using css. so button borders can cut or something..
Add to you code the background-color for the 'svg' and adjust the position top. that was it.
div {
padding: 20px;
}
.ms-btn,
.ms-btn:hover {
border: 2px solid #3E5B73;
color: #3E5B73;
font-size: 12px;
font-family: 'Ubuntu';
border-radius: 40px;
padding: 16px 28px;
position: relative;
background: transparent;
transition: 0.3s all linear;
}
.ms-btn:before {
content: url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiPjxwYXRoIGQ9Ik0yMS44ODMgMTJsLTcuNTI3IDYuMjM1LjY0NC43NjUgOS03LjUyMS05LTcuNDc5LS42NDUuNzY0IDcuNTI5IDYuMjM2aC0yMS44ODR2MWgyMS44ODN6Ii8+PC9zdmc+');
position: absolute;
left: -15px;
top: 15%;
background: #fff;
padding: 5px;
height: 24px;
display: flex;
transform: translateX(0px);
transition: 0.3s all linear;
}
<div>
<a class="ms-btn" href="">LEARN MORE</a>
</div>
Use clip-path to cut the border. I have added 2 CSS variables to control the cut area:
.ms-btn {
--s: 15px;
--b: 10px;
display: inline-block;
margin: 50px;
color: #3E5B73;
font-size: 12px;
padding: 16px 28px;
position: relative;
transition: 0.3s all linear;
}
/* the border */
.ms-btn:before {
content: "";
position: absolute;
inset: 0;
border: 2px solid #3E5B73;
border-radius: 40px;
clip-path:polygon(0 0,100% 0,100% 100%,0 100%,0 calc(50% + var(--s)),var(--b) calc(50% + var(--s)),var(--b) calc(50% - var(--s)),0 calc(50% - var(--s)));
}
/* the arrow */
.ms-btn:after {
content: "";
position: absolute;
left: -10px;
top: calc(50% - 10px);
background: red;
height: 20px;
width: 20px;
}
<a class="ms-btn" href="">LEARN MORE</a>
The closest style to what you want is that I noted below. I remove left border and reduce top and bottom left border radius. You can increase or decrease them as you want. This arrow doesn't have and doesn't need background color and I think it will solve you problem and meet your need.
div {
padding: 20px;
}
.ms-btn,
.ms-btn:hover {
border-width: 2px 2px 2px 0px;
border-color: #3E5B73;
border-style: solid;
color: #3E5B73;
font-size: 12px;
font-family: 'Ubuntu';
border-radius: 20px 40px 40px 20px;
padding: 16px 28px;
position: relative;
background: transparent;
transition: 0.3s all linear;
}
.ms-btn:before {
content: url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiPjxwYXRoIGQ9Ik0yMS44ODMgMTJsLTcuNTI3IDYuMjM1LjY0NC43NjUgOS03LjUyMS05LTcuNDc5LS42NDUuNzY0IDcuNTI5IDYuMjM2aC0yMS44ODR2MWgyMS44ODN6Ii8+PC9zdmc+');
position: absolute;
left: -25px;
top: 15%;
padding: 5px;
height: 24px;
display: flex;
transform: translateX(0px);
transition: 0.3s all linear;
}
<div>
<a class="ms-btn" href="">LEARN MORE</a>
</div>

Border behind Button slight below position CSS

I m trying to implement below button CSS, I tried to used box-shadow as well psuedo code i.e before after still not getting the output I wanted.
the button that I wanted:
my code:
.et_pb_button {
background-color: #f16922!important;
width: 65%;
outline: 3px solid #f16922;
outline-offset: 10px;
text-transform: uppercase;
font-size: 14px!important;
}
Button
Please see below snippet:
button {
position: relative;
display: inline-block;
vertical-align: top;
background-color: blue;
color: #fff;
border-radius: none;
text-transform: uppercase;
border: none;
padding: 10px 12px;
}
button::after {
content: '';
position: absolute;
top: 5px;
left: -5px;
right: -5px;
bottom: -5px;
border: 1px solid red;
display: block;
z-index: -1;
}
<button>View Project</button>
.btngroup button{
background-color: rgb(29, 174, 236);
border: 0;
padding: 10px 15px;
font-size: 15px;
color: white;
width: 150px;
height: 50px;
text-transform: uppercase
}
.btngroup .drop{
width: 165px;
height: 50px;
border: 1.5px solid red;
margin-top: -42.5px;
}
<center>
<div class="btngroup">
<button>view project</button>
<div class="drop"></div>
</div>
</center>
Here is an idea with one element and multiple background and border-image:
.button {
display:inline-block;
padding:10px 60px 20px;
margin:10px;
color:#fff;
border:2px solid transparent;
border-image:linear-gradient(to bottom,transparent 10px,red 0) 2;
background:
linear-gradient(blue,blue) top center/calc(100% - 20px) calc(100% - 10px),
linear-gradient(red,red) 0 8px /100% 2px;
background-repeat:no-repeat;
}
<span class="button">Button</span>
And with CSS variable to easily control the whole shape:
.button {
--t:10px; /* Distance of the border from the top*/
--p:10px; /* Distance between the border and background*/
--b:2; /* Thickness of the border (unitless to be used with slice)*/
--c:red; /* border color*/
display:inline-block;
padding:var(--p) 60px calc(2*var(--p));
margin:10px;
color:#fff;
border:calc(1px*var(--b)) solid transparent;
border-image:linear-gradient(to bottom,transparent var(--t),var(--c) 0) var(--b);
background:
linear-gradient(blue,blue) top center/calc(100% - 2*var(--p)) calc(100% - var(--p)),
linear-gradient(var(--c),var(--c)) 0 calc(var(--t) - 1px*var(--b))/100% calc(1px*var(--b));
background-repeat:no-repeat;
}
<span class="button">Button</span>
<span class="button" style="--c:green;--t:15px;--p:8px;--b:3;">Button</span>
<span class="button" style="--c:#000;--t:25px;--p:15px;--b:1;">Button</span>
Here's an alternative based on Hanif's suggestion, which uses both pseudo-elements instead of one with a negative z-index. For some backgrounds (e.g. an image or gradient), it might be necessary to adjust the background-position for the ::after
button {
position: relative;
display: inline-block;
vertical-align: top;
background-color: blue;
color: #fff;
border-radius: none;
text-transform: uppercase;
border: none;
padding: 10px 12px;
}
button::before {
content: '';
position: absolute;
top: 5px;
left: -5px;
right: -5px;
bottom: -5px;
border: 1px solid red;
display: block;
}
button::after {
content: '';
position: absolute;
top: 5px;
left: 0;
right: 0;
height: 1px;
background: inherit;
display: block;
}
<button>View Project</button>

css focus property not working properly

I am using CSS transform and transition properties. When I hover the image, the button shows up as expected over the image. The problem I found now is that when I focus on the image by pressing the TAB key, the image simply disappears and only the button shows.
Html:
<div class="main">
<img src="phone.jpg" >
<div class="paragraph">This wil be centered</div>
<div class="content">
<button>Nokia 7210 Classic</button>
</div>
</div>
CSS:
.clearfix{
clear: both;
}section
{
text-align: center;
}
.main{
float:left;
width:30%;
text-align: center;
border:10px solid white;
width:306px;
height:306px;
margin : 50px auto;
box-shadow: 0px 0px 25px black;
overflow: hidden;
}
.paragraph{
-webkit-transform: translateY(-300%);
border: 5px solid grey;
background-color: grey;
opacity: 0.5;
}
.main:hover .content,
.main:focus .content{
-webkit-transform: translateY(-340px);
-webkit-transition: -webkit-transform 700ms;
}
.content{
width: 306px;
height: 306px;
background: rgba(51, 102, 255, 0.5);
}
img{
height:inherit;
width:inherit;
-webkit-transition: -webkit-transform 5000ms;
}
button{
width: 100%;
height: 50px;
margin-top: 100px;
background: black;
border: 0;
cursor: pointer;
color: white;
font: 16px tahoma;
}
button:hover{
opacity: 0.5;
}
How can I overcome this problem in a way that the same effect happens on FOCUS?

Transition input width

I have the input search field. When I click on it I need it to become wider performing smooth transition from right to left, i.e. the input is located on the right side of the page and when I click on it it should stretch to the left in some number of pixels and become wider.
Here's my css:
#header #search input {
background: #FFF;
padding: 1px 1px 1px 5px;
width: 178px;
height: 21px;
border: 1px solid #CCCCCC;
border-radius: 6px;
-webkit-transition: all .5s;
-moz-transition: all .5s;
transition: all .5s;
}
#header #search input:focus {
background: #FFF;
padding: 1px 1px 1px 5px;
width: 300px;
height: 21px;
border: 1px solid #CCCCCC;
Could you help me with implementing that?
input[type="search"] {
background: #FFF;
padding: .5rem 1rem;
position: relative;
top: 0;
left: 0;
width: 178px;
height: 40px;
outline: none;
border: 1px solid #CCCCCC;
border-radius: 6px;
transition: all .5s;
}
input[type="search"]:focus {
width: 300px;
top: 0;
right: 100%;
}
<div style="text-align:right;">
<input type="search" id="search" />
</div>
Position the input absolutely and set the right property to zero:
position:absolute;
right:0;
That forces the expansion to the left when focused.
jsFiddle example
Make your containers offset parents using position: relative.
#header, #search {
width: 100%;
position: relative;
}
Then position your input using position: absolute and place it using right.
#header #search input {
position: absolute;
right: 0px;
background: #FFF;
padding: 1px 1px 1px 5px;
width: 178px;
height: 21px;
border: 1px solid #CCCCCC;
border-radius: 6px;
-webkit-transition: all .5s;
-moz-transition: all .5s;
transition: all .5s;
}
#header #search input:focus {
background: #FFF;
padding: 1px 1px 1px 5px;
width: 300px;
height: 21px;
border: 1px solid #CCCCCC;
Your animation will now stretch to the left.

How to create a pricetag shape in CSS and HTML

So I've found this answer - CSS3 menu shape, style but have no idea on how to put it on the left side. I've searched for it already but with no luck.
This is what I'm trying to achieve:
And I've found this one also - Change the shape of the triangle. How can I make it work on the opposite side? I mean the arrow needs to be on the left side. And is it possible to do this with one div?
Want one that you can put over any background color?
jsBin demo
Only this HTML:
<span class="pricetag"></span>
And this CSS:
.pricetag{
white-space:nowrap;
position:relative;
margin:0 5px 0 10px;
displaY:inline-block;
height:25px;
border-radius: 0 5px 5px 0;
padding: 0 25px 0 15px;
background:#E8EDF0;
border: 0 solid #C7D2D4;
border-top-width:1px;
border-bottom-width:1px;
color:#999;
line-height:23px;
}
.pricetag:after{
position:absolute;
right:0;
margin:1px 7px;
font-weight:bold;
font-size:19px;
content:"\00D7";
}
.pricetag:before{
position:absolute;
content:"\25CF";
color:white;
text-shadow: 0 0 1px #333;
font-size:11px;
line-height:0px;
text-indent:12px;
left:-15px;
width: 1px;
height:0px;
border-right:14px solid #E8EDF0;
border-top: 13px solid transparent;
border-bottom: 13px solid transparent;
}
which basically follows this principles: How to create a ribbon shape in CSS
If you want to add borders all around:
jsBin demo with transform: rotate(45deg) applied to the :before pseudo
.pricetag{
white-space:nowrap;
position:relative;
margin:0 5px 0 10px;
displaY:inline-block;
height:25px;
border-radius: 0 5px 5px 0;
padding: 0 25px 0 15px;
background:#E8EDF0;
border: 1px solid #C7D2D4;
color:#999;
line-height:23px;
}
.pricetag:after{
position:absolute;
right:0;
margin:1px 7px;
font-weight:bold;
font-size:19px;
content:"\00D7";
}
.pricetag:before{
position:absolute;
background:#E8EDF0;
content:"\25CF";
color:white;
text-shadow: 0 0 1px #aaa;
font-size:12px;
line-height:13px;
text-indent:6px;
top:3px;
left:-10px;
width: 18px;
height: 18px;
transform: rotate(45deg);
border-left:1px solid #C7D2D4;
border-bottom:1px solid #C7D2D4;
}
Since the example image in the question has extra outer borders, achieving it with the border trick will involve multiple (pseudo) elements and will become complex (because in addition to the arrow shape, a circle is also needed in front). Instead, the same could be achieved by using transform: rotate() like in the below sample.
The approach is pretty simple and as follows:
The parent div container houses the text that should be present within the price-tag shape.
The :after pseudo-element has transform: rotate(45deg) and produces the triangle shape. This is then positioned absolutely with respect to the left edge of the parent. The background set on the pseudo-element prevents the left border of the parent container from being visible.
The :before pseudo-element forms the circle present on the left side (using border-radius).
The X mark at the end is added using a span tag and the × entity.
The parent div container's width is set to auto so that it can expand based on the length of the text.
Note: This sample uses transforms, so will require polyfills in lower versions of IE.
div {
position: relative;
display: inline-block;
width: auto;
height: 20px;
margin: 20px;
padding-left: 15px;
background: #E8EDF2;
color: #888DA3;
line-height: 20px;
border-radius: 4px;
border: 1px solid #C7D2DB;
}
div:after,
div:before {
position: absolute;
content: '';
border: 1px solid #C7D2DB;
}
div:after { /* the arrow on left side positioned using left property */
height: 14px;
width: 14px;
transform: rotate(45deg);
background: #E8EDF2;
border-color: transparent transparent #C7D2DB #C7D2DB;
left: -6px;
top: 2px;
}
div:before { /* the circle on the left */
height: 4px;
width: 4px;
border-radius: 50%;
background-color: white;
left: 0px;
top: 7px;
z-index: 2;
}
.right { /* the x mark at the right */
text-align: right;
margin: 0px 4px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<div>Home<span class='right'>×</span>
</div>
<div>Home Sweet Home<span class='right'>×</span>
</div>
<div>Hi<span class='right'>×</span>
</div>
Fiddle Demo
I wanted a simplified version of what was proposed here (without the hole effect and borders) but with the pointing side of it with rounded corner as well. So I came up with this solution. Visually this is what you get:
The HTML for it:
<div class="price-tag">Marketing</div>
<div class="price-tag">Sales</div>
<div class="price-tag">Inbound</div>
And the CSS for it:
.price-tag {
background: #058;
border-radius: 5px;
color: #fff;
cursor: pointer;
display: inline-block;
font-size: 0.875rem;
height: 30px;
line-height: 30px;
margin-right: 1rem;
padding: 0 0.666rem;
position: relative;
text-align: center;
}
.price-tag:after {
background: inherit;
border-radius: 4px;
display: block;
content: "";
height: 22px;
position: absolute;
right: -8px;
top: 4px;
-ms-transform: rotate(45deg); /* IE 9 */
-webkit-transform: rotate(45deg); /* Chrome, Safari, Opera */
transform: rotate(45deg);
width: 22px;
z-index: -1;
}
.price-tag:hover {
background: #07b;
}
original example
Modified: http://jsbin.com/ruxusobe/1/
Basically, it needs to float left, use border-right (instead of left) and modify the padding.
CSS:
.guideList{
font-size: 12px;
line-height: 12px;
font-weight: bold;
list-style-type: none;
margin-top: 10px;
width: 125px;
}
.guideList li{
padding: 5px 5px 5px 0px;
}
.guideList .active{
background-color: #0390d1;
color: white;
}
.guideList .activePointer{
margin-top: -5px;
margin-bottom: -5px;
float: left;
display: inline-block;
width: 0px;
height: 0px;
border-top: 11px solid white;
border-right: 11px solid transparent;
border-bottom: 11px solid white;
}
HTML:
<ul class="guideList">
<li><a>Consulting</a></li>
<li class="active"><span class="activePointer"></span>Law</li>
<li><a>Finance</a></li>
<li><a>Technology</a></li>
</ul>
Here is a simple example...
Orignal Version
Edited Version
CSS:
div {
margin-left: 15px;
background: #76a7dc;
border: 1px solid #CAD5E0;
padding: 4px;
width:50px;
position: relative;
}
div:after {
content:'';
display: block;
position: absolute;
top: 2px;
left: -1.3em;
width: 0;
height: 0;
border-color: transparent #76a7dc transparent transparent;
border-style: solid;
border-width: 10px;
}
Notice on border-color, only right is set with a color and everything else is set to transparent.
using pseudo element and a little bit playing with border you can achieve the exact thing. Check the DEMO.
HTML code is :
<a class="arrow" href="#">Continue Reading</a>
CSS Code is:
body{padding:15px;}
.arrow {
background: #8ec63f;
color: #fff;
display: inline-block;
height: 30px;
line-height: 30px;
padding: 0 12px;
position: relative;
border-radius: 4px;
border: 1px solid #8ec63f;
}
.arrow:before {
content: "";
height: 0;
position: absolute;
width: 0;
}
.arrow:before {
border-bottom: 15px solid transparent;
border-right: 15px solid #8ec63f;
border-top: 15px solid transparent;
left: -15px;
}
.arrow:hover {
background: #f7941d;
color: #fff;
border-radius: 4px;
border: 1px solid #f7941d;
}
.arrow:hover:before {
border-bottom: 15px solid transparent;
border-top: 15px solid transparent;;
border-right: 15px solid #f7941d;
}