How to make an up and down arrow - html

How can draw an up-down arrow with pure CSS?
This is what I get using HTML :
.up-down-arrow {
font-size: 50px;
color: #666;
padding: 0;
margin: 0;
display: inline-block;
}
<div class="up-down-arrow">↕</div>
But the line between the arrows is too short. Can I make it longer?
Ideally, this is what I am after:

Single element solution
You can achieve that with pseudo elements, CSS triangles and some positioning:
.arrow {
width: 2px;
height: 200px; /* <- adjust your height as you need it */
background: black;
margin: 10px;
position: relative;
}
.arrow::before,
.arrow::after {
content: '';
position: absolute;
left: -9px;
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
}
.arrow::before {
top: 0;
border-bottom: 15px solid black;
}
.arrow::after {
bottom: 0;
border-top: 15px solid black;
}
<div class="arrow"></div>
Multiple elements solution
To achieve the actual arrow shape, you will need multiple elements. Here the pseudo elements are used to create white triangles, that cut out the black arrow heads:
.arrow {
width: 2px;
height: 200px; /* <- adjust your height as you need it */
background: black;
margin: 10px;
position: relative;
}
.up, .down, .arrow::before, .arrow::after {
position: absolute;
left: -9px;
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
}
.up {
top: 0;
border-bottom: 15px solid black;
}
.down {
bottom: 0;
border-top: 15px solid black;
}
.arrow::before, .arrow::after {
content: '';
z-index: 2;
}
.arrow::before {
top: 11px;
border-bottom: 4px solid white;
}
.arrow::after {
bottom: 11px;
border-top: 4px solid white;
}
<div class="arrow">
<div class="up"></div>
<div class="line"></div>
<div class="down"></div>
</div>
Or another variant with a continuous line:
.line {
position: relative;
margin: -15px 0 -15px 9px;
width: 2px;
height: 180px;
background-color: black;
z-index: 5;
}
.up,
.down {
position: relative;
z-index: 3;
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
}
.up {
border-bottom: 15px solid black;
}
.down {
border-top: 15px solid black;
}
.down::before, .up::after {
position: absolute;
left: -10px;
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
content: '';
z-index: 4;
}
.down::before {
bottom: 11px;
border-top: 4px solid white;
}
.up::after {
top: 11px;
border-bottom: 4px solid white;
}
<div class="arrow">
<div class="up"></div>
<div class="line"></div>
<div class="down"></div>
</div>

To make the up-down arrows with the line in between the same as your example, I would suggest using SVG. You can use it inline as shown in the following example :
.wrap{
position:relative;
height:70vh;
border-left:1px solid #000;
margin:10vh 50px;
padding:5vh 20px;
}
.arrow {
position:absolute;
left:-5px;
width: 9px;
height: auto;
}
.up{top:-9px;}
.down{bottom:-9px;}
<div class="wrap">
<svg class="arrow up" viewbox="0 0 7 10">
<path d="M3.5 0 L7 10 Q3.5 7 0 10z"/>
</svg>
<svg class="arrow down" viewbox="0 0 7 10">
<path d="M3.5 10 L7 0 Q3.5 3 0 0z"/>
</svg>
Whatever content you need here
</div>
The inline SVG arrows are made with a path element and using one quadratic curve (made with Q3.5 7 0 10 in the up arrow).
The line between the arrows is made with a border left on a container div it expands with the height of this container.
Both arrows are positioned absolutely.

Here is one more solution using arrow char code \027A4 for ::before and ::after content.
Size of these chars has bound to root font size rem and their modification rotate, top and left based on the content font-size.
.arrow {
position: relative;
width: 3px;
height: 150px;
margin: 20px;
background: tomato;
}
.arrow::before,
.arrow::after {
content: '\027A4';
position: absolute;
font-size: 1.5rem;
color: tomato;
}
.arrow::before {
top: -.9em;
left: -.5em;
transform: rotate(-90deg);
}
.arrow::after {
bottom: -.9em;
left: -.32em;
transform: rotate(90deg);
}
<div class="arrow"></div>

To keep it simple, change the height style in mid class to increase the length of line!
.up {
width: 0px;
height: 0px;
border-bottom: 10px solid black;
border-left: 8px solid transparent;
border-right: 8px solid transparent;
border-top: none;
}
.mid {
margin-left:7px;
width: 2px;
height: 180px;
background-color:black;
}
.down{
width: 0px;
height: 0px;
border-top: 10px solid black;
border-left: 8px solid transparent;
border-right: 8px solid transparent;
border-bottom: none;
}
<div class='up'></div>
<div class='mid'></div>
<div class='down'></div>
Hope it helps!

Related

How do I change an active button's appearance to look like it has an arrow pointing

So I want to create a button that looks like this when it's active (you can see that it has a little arrow pointing to the right)
Currently I have something like that, it stays blue after clicked, text turns white and all that. I used .addClass for that, but I have no idea if I should use it again to glue on a triangle onto my button, there has to be a better way right?
While I'm at it, how can I make the shadow/sidebar?
Please, experienced people, give this beginner some enlightenment
add below css for
.active {
height: 50px;
width: 100px;
background: blue;
height: 50px;
width: 100px;
background: blue;
position: relative;
}
.active:after {
content: "";
border-right: 10px solid transparent;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 10px solid black;
height: 0;
width: 0;
position: absolute;
right: -20px;
top: 50%;
transform: translateY(-50%);
}
<div class="active"></div>
try
.active {
height: 50px;
width: 200px;
background: #0092ff;
}
.active:after {
content: "";
border-style: solid;
border-width: 10px 0 10px 10px;
border-color: transparent transparent transparent #0092ff;
display: block;
margin-left: 200px;
transform: translateY(75%);
}
.active:hover:after {
content: "";
border-left: 0px solid #0092ff;
transition: border-left 0.2s ease-in;
}
<div class="active"></div>
Please Check following working example.
$(function() {
$('.btn').click(function() {
$(this).closest('ul').find('.active').removeClass('active');
$(this).addClass('active');
});
});
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
li a {
padding: 10px;
background: teal;
position: relative;
display: block;
width: 60px;
cursor: pointer;
}
.active::after {
content: " ";
border-right: 10px solid transparent;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 10px solid teal;
height: 0;
width: 0;
position: absolute;
right: -20px;
top: 50%;
transform: translateY(-50%);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
<li><a class="btn active">Home</a></li>
<li><a class="btn">News</a></li>
<li><a class="btn">Contact</a></li>
<li><a class="btn">About</a></li>
</ul>
you need to add position:relative to the selector ul li.
after that, you can use the following code below to add content through the pseudo element after of the active link.
change the size of the borders, as well as positions for top and right to suit your needs.
ul li.active:after {
content: "";
width: 0;
height: 0;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
border-left: 20px solid #0092ff;
position:absolute;
top: 15px;
right:-15px;
}

Adding a triangle in css under another element

I have been trying hard without success to add a little triangle under my square to act as a pointer like this:
My code by itself works, but whenever I try to add css to make this triangle nothing will appear. I think it has to do with before-after functions, but I'm not really getting it. Anyone can help me with that?
<div id="slider_outer1">
<div class="slider_segment"><img src="myurl.com" alt="Nature" style="width:100%;"></div>
<div id="slider_marker1"></div>
</div>
<style>
.container {width:400px;}
#slider_outer1 {width: 98%;border: 5px solid #8f89ff; position: relative;display: inline-block; border-radius: 5px;}
.slider_segment {width: 100%; float: left; display: inline;}
#slider_marker1 {
position: absolute;
border: 2px solid #574fff;
height: 30px;
width: 5%;
top: 120px;
left: 57.25%;
text-align: center;
Margin-left: -10%;
padding: 5px 0px;
background: #ffffff;
border-radius: 5px;
}
div#slider_marker1:after {
content: "5";
font-size: 20px;
padding: 5px;
line-height: 30px;
font-family: sans-serif;
}
</style>
edit: code of the triangle
<div class="triangle-down"></div>
<style>
.triangle-down {
width: 0;
height: 0;
border-left: 15px solid transparent;
border-right: 15px solid transparent;
border-top: 20px solid #555;
}
</style>
Generally in CSS triangles are made using borders, not before and after pseudo elements. To create a downward pointing triangle, you would create a top border of n number of pixels, and left and right borders of half that width and also transparent.
Example:
<div id="slider_outer1">
<div class="slider_segment"><img src="myurl.png" alt="Nature" style="width:100%;"></div>
<div id="slider_marker1"><div id='triangle-down'></div></div>
</div>
<style>
.container {width:400px;}
#slider_outer1 {width: 98%;border: 5px solid #8f89ff; position: relative;display: inline-block; border-radius: 5px;}
.slider_segment {width: 100%; float: left; display: inline;}
#slider_marker1 {
position: absolute;
border: 2px solid #574fff;
height: 30px;
width: 5%;
top: 120px;
left: 57.25%;
text-align: center;
Margin-left: -10%;
padding: 5px 0px;
background: #ffffff;
border-radius: 5px;
}
#triangle-down {
position: absolute;
top: 40px;
right: 50%;
transform: translateX(50%);
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 20px solid blue;
}
div#slider_marker1:after {
content: "5";
font-size: 20px;
padding: 5px;
line-height: 30px;
font-family: sans-serif;
}
</style>
See my codepen here: https://codepen.io/anon/pen/bvXOab
You could add another div for the triangle like
<div id='triangle'></div>
Css For the triangle...
#triangle{
width: 0;
height: 0;
border-left: 40px solid transparent;
border-right: 40px solid transparent;
border-top: 80px solid blue;
}
However I feel that your problem is not that it just isnt appearing its that the positioning is messed up so its 'hidden' behind the sliders
I think I understand what you're trying to make. This should add a triangle above the marker. This solution should allow you to also remove anything related to triangle-down as it only requires the slider_marker1 div
#slider_marker1::before {
content: "";
width: 0;
height: 0;
position: absolute;
top: -6px;
left: 0;
right: 0;
margin: auto;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-bottom: 4px solid green;
z-index: 100;
}

How to create play button with border-radius?

Hi I'm trying to make a Pomodoro clock. I've made a play button by removing border-right and increasing border-left width to create a triangle.
My questions is - how do I apply border-radius to it?
https://codepen.io/jenlky/pen/ypQjPa?editors=1100
<div id="all-buttons" class="buttons">
<!-- play button -->
<div id="play" class="play-button"></div>
<!-- pause button -->
<div id="pause">
<div class="line-1"></div>
<div class="line-2"></div>
</div>
<!-- end of play and pause button-->
</div>
.play-button {
z-index: 2;
width: 48px;
height: 48px;
border-style: solid;
border-width: 24px 0px 24px 48px;
border-color: white white white #FF8F83;
}
HTML play button:
.circle_inner{
position: relative;
height: 100%;
}
.circle_inner:before{
content: "";
display: block;
width: 0;
height: 0;
border-style: solid;
border-width: 10px 0 10px 20px;
border-color: transparent transparent transparent #000;
position: absolute;
top: 50px;
left: 50%;
margin: -10px 0 0 -7px;
}
<div class="circle_inner">
</div>
Try this (Less)
<div class="control play">
<span class="left"></span><span class="right"></span>
</div>
.control {
#color: #ffb160;
#highlight: darken(#color, 10%);
#duration: 0.4s;
#sin: 0.866;
#size: 112px;
border-radius: 50%;
margin: 20px;
padding: #size*0.25;
width: #size;
height: #size;
font-size: 0;
white-space: nowrap;
text-align: center;
cursor: pointer;
&, .left, .right, &:before {
display: inline-block;
vertical-align: middle;
transition: border #duration, width #duration, height #duration, margin #duration;
transition-tiomig-function: cubic-bezier(1, 0, 0, 1);
}
&:before {
content: "";
height: #size;
}
&.pause {
.left, .right {
margin: 0;
border-left: #size*0.33 solid #color;
border-top: 0 solid transparent;
border-bottom: 0 solid transparent;
height: #size*#sin;
}
.left {
border-right: #size*0.2 solid transparent;
}
}
&.play {
#border: #size/4;
.left {
margin-left: #size/6;
border-left: #size*#sin/2 solid #color;
border-top: #border solid transparent;
border-bottom: #border solid transparent;
border-right: 0px solid transparent;
height: #size - 2*#border;
}
.right {
margin: 0;
border-left: #size*#sin/2 solid #color;
border-top: #border solid transparent;
border-bottom: #border solid transparent;
height: 0px;
}
}
&:hover {
border-color: #highlight;
.left, .right {
border-left-color: #highlight;
}
}
}

How to create text stroke and triangle with pure CSS?

I am trying to create a css design like the image attached below. Actually I need to create this style only using CSS without using any images.
I tried get it to work but not sure How to create inner triangle.
This is my HTML -
body {
background: #cdc6e1;
}
.content-box {
background: #28166f;
width: 250px;
height: 100px;
}
.tag {
background: #f8c300;
width: 100px;
height: 0;
padding-left: 10%;
padding-bottom: 10%;
overflow: hidden;
}
.tag:after {
content: "";
display: block;
width: 0;
height: 0;
margin-left: -500px;
border-left: 500px solid transparent;
border-right: 500px solid transparent;
border-bottom: 500px solid #f8c300;
}
<div class="content-box">
<div class="tag">
<h1>1<span>st</span></h1>
</div>
<div class="name">
<h1>First<br>
Place</h1>
</div>
</div>
Hope somebody may help me out to achieve to this custom style.
Thank you.
A basic mockup would be to use some pseudo elements in order to generate this:
.outer {
height: 200px;
width: 400px;
background: purple;
border: 10px solid pink;
position: relative;
text-Align: right;
font-size: 50px;
line-height: 200px;
}
.outer:before,
.outer:after {
height: 0;
width: 0;
position: absolute;
content: "";
border-bottom: 100px solid yellow;
border-right: 70px solid transparent;
border-left: 70px solid transparent;
bottom: 0;
left: 20px;
z-index: 8;
}
.outer:after {
border-bottom: 130px solid blue;
border-right: 90px solid transparent;
border-left: 90px solid transparent;
z-index: 0;
}
.place {
position: absolute;
left: 50px;
color: red;
bottom: -20px;
font-size: 100px;
line-height: initial;
z-index: 10;
text-shadow:
3px 3px 0 white,
/* Simulated effect for Firefox and Opera
and nice enhancement for WebKit */
-1px -1px 0 white,
1px -1px 0 white,
-1px 1px 0 white,
1px 1px 0 white;
}
<div class="outer">First Place
<div class="place">1st</div>
</div>
Note. The text outline property is yet to be implemented in any of the major browsers yet, so it may require a 'larger white text' to be positioned behind to create this text outline in your mockup.
A workaround (as stateed in the comments) would be to 'hack' the text shadow:
text-shadow:
3px 3px 0 white, /* Simulated effect for Firefox and Opera
and nice enhancement for WebKit */
-1px -1px 0 white,
1px -1px 0 white,
-1px 1px 0 white,
1px 1px 0 white;
Text Stroke
Although only available in webkit broswers, you may possibly want to use text-stroke for your 'white border' to the text (unavailable in IE or Firefox)
div {
font-size: 50px;
position: relative;
height: 50px;
width: 50px;
color: black;
}
div:before {
content: "1st";
z-index: -1;
left: 0;
top: 0;
position: absolute;
-webkit-text-fill-color: black;
-webkit-text-stroke: 8px red;
}
html {
background: gray;
}
<div>
1st
</div>
<br/>
<strong>Note</strong> only available in webkit browsers
Create a duplicate triangle and place it behind. Code given below. JSBin: http://jsbin.com/totewinizu/2/
HTML:
.tag {
width: 100px;
display: block;
position: relative;
top: 20px;
border-color: transparent transparent red transparent;
border-style: solid;
border-width: 0px 60px 80px 60px;
height: 0px;
width: 0px;
z-index: 99;
}
.dupe {
position: absolute;
border-color: transparent transparent white transparent;
border-style: solid;
border-width: 0px 60px 80px 60px;
top: 40px;
left: 20px;
z-index: 9;
}
<div class="content-box">
<div class="tag">
<h1>1</h1><span>st</span>
</div>
<div class='tag dupe'>
</div>
<div class="name">
<h1>First<br>
Place</h1>
</div>
</div>

Achieving arrow-like shapes in a banner in CSS

I want to achieve the following shapes using pure CSS, no images.
I've come to the following point.
Here is the HTML structure:
<div class="sixteen columns">
<div id="applicationStatus">
<ul>
<li class="applicationStatus">Application Received</li>
<li class="applicationStatusGood">Language Exam</li>
<li class="applicationStatusNoGood">Oral Exam</li>
<li class="applicationStatus">Grant</li>
</ul>
</div>
</div>
And here is the CSS:
#applicationStatus {
position: relative;
width: auto;
height: 140px;
left: 40px; }
ul.applicationStatus {
list-style: none; }
li.applicationStatus, li.applicationStatusGood, li.applicationStatusNoGood {
height: 140px;
background-color: #767676;
display: inline-block;
/* Dirty IE Hack */
zoom: 1;
*display: inline;
margin-right: 30px;
margin-left: 30px;
padding: 10px;
color: white;
font-size: 18px;
text-align: center;
line-height: 150px;
/* vertical-align: middle; */ }
li.applicationStatus:after, li.applicationStatusGood:after, li.applicationStatusNoGood:after {
content: "";
position: absolute;
width: 0;
height: 0;
border-top: 80px solid transparent;
border-left: 30px solid #767676;
border-bottom: 80px solid transparent;
margin: -10px 90px 0 10px; }
li.applicationStatus:before, li.applicationStatusGood:before, li.applicationStatusNoGood:before {
content: "";
position: absolute;
width: 0;
height: 0;
left: 0px;
border-top: 80px solid transparent;
border-left: 30px solid white;
border-bottom: 80px solid transparent;
margin: -10px 0px 0 0px; }
li.applicationStatus:first-child, li.applicationStatusGood:first-child, li.applicationStatusNoGood:first-child {
margin-left: 0px;
text-indent: 30px; }
li.applicationStatus:last-child, li.applicationStatusGood:last-child, li.applicationStatusNoGood:last-child {
border-top: 0px solid transparent;
border-left: 0px solid transparent;
border-bottom: 0px solid transparent; }
li.applicationStatusGood {
background-color: #77a942; }
li.applicationStatusGood:after {
border-left: 30px solid #77a942; }
li.applicationStatusNoGood {
background-color: #c42c00; }
li.applicationStatusNoGood:after {
border-left: 30px solid #c42c00; }
Why doesn't the :before selector apply to all of the shapes or all in all how can I achieve what I want?
Modification of Your Code
The main issue you faced was not having position: relative on your li elements. But there were other things that needed tweaking too.
Here is a fiddle example to see.
I added the class you failed to reference in your HTML above to the ul element, so here is the HTML:
<div class="sixteen columns">
<div id="applicationStatus">
<ul class="applicationStatus">
<li class="applicationStatus">Application Received</li>
<li class="applicationStatusGood">Language Exam</li>
<li class="applicationStatusNoGood">Oral Exam</li>
<li class="applicationStatus">Grant</li>
</ul>
</div>
</div>
Then I modified your CSS a bit to condense it (could be more condensed if CSS3 only was being supported):
#applicationStatus {
position: relative;
width: auto;
height: 140px;
left: 40px; }
.applicationStatus li { /* Added this and moved much code to here */
position: relative; /* this was a key property missing from your code */
text-indent: 30px;
height: 140px;
background-color: #767676;
display: inline-block;
/* Dirty IE Hack */
zoom: 1;
*display: inline;
/* margin-right: 30px; Eliminated this */
margin-left: 30px;
padding: 10px 10px 10px 30px; /* tweaked this */
color: white;
font-size: 18px;
text-align: center;
line-height: 150px;
}
ul.applicationStatus { /* this was irrelevant with the HTML you gave, but I added the class to the ul */
list-style: none; }
/* tweaked various things below here */
li.applicationStatus:first-child:after, li.applicationStatusGood:after, li.applicationStatusNoGood:after {
content: "";
position: absolute;
width: 0;
height: 0;
border-top: 80px solid transparent;
border-left: 30px solid #767676;
border-bottom: 80px solid transparent;
margin: -10px 90px 0 10px;
}
li.applicationStatus:last-child:before, li.applicationStatusGood:before, li.applicationStatusNoGood:before {
content: "";
position: absolute;
width: 0;
height: 0;
left: 0;
border-top: 80px solid transparent;
border-left: 30px solid white;
border-bottom: 80px solid transparent;
margin: -10px 0px 0 0px;
}
li.applicationStatus:first-child {
padding-left: 10px;
margin-left: 0;
}
li.applicationStatus:last-child {
padding-right: 30px;
}
li.applicationStatusGood {
background-color: #77a942; }
li.applicationStatusGood:after {
border-left: 30px solid #77a942; }
li.applicationStatusNoGood {
background-color: #c42c00; }
li.applicationStatusNoGood:after {
border-left: 30px solid #c42c00; }
U can try this website.
http://cssarrowplease.com/
.arrow_box {
position: relative;
background: #88b7d5;
border: 8px solid #c2e1f5;
}
.arrow_box:after, .arrow_box:before {
left: 100%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
.arrow_box:after {
border-color: rgba(136, 183, 213, 0);
border-left-color: #88b7d5;
border-width: 30px;
top: 50%;
margin-top: -30px;
}
.arrow_box:before {
border-color: rgba(194, 225, 245, 0);
border-left-color: #c2e1f5;
border-width: 41px;
top: 50%;
margin-top: -41px;
}