CSS - Arrow not lining up - html

I am trying tro create a pure CSS arrow with a line like this...
.arrow {
position:absolute;
left:50%;
}
.arrow_line {
width:2px;
background:darkblue;
height:60px;
margin:auto;
}
.arrow_point {
box-sizing: border-box;
height: 25px;
width: 25px;
border-style: solid;
border-color: darkblue;
border-width: 0px 2px 2px 0px;
transform: rotate(45deg);
transition: border-width 150ms ease-in-out;
margin-top: -24px;
}
<div class="arrow">
<div class="arrow_line"></div>
<div class="arrow_point"></div>
</div>
The vertical line never quite seems to line up vertically with the arrow, I have left it slightly adrift in the example to better demonstrate that it is not centered in relation to the arrow.
Is there a better way to create a CSS arrow?

You can use one element and gradient then you won't have issue with centring:
.arrow {
width:80px;
height:80px;
background:
linear-gradient(blue,blue) bottom right/40px 4px,
linear-gradient(blue,blue) bottom right/4px 40px,
linear-gradient(
to top right,
transparent calc(50% - 2px),
blue calc(50% - 2px),
blue calc(50% + 2px),
transparent calc(50% + 2px));
background-repeat:no-repeat;
transform:rotate(45deg);
margin:20px;
}
<div class="arrow">
</div>
You can also easily adjust the size:
.arrow {
width:var(--s,80px);
height:var(--s,80px);
background:
linear-gradient(blue,blue) bottom right/calc(var(--s,80px)/2) calc(var(--t,2px)*2),
linear-gradient(blue,blue) bottom right/calc(var(--t,2px)*2) calc(var(--s,80px)/2),
linear-gradient(
to top right,
transparent calc(50% - var(--t,2px)),
blue calc(50% - var(--t,2px)),
blue calc(50% + var(--t,2px)),
transparent calc(50% + var(--t,2px)));
background-repeat:no-repeat;
transform:rotate(45deg);
margin:20px;
display:inline-block;
}
<div class="arrow">
</div>
<div class="arrow" style="--t:3px;--s:60px">
</div>
<div class="arrow" style="--t:1px;--s:40px">
</div>
<div class="arrow" style="--t:2px;--s:20px">
</div>
<div class="arrow" style="--t:1px;--s:20px">
</div>

Give your line a width which is odd. You used 2px on the line, and that resulted in the line being slightly off to one side.
I made it 3px as example.
Or vice versa, make your "point" an even number, which may make more sense, since you'll want the lines to have the same thicckness.
.arrow {
position:absolute;
left:50%;
}
.arrow_line {
width:2px;
//width: 3px;
background:darkblue;
height:60px;
margin:auto;
}
.arrow_point {
box-sizing: border-box;
height: 26px;
//height: 25px;
width: 26px;
//width: 25px;
border-style: solid;
border-color: darkblue;
border-width: 0px 2px 2px 0px;
transform: rotate(45deg);
transition: border-width 150ms ease-in-out;
margin-top: -24px;
}
<div class="arrow">
<div class="arrow_line"></div>
<div class="arrow_point"></div>
</div>

Since you arrow point is 25px wide, it won't line up. Because 25 isn't an even number.
Change it to 24 like below or any other even number.
.arrow {
position:absolute;
left:50%;
}
.arrow_line {
width:2px;
background:darkblue;
height:60px;
margin:auto;
}
.arrow_point {
box-sizing: border-box;
height: 24px;
width: 24px;
border-style: solid;
border-color: darkblue;
border-width: 0px 2px 2px 0px;
transform: rotate(45deg);
transition: border-width 150ms ease-in-out;
margin-top: -24px;
}
<div class="arrow">
<div class="arrow_line"></div>
<div class="arrow_point"></div>
</div>

.arrow {
position:relative;
height:30px;
width:2px;
background:red;
}
.arrow:after{
position: absolute;
content: '';
height: 10px;
width: 10px;
transform: rotate(45deg) translateX(-65%);
border: 2px solid red;
border-top: none;
border-left: none;
bottom: -20%;
left: 50%;
}
<div class="arrow">
</div>
working randomly change height width of after

Make it simple by using unicode arrow instead of creating it.
.arrow{
color:red;
font-size:70px;
}
<div class="arrow">↓</div>

You just need to make two small changes to your code:
1) delete the css for .arrow
2) for .arrow_point change margin-top to margin:-24px auto;
if you want to you can delete the < div class='arrow' >
simple solutions are best!
.arrow {
/*position:absolute;
left:50%;*/
}
.arrow_line {
width:2px;
background:darkblue;
height:60px;
margin:auto;
}
.arrow_point {
box-sizing: border-box;
height: 25px;
width: 25px;
border-style: solid;
border-color: darkblue;
border-width: 0px 2px 2px 0px;
transform: rotate(45deg);
transition: border-width 150ms ease-in-out;
/*margin-top: -24px;*/
margin:-24px auto;
}
<div class="arrow">
<div class="arrow_line"></div>
<div class="arrow_point"></div>
</div>

Related

Adding border to webkit-mask-image

I have two containers and I want to link them with a negative-rounded-ish div : JSFIddle
HTML:
<div class="div"></div>
<div class="d-flex">
<div class="p1"></div>
<div class="p2"></div>
</div>
<div class="div"></div>
CSS:
.div {
background:#e0e0e0;
border:solid 1px red;
padding:10px;
border-radius:5px
}
.p1 {
background:#e0e0e0;
width: 25px;height: 10px;
-webkit-mask-image: radial-gradient(circle at left, transparent 0, transparent 19px, black 0px);
}
.d-flex { display:flex }
.p2 {
background:#e0e0e0;
width: 25px; height: 10px;
-webkit-mask-image: radial-gradient(circle at right, transparent 0, transparent 19px, black 0px);
}
Preview:
I want to know if I can extend borders to get sth like this
CSS tricks with before & after pseudo might help!
.div {
background:#e0e0e0;
border:solid 1px red;
padding:10px;
border-radius:5px
}
.join {
margin-left: 20px;
background:#e0e0e0;
width: 20px;
height: 10px;
overflow:hidden;
position:relative;
z-index:1;
margin-top:-1px;
margin-bottom: -1px;
}
.join:before, .join:after{
content: '';
height: 8px;
width: 10px;
position:absolute;
border-radius:10px;
border:1px solid red;
background-color:#fff;
}
.join:before{
left:-5px;
border-left: 0;
}
.join:after{
right:-5px;
border-right: 0;
}
<div class="div"></div>
<div class="join"></div>
<div class="div"></div>

CSS-only ribbon with skewed bottom corner

What i'm trying to achieve is to create a purely-CSS ribbon which will:
adapt to the included text (working),
floated to the left of container (working),
have a skewed bottom right corner like on below img:
This is my code - HTML:
<div class="container">
<div class="ribbon left_ribbon"><h2>Testing</h2></div>
</div>
and CSS:
.container {
width:80%;
background:grey;
display:block;
min-height:500px;
margin:0 auto;
}
.ribbon{
color: #fff;
margin: 30px 0 50px;
position: relative;
text-transform: uppercase;
background: rgb(0, 164, 239);
box-shadow: 0px 1px 3px rgba(0,0,0,.2);
padding: 10px 15px;
clear: both;
}
div.left_ribbon{
color: #000;
margin-left: -10px;
float: left;
}
div.left_ribbon h2{
margin: 0 12px;
color:#fff;
}
div.left_ribbon::before{
display: block;
width: 10px;
height: 0px;
position: absolute;
bottom: -10px;
left: -10px;
content: "";
border-bottom: 10px solid transparent;
border-right: 10px solid rgb(0, 80, 116);
}
is it doable via CSS or I have to use SVG file?
clip-path can do it easily:
.box {
width:200px;
height:100px;
margin:50px;
position:relative;
background:grey;
}
.box:before {
content:"Ribbon";
font-size:25px;
padding:5px 25px 10px;
position:absolute;
top:10px;
left:-5px;
background:
linear-gradient(#000 0 0) bottom/100% 5px no-repeat
#00a4ef;
clip-path:polygon(0 0,100% 0,80% calc(100% - 5px),5px calc(100% - 5px),5px 100%,0 calc(100% - 5px))
}
<div class="box">
</div>
With some CSS variables to easily control:
.box {
--s:10px; /* skewed part */
--o:5px; /* offset part */
--c:#00a4ef; /* color */
width:200px;
height:100px;
display:inline-block;
margin:5px;
position:relative;
background:grey;
}
.box:before {
content:attr(data-text);
font-size:25px;
padding:5px calc(10px + var(--s)) calc(5px + var(--o)) calc(10px + var(--o));
position:absolute;
top:10px;
left:calc(-1*var(--o));
background:
linear-gradient(#000 0 0) bottom/100% var(--o) no-repeat
var(--c);
clip-path:polygon(0 0,100% 0,calc(100% - var(--s)) calc(100% - var(--o)),var(--o) calc(100% - var(--o)),var(--o) 100%,0 calc(100% - var(--o)))
}
<div class="box" data-text="test"></div>
<div class="box" data-text="another test" style="--c:red;--o:10px;--s:25px"></div>
<div class="box" data-text="another one" style="--c:yellow;--o:0px;--s:40px"></div>
Please modify your CSS as below. pseudo after CSS added making it skewed form bottom right corner and, modified box-shadow from .ribbon for removing visible shadow of skewed area.
.container {
width:80%;
background:grey;
display:block;
min-height:500px;
margin:0 auto;
}
.ribbon{
color: #fff;
margin: 30px 0 50px;
position: relative;
text-transform: uppercase;
background: rgb(0, 164, 239);
box-shadow: 0px 1px 3px rgb(0 0 0 / 0%);
padding: 10px 15px;
clear: both;
}
div.left_ribbon{
color: #000;
margin-left: -10px;
float: left;
}
div.left_ribbon h2{
margin: 0 12px;
color:#fff;
}
div.left_ribbon::before{
display: block;
width: 10px;
height: 0px;
position: absolute;
bottom: -10px;
left: -10px;
content: "";
border-bottom: 10px solid transparent;
border-right: 10px solid rgb(0, 80, 116);
}
div.left_ribbon::after{
content: '';
position: absolute;
top: 0;
right: 0;
border-bottom: 47px solid grey;
border-left: 23px solid rgb(0, 164, 239);
width: 0;
}
<div class="container">
<div class="ribbon left_ribbon"><h2>Testing</h2></div>
</div>

CSS3 for Curve Symbol

Im looking for css code for below shape, i have tried using border radius but have to work with different div's for top border and left curve.
Im looking for css which draws complete shape below. Any help ?
.Curve{
top: 25px;
left: 25px;
width: 50px;
border: solid 1px #4C5D65;
height: 86px;
content: " ";
padding: 0px;
position: absolute;
transform: rotate(271deg);
border-color: transparent transparent #4C5D65 transparent;
border-radius: 0 0 51px 99%/44px;
}
<span class="Curve"> </span>
Here is what i have tried
https://jsfiddle.net/sonymax46/wdaLomnf/3/
Here is an idea with one element. Simply adjust the gradient until you get what you want.
.curve {
width:100px;
height:50px;
border-top:2px solid;
background:
radial-gradient(100% 57% at left,transparent calc(100% - 2px),#000,transparent 100%)
left/15px 100% no-repeat;
}
<div class="curve"></div>
Another idea:
.curve {
width:100px;
height:50px;
border-top:2px solid;
position:relative;
overflow:hidden;
}
.curve:before {
content:"";
position:absolute;
width:80px;
height:80px;
border-radius:50%;
top:calc(50% - 40px);
right:calc(100% - 12px);
border:2px solid;
box-sizing:border-box;
}
<div class="curve"></div>
Maybe change
border-color: transparent transparent #4C5D65 transparent; to
border-color: #4C5D65 transparent #4C5D65 transparent;
or add an element above, make the margins of both equal to zero, and then make the bottom border the same colour.
Hope this help you.
.Curve {
top: 25px;
left: 25px;
width: 50px;
border: solid 1px #4C5D65;
height: 86px;
content: " ";
padding: 0px;
position: absolute;
transform: rotate(271deg);
border-color: transparent transparent #4C5D65 transparent;
border-radius: 0 0 51px 99%/44px;
}
span.Curve:after {
position: absolute;
content: '';
height: 100%;
width: 100%;
border-right: 1px solid #21262D;
top: 92%;
left: -6px;
/* background: rebeccapurple; */
}
<span class="Curve"></span>

create hr with css and html with arrow bottom left

I need some help.
How can I display the html code according to the attached image.
I tried modifying the css, but it's not ok
div {
margin:50px;
background-color: #c1c1c1;
border:#000 solid 1px;
position:relative;
}
div:after{
content:'';
width:24px;
height:24px;
background:#fff;
position:absolute;
-moz-transform:rotate(45deg);
-webkit-transform:rotate(45deg);
transform:rotate(45deg);
top:-12px;
left:50px;
border-right:#000 solid 2px;
border-bottom:#000 solid 2px;
}
<div></div>
Thank You
A bit of transform:skew() does it.
Unless you're targeting very old browsers, it's no longer necessary to include the vendor-specific prefixes on these rules; they're broadly supported. (Mozilla/Firefox and IE haven't needed the prefixes for 2d transforms since 2012; Safari since 2015).
div {
margin:50px;
background-color: #c1c1c1;
border:#000 solid 1px;
position:relative;
}
div:after{
content:'';
width:24px;
height:24px;
background:#fff;
position:absolute;
top:-12px;
left:50px;
border-bottom:#000 solid 2px;
border-left:#000 solid 2px;
transform:skew(0,-45deg)
}
<div></div>
Here is another way to have transparency:
div {
margin: 50px;
height: 2px;
background: linear-gradient(to right, #000 44px, transparent 44px, transparent 60px, #000 60px);
position: relative;
}
div:before,
div:after {
content: '';
width: 2px;
position: absolute;
top: 2px;
background: #000;
}
div:after {
height: 26px;
transform-origin: top right;
transform: rotate(45deg);
left: 60px;
}
div:before {
height: 19px;
top: 0px;
left: 42px;
}
body {
background: pink
}
<div></div>

How to put text on a CSS Triangle

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>