How to create a straight line border [duplicate] - css

This question already has answers here:
set css border to end in a 90 instead of a 45 degree angle
(7 answers)
css outline left and right
(1 answer)
Closed 2 years ago.
I want to create a element that has a red border and a white right border but CSS creates a small diagonal cut out:
h1 {
border: 5px solid red;
border-right: 5px solid white;
}
Is there a way to make the lines go straight?
div {
width: 300px;
height: 100px;
background: #eee;
border-radius: 0px;
border-top: 0;
border-left: 0;
border-right: 0;
border-left: 6px solid #0b0;
border-top: 6px solid #0b0;
border-bottom: 6px solid #0b0;
border-right: 6px solid #fff;
margin: 10px;
}
<div></div>

Simply reduce the width of the right border.
I've added a background color to the div tags to emphasize where the content is drawn. Drawing a zero-width border will definitely affect the layout, but you could adjust for that by adding a margin-right.
#div1,
#div2,
#div3,
#div4 {
height: 100px;
width: 100px;
margin: 2px;
display: inline-block;
background-color: grey;
border: 5px solid red;
}
#div2 {
border-right-color: white;
}
#div3 {
border-right: 0px;
}
<div id="div1"></div>
<div id="div2"></div>
<div id="div3"></div>

Related

CSS how to draw arrow on vertical line [duplicate]

This question already has an answer here:
Html/Css Triangle with pseudo elements
(1 answer)
Closed 1 year ago.
How to add an arrow on the CSS vertical line by using just pure CSS?
My vertical line is just using the CSS border-right only, then I want to add a two-lines arrow on this line to make it like an arrow, like this:
<div class="ve-line"></div>
.ve-line{
border-right: 1px solid rgb(232, 232, 232);
}
You can create CSS triangle by using border than add another one larger triangle to create border like style and position it absolutly with right: -1px to place it on the line.
.ve-line{
border-right: 1px solid rgb(232, 232, 232);
height: 500px;
position: relative;
}
.triangle {
position: absolute;
right: -1px;
top: 100px;
}
.triangle:before,
.triangle:after {
content: "";
display: inline-block;
width: 0;
height: 0;
}
.triangle:before {
border-top: 22px solid transparent;
border-bottom: 22px solid transparent;
border-right: 22px solid rgb(232, 232, 232);
}
.triangle:after {
position: absolute;
right: 0;
top: 2px;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
border-right: 20px solid white;
}
<div class="ve-line">
<div class="triangle"></div>
</div>

how to create an extra border when div is created with css border already

I have created a div that looks like an arrow with css border.
.blue-arrow-right {
width: 0;
height: 0;
position: relative;
float: left;
margin-left: 0px;
margin-top: 5px;
border-top: 30px solid transparent;
border-bottom: 30px solid transparent;
border-left: 30px solid #009de1;
}
Now i want to create an extra border on the right side of that div, lets say: 1px solid black
How can i do that?
hers is the fiddle: https://jsfiddle.net/wqehc9vv/4/
So it should look like this:
image preview
You can use a pseudo-element like :before for that. And make it slightly bigger than the div. Also position it accordingly. See below
.blue-arrow-right {
width: 0;
height: 0;
position: relative;
float: left;
margin-left: 0px;
margin-top: 5px;
border-top: 30px solid transparent;
border-bottom: 30px solid transparent;
border-left: 30px solid #009de1;
}
.blue-arrow-right:before {
content:"";
position:absolute;
left:-30px;
top:-32px;
border-top: 32px solid transparent;
border-bottom: 32px solid transparent;
border-left: 32px solid black;
z-index:-1;
}
<div class="blue-arrow-right">
</div>

border colors change when applying border-radius to a zero-width element

I'm using border-top and border-left on a zero-width element to create a triangle.
.triangle {
border-top: solid 100px red;
border-left: solid 100px blue;
width: 0;
margin: 10px;
}
.borderRadius { border-radius: 10px; }
<div class="triangle"></div>
<div class="triangle borderRadius"></div>
However if a border-radius is applied to the element, the red border turns blue!! See JSfiddle here: https://jsfiddle.net/brentonstrine/3z3gqwts/
What is happening here? Is there a way to get a rounded-corner on my triangle?
To get a rounded border on your triangle you might have to declare all borders:
div {
border-top: solid 50px red;
border-right: solid 50px red;
border-left: solid 50px blue;
border-bottom: solid 50px blue;
width: 10px;
height: 10px;
}
DEMO

Draw a circle's sector using its borders

As shown below:
I want to draw a sector of a circle using borders only in order to make something like a chart, but if it's possible I don't want to use any plugins.
.circle {
background-color: transparent;
border: 4px solid #0c8a98;
border-radius: 100%;
height: 50px;
width: 50px;
}
<div class="circle"></div>
Do this. The border sides need to added individually.
.circle {
width: 50px;
height: 50px;
background-color: transparent;
border-top: none;
border-bottom: 4px solid #0c8a98;
border-left: 4px solid #0c8a98;
border-right: 4px solid #0c8a98;
border-radius: 100%;
}
<div class="circle"></div>

CSS triangles getting cut off

I'm trying to create some CSS triangles, using css and the :after pseudo class. Somehow, the up and down arrows are working properly, but the left and right arrows are being "cut off" (see fiddle: http://jsfiddle.net/K9vxN/ )
This is basically the css I'm using:
.arrow-right:after {
content:"";
border-top: 60px solid transparent;
border-bottom: 60px solid transparent;
border-left: 60px solid green;
}
Does anyone know why this is happening?
Make the :after pseudo element inline-block (or block). Currently it's an inline element, and it's size is based on the line height of the (empty) text it contains.
You'll have to fix some positioning then, though, but that should be trivial.
div { height:0px; }
div:after { content:""; display: block;}
.arrow-up:after {
margin-left: 50px; /* move right, to show it */
width: 0;
height: 0;
border-left: 15px solid transparent;
border-right: 15px solid transparent;
border-bottom: 15px solid black;
}
.arrow-down:after {
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-top: 20px solid #f00;
}
.arrow-right:after {
width: 0;
height: 0;
border-top: 60px solid transparent;
border-bottom: 60px solid transparent;
border-left: 60px solid green;
}
.arrow-left:after {
width: 0;
height: 0;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-right:10px solid blue;
}
<div class="arrow-up"></div>
<div class="arrow-down"></div>
<div class="arrow-left"></div>
<div class="arrow-right"></div>
http://jsfiddle.net/K9vxN/2/
By the way, you might not need to use :after at all, but that depends on whether you want the div to have an arrow or to be an arrow. That's up to you. ;)
Simply add display: block to all your :after selectors. For example
.arrow-up:after {
display: block; /* Added this */
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 5px solid black;
}
Here's a demo
Ensure the :after pseudo-element is specified as either block or inline-block, dependent upon your usage scenario.
div:after {
content:"";
display: block;
}
See http://jsfiddle.net/kFa6a/
your pseudo-element needs layout to be triggered:
you can set as display:block; or any other value of display but inline.
You can use as well float or position:absolute/fixed to trigger layout.
http://jsfiddle.net/K9vxN/5/
div:after {
content:"";
display:block;/* or table, inline-table,inline-block, but not inline*/
/* to your choice, where it suits design the best */
/* pick up here instead display*/
/*position:absolute;*//* or fixed */;
/* float:left;*//* or right */
}

Resources