I saw this question and answer: CSS Gradient arrow shape with inner shadow and gradient border and I'm looking to create the same thing but with an arrow on each side.
Here is what the final result would looks like:
I would do it in 3 steps:
create a normal rectangular element with a background gradient (e.g. from orange to red)
create a pseudo element ::before with a background color, the gradient is starting with (e.g. orange)
create a pseudo element ::after with a background color, the gradient is ending with (e.g. red)
Now you just need to position the pseudo elements properly and use the border property to create the triangle shape:
div {
position: relative;
display: inline-block;
text-transform: uppercase;
color: white;
height: 3em;
min-width: 10em;
line-height: 3em;
font-family: Arial;
font-size: 1.5em;
font-weight: bold;
text-align: center;
background: linear-gradient(to right, orange, red);
padding: 0 1em;
margin: 0 1em;
}
div::before,
div::after {
content: '';
position: absolute;
height: 0;
width: 0;
border-top: 1.5em solid transparent;
border-bottom: 1.5em solid transparent;
}
div::before {
left: -1em;
border-right: 1em solid orange;
}
div::after {
right: -1em;
border-left: 1em solid red;
}
<div>Exemple</div>
What about a solution with only gradient and no pseudo element:
.arrow {
text-transform: uppercase;
color: white;
width: 200px;
line-height: 3em;
font-family: Arial;
font-size: 1.5em;
font-weight: bold;
text-align: center;
background:
linear-gradient(to top left ,orange 50%,transparent 51%) top left /20px 50%,
linear-gradient(to bottom left ,orange 50%,transparent 51%) bottom left /20px 50%,
linear-gradient(to top right,red 50%,transparent 51%) top right /20px 50%,
linear-gradient(to bottom right,red 50%,transparent 51%) bottom right/20px 50%,
linear-gradient(to right, orange, red) 20px 0/calc(100% - 40px) 100% ;
background-repeat:no-repeat;
margin: 20px;
}
<div class="arrow">Exemple</div>
<div class="arrow">work with <br>2 lines</div>
And here is another one with clip-path:
.arrow {
text-transform: uppercase;
color: white;
width: 200px;
line-height: 3em;
font-family: Arial;
font-size: 1.5em;
font-weight: bold;
text-align: center;
background: linear-gradient(to right, orange, red);
margin: 20px;
clip-path: polygon(90% 0, 100% 50%, 90% 100%, 10% 100%, 0 50%, 10% 0);
}
<div class="arrow">Exemple</div>
<div class="arrow">work with <br>2 lines</div>
You Can also write css without using gradient background
Step 1: write html
<span class="right-arrow" style="
background-color: red;
width: 16%;
display: -webkit-box;
padding: 10px 10px;
color: #fff;
font-size: 16px;
font-weight: 600;
position: relative;
">
Example
</span>
Step 2: Write css
span{
background-color: red;
width: 180px;
display: -webkit-box;
padding: 10px 10px;
color: #fff;
font-size: 16px;
font-weight: 600;
position: relative;
}
span.right-arrow:after {
content: '';
width: 0;
height: 0;
border-top: 21px solid transparent;
border-left: 21px solid red;
border-bottom: 21px solid transparent;
position: absolute;
right: -21px;
top: 0;
}
Now it working fine
W3Schools has a great example of gradients in CSS: https://www.w3schools.com/css/css3_gradients.asp
background: linear-gradient(direction, color-stop1, color-stop2, ...)
background: linear-gradient(to right, red , yellow);
For the shape of your div, W3Schools also has a great page for creating geometric shapes: https://www.w3schools.com/howto/howto_css_shapes.asp
But to paste the same code twice:
div {
position: relative;
display: inline-block;
height: 3em;
min-width: 10em;
background: linear-gradient(to right, orange, red);
padding: 0 1em;
margin: 0 2em;
}
div::before,
div::after {
content: '';
position: absolute;
height: 0;
width: 0;
border-top: 1.5em solid transparent;
border-bottom: 1.5em solid transparent;
}
div::before {
left: -1em;
border-right: 1em solid orange;
}
div::after {
right: -1em;
border-left: 1em solid red;
}
Related
I've found out the way to create a border bottom with 2 different colors, but is it possible to have a space between the 2 different colors like the picture shown above?
You will have to tweak the percentages to get the white gap exactly where you want it, but this should get you started.
a {
font-family: sans-serif;
font-size: 36px;
background:
linear-gradient(
to right,
rgba(0, 83, 124,1) 0%,
rgba(0, 83, 124,1) 80%,
rgba(255,255,255,1) 80%,
rgba(255,255,255,1) 82%,
rgba(255, 63, 63,1) 82%,
rgba(255, 63, 63,1) 100%
) bottom left no-repeat;
padding: 6px 0;
text-decoration: none;
background-size: 100% 6px;
color: rgba(0, 83, 124,1);
}
CONTACT US
#font-face {
font-family: "Arial-Bold";
src: url(https://www.cufonfonts.com/download/font/single/48880/arial);
}
h2 {
font-family: "Arial-Bold";
position: relative;
display: inline-block;
color: #1b478d;
text-transform: uppercase;
}
h2::before {
position: absolute;
content: " ";
width: 74%;
left: 0;
bottom: -5px;
height: 5px;
background: #1b478d;
}
h2::after {
position: absolute;
content: " ";
width: 24%;
right: 0;
bottom: -5px;
height: 5px;
background: #e69399;
}
<h2>Contact Us</h2>
You Can Achieve That Using CSS's Border Color Property
h2 {
font-family: sans-serif;
color: #1b478d;
text-transform: uppercase;
}
.txt1 {
border-bottom: 5px solid #1b478d;
margin-right: 4px; /* Space You Want between the Word "Contact" and "Us" */
}
.txt2 {
border-bottom: 5px solid #e69399;
}
<h2>
<span class="txt1">Contact</span><span class="txt2">Us</span>
</h2>
The margin-right property in .txt1 is being used for the space between the both word "Contact" and "Us"
I want to draw the below ripple using css.
The closest I darw was something like this.
display: block;
width: 126px;
height: 180px;
background-color: rgba(99, 83, 196, 0.38);
border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
Does anyone have an idea on how to draw a half ripple ?
I think it is just two concentric circles that are masked by the rounded rectangle. You can achieve this with a circular gradient background:
#out {
background: #ddd;
padding: 10px;
width: 200px;
}
#in {
background: #fff;
background: radial-gradient(circle at 180px 10px, rgba(146,136,193,1) 30px, rgba(183,178,214,1) 30.5px, rgba(183,178,214,1) 50px, rgba(255,255,255,1) 50.5px);
background-repeat: no-repeat;
border-radius: 8px;
color: #6456BD;
font-family: sans-serif;
font-size: 20px;
font-weight: 700;
height: 40px;
padding: 30px 20px;
}
<div id="out">
<div id="in">
Usage<br>balances
</div>
</div>
I'm trying the find a way to have a dynamic border with a triangle. For the moment, with the basic gradient effect, this is what I did:
My current effect in action
But as you can see, the background has a gradient and we can see the border background that does not match..
How can I achieve this effect? Also, the text may vary on different screen size and with other words.
Thank you!
Using pseudo-elements and skewX is one clean way to achieve this. Check this out, I'm using a top, left & right border on the element, and then style the before as the left bottom border and the after as the right one:
body {
background-color: white;
background-image: linear-gradient(45deg, #999 25%, transparent 25%, transparent 75%, black 75%, black), linear-gradient(45deg, black 25%, transparent 25%, transparent 75%, #999 75%, #999);
background-size: 10px 10px;
background-position: 0 0, 50px 50px;
}
.dialog {
text-align: center;
color: green;
font-size: 65px;
width: 300px;
height: 120px;
background-color: transparent;
border-width: 5px 5px 0 5px;
border-color: red;
border-style: solid;
display: inline-block;
position: relative;
}
.dialog:before {
content: '';
border-top: 5px solid red;
border-right: 5px solid red;
transform-origin: left top;
transform: skewX(45deg);
position: absolute;
content: ' ';
height: 10px;
width: 46%;
background: inherit;
left: -5px;
bottom: -10px;
}
.dialog:after {
content: '';
border-top: 5px solid red;
border-left: 5px solid red;
transform-origin: left top;
transform: skewX(-45deg);
position: absolute;
content: ' ';
height: 10px;
width: 46%;
background: inherit;
right: -5px;
bottom: -10px;
}
<div class="dialog">Here I am</div>
To achieve this you can make it with a background image, for exemple http://bootsnipp.com/snippets/featured/carousel-reviews-with-rating.
As you can see he take an image and resize it to take only a triangle like this:
.sprite-i-triangle {
background-position: 0 -1298px;
height: 44px;
width: 50px;
}
Try to find an image that meets your expectations. Otherwise you have some exemples in this site. (http://bootsnipp.com)
I want to achieve border top and bottom like below image how can I achieve with CSS tricks?
Challenge is I don't want entire width with border and it should be responsive too.
Mobile version image is http://i.imgur.com/XZTW28N.jpg and it should work in desktop and mobile browser too.
I tried with %width border but it's not working.
I wrote below code but it's not 100% perfect answer for me.
HTML:
<h1>How it Works</h1
CSS:
h1:before, h1:after {
content: "";
height: 1px;
background: linear-gradient(to right, rgba(0,0,0,0) 0%,rgba(147,147,147,1) 50%,rgba(0,0,0,0) 100%);
display: block;
margin-bottom: 10px;
margin-top: 10px;
}
http://jsfiddle.net/wjhnX/488/
I made a few changes in your CSS:
h1{
text-align: center;
font-size: 70px;
}
h1:before, h1:after{
position: relative;
content: "";
width: 30%;
left: 35%;
display: block;
margin-bottom: 10px;
margin-top: 10px;
border-bottom: 5px dotted yellow;
}
DEMO
EDIT:
If you want a fixed width you can add:
h1:before, h1:after{
width: 150px; /* You can change this value */
left: 50%;
transform: translateX(-50%);
}
DEMO2
You can use box-shadows also to achieve this, first create an after psuedo-element on top and a before pseudo-element on bottom then give the two of the box-shadows
body{
background:#09858F;
}
div{
position:relative;
display:inline-block;
margin:100px;
}
h1{
text-align:center;
font-family: Calibri;
font-size:50px;
color:#fff;
margin:50px;
}
h1:after{
content:"";
position:absolute;
left:30%;
height:10px;
width:10px;
background:yellow;
top:20%;
border-radius:50%;
box-shadow:20px 0 0 0 yellow,40px 0 0 0 yellow,60px 0 0 0 yellow,80px 0 0 0 yellow,100px 0 0 0 yellow,120px 0 0 0 yellow,140px 0 0 0 yellow,160px 0 0 0 yellow;
}
h1:before{
content:"";
position:absolute;
left:30%;
height:10px;
width:10px;
background:yellow;
bottom:20%;
border-radius:50%;
box-shadow:20px 0 0 0 yellow,40px 0 0 0 yellow,60px 0 0 0 yellow,80px 0 0 0 yellow,100px 0 0 0 yellow,120px 0 0 0 yellow,140px 0 0 0 yellow,160px 0 0 0 yellow;
}
<div><h1>How it Works</h1></div>
Here is another approach using radial-gradient background image to produce the dots at the top and bottom. The output is responsive and the no. of dots at the top and bottom are determined by the width (for example, width: 108px produces 9 dots as background-size in x-axis is 12px).
The advantage of this approach over the others is that this allows greater control over the size of the dots and the space in between the dots. The downside is the browser support for radial-gradient which is lower (IE10+) compared to dotted border method.
h1 {
position: relative;
text-align: center;
font-size: 48px;
line-height: 1em;
padding: 0.625em;
font-family: Calibri;
font-weight: 100;
}
h1:after {
position: absolute;
content: '';
width: 108px; /* multiples of background-size in X-axis */
height: 100%;
top: 0px;
left: calc(50% - 50px);
background: radial-gradient(circle at 50% 50%, rgb(250, 189, 38) 30%, transparent 50%), radial-gradient(circle at 50% 50%, rgb(250, 189, 38) 30%, transparent 50%);
background-size: 12px 6px;
background-repeat: repeat-x;
background-position: 50% 0.125em, 50% 2em;
}
/* Just for demo */
body {
background: rgb(9, 133, 143);
color: white;
}
<!-- library included to support older browsers -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<h1>How it works</h1>
<h1>How it works with long text</h1>
Screenshot with large dots:
All that is needed to be done to make the dots smaller in size is to reduce the color-stop percentages of the radial gradient. The smaller the percentages, the smaller the dots.
h1 {
position: relative;
text-align: center;
font-size: 48px;
line-height: 1em;
padding: 0.625em;
font-family: Calibri;
font-weight: 100;
}
h1:after {
position: absolute;
content: '';
width: 108px; /* multiples of background-size in X-axis */
height: 100%;
top: 0px;
left: calc(50% - 50px);
background: radial-gradient(circle at 50% 50%, rgb(250, 189, 38) 25%, transparent 35%), radial-gradient(circle at 50% 50%, rgb(250, 189, 38) 25%, transparent 35%);
background-size: 12px 6px;
background-repeat: repeat-x;
background-position: 50% 0.125em, 50% 2em;
}
/* Just for demo */
body {
background: rgb(9, 133, 143);
color: white;
}
<!-- library included to support older browsers -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<h1>How it works</h1>
<h1>How it works with long text</h1>
Screenshot with smaller dots:
I was just wondering how to align links in a navigation menu in the middle vertically, as I have tried vertical align and it is not working and have searched stack overflow and have found no answers.
Note: the navmenu usually goes the full length of the page and the link are at the top, not in the middle.
Here is the fiddle
Here is the code:
CSS:
* {
padding: 0px;
margin: 0px;
}
.top {
position: fixed;
background-color: red;
border-radius: 10px;
width: 100%;
min-width: 1024px;
height: 100px;
border-radius: 10px;
border: 4px solid white;
}
.left {
position: fixed;
float: left;
margin-top: 5px;
width: 30%;
height: 100%;
background-color: red;
margin-bottom: 10px;
border-radius: 10px;
border: 4px solid white;
}
.menuandtop { bgcolor: yellow; }
.main {
width: 90%;
margin: 0px;
height: 100%;
background-color: pink;
border-radius: 10px;
float: right;
}
a { text-decoration: none; }
.navmenu { list-style-type: none; }
.navmenu li a {
color: #2E2E2E;
font-family: arial;
font-face: arial;
font-weight: bold;
}
ul.navmenu a {
display: block;
text-decoration: none;
}
.navmenu li {
background: rgb(255,50,50);
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2ZmMzIzMiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjUwJSIgc3RvcC1jb2xvcj0iI2ZmNmQ2ZCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjUyJSIgc3RvcC1jb2xvcj0iI2ZmMjgyOCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNmZjAwMDAiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-linear-gradient(top, rgba(255,50,50,1) 0%, rgba(255,109,109,1) 50%, rgba(255,40,40,1) 52%, rgba(255,0,0,1) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(255,50,50,1)), color-stop(50%, rgba(255,109,109,1)), color-stop(52%, rgba(255,40,40,1)), color-stop(100%, rgba(255,0,0,1)));
background: -webkit-linear-gradient(top, rgba(255,50,50,1) 0%, rgba(255,109,109,1) 50%, rgba(255,40,40,1) 52%, rgba(255,0,0,1) 100%);
background: -o-linear-gradient(top, rgba(255,50,50,1) 0%, rgba(255,109,109,1) 50%, rgba(255,40,40,1) 52%, rgba(255,0,0,1) 100%);
background: -ms-linear-gradient(top, rgba(255,50,50,1) 0%, rgba(255,109,109,1) 50%, rgba(255,40,40,1) 52%, rgba(255,0,0,1) 100%);
background: linear-gradient(to bottom, rgba(255,50,50,1) 0%, rgba(255,109,109,1) 50%, rgba(255,40,40,1) 52%, rgba(255,0,0,1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ff3232', endColorstr='#ff0000', GradientType=0 );
filter: none;
height: 20%;
text-align: center;
}
.li1 { border-bottom: 1px solid #2E2E2E; }
.li2 { border-top: 1px solid #2E2E2E; }
.li3 {
border-top: 1px solid #2E2E2E;
border-bottom: 1px solid #2E2E2E;
}
HTML:
<body height="1000px" bgcolor="#2E2E2E">
<div class="menuandtop">
<div class="top"> </div>
<br>
<br>
<br>
<br>
<br>
<div class="left">
<ul class="navmenu">
<li class="li1">Home</li>
<li class="li3">Home</li>
<li class="li3">Home</li>
<li class="li3">Home</li>
<li class="li2">Home</li>
</ul>
</div>
</div>
<div class="footer"> </div>
</body>
There are a few way this can be achieved, one way is to create an invisible inline-block element with 100% height which the navigation is vertically aligned to. Change your CSS in the following way:
.left{
position: fixed;
float: left;
margin-top: 5px;
width: 30%;
height: 100%;
background-color: red;
margin-bottom: 10px;
border-radius: 10px;
border: 4px solid white;
font-size: 0;
}
Font size is set to 0 to remove white space.
.left:after {
content: "";
display: inline-block;
height: 100%;
vertical-align: middle;
width: 0;
}
The :after pseudo-element is used to create the invisible element.
.navmenu{
display: inline-block;
font-size: 16px;
list-style-type: none;
width: 100%;
}
The menu is then set to be inline-block and the font-size set to offset the zeroed font size in the parent element.
http://jsfiddle.net/D7V7p/
here you are:
http://jsfiddle.net/J7P2c/
just add the following code:
.left {
display:table;
}
.navmenu{
display:table-cell;
vertical-align:middle;
}
Update: updated fiddle,
although on firefox it worked fine, on chrome there seemed to be some kind of error produced by the height of the li, so remove the following:
.navmenu li{
height: 20%;
}
Updated fiddle: http://jsfiddle.net/Vr8cv/1/