Create corner border in CSS [duplicate] - html

This question already has answers here:
Any way to limit border length?
(10 answers)
Closed 5 years ago.
How can I create the "blue" and "orange" corners in CSS, like in this image:
Thanks

You can use :before and :after pseudo-classes like this:
div {
position: relative;
width: 100px;
height: 100px;
margin: 20px;
border: 1px solid #000;
}
div:after {
display: block;
content: "";
width: 20px;
height: 20px;
position: absolute;
top: -5px;
right: -5px;
border-top: 3px solid blue;
border-right: 3px solid blue;
}
span:before {
display: block;
content: "";
width: 20px;
height: 20px;
position: absolute;
bottom: -5px;
left: -5px;
border-bottom: 3px solid orange;
border-left: 3px solid orange;
}
<div><span></span></div>

If you're going to use 'before' and 'after' elements only one HTML tag is required ie. the outermost div in this case and call up the before and after elements on this element. Extra tags add up on the renderer load.
div {
position: relative;
width: 100px;
height: 100px;
margin: 20px;
border: 1px solid #bbb;
}
div:after {
display: block;
content: "";
width: 20px;
height: 20px;
position: absolute;
top: -5px;
right: -5px;
border-top: 3px solid blue;
border-right: 3px solid blue;
}
div:before {
display: block;
content: "";
width: 20px;
height: 20px;
position: absolute;
bottom: -5px;
left: -5px;
border-bottom: 3px solid red;
border-left: 3px solid red;
}
<div></div>

try this
div{
box-sizing:border-box;
}
div.outer{
height:150px;
width:150px;
position:relative;
background:#fff;
padding:2px;
}
div.inner {
border:1px solid #d6d6d6;
height:100%;
width:100%;
}
div.outer:before{
content:"";
background:#F87200;
width:25px;
height:25px;
position:absolute;
bottom:-5px;
left:-5px;
display:block;
z-index: -1;
}
div.outer:after{
content:"";
background:#0092D4;
width:25px;
height:25px;
position:absolute;
top:-5px;
right:-5px;
display:block;
z-index: -1;
}
<div class="outer">
<div class="inner"></div>
</div>

Related

How to create CSS border corners around text [duplicate]

This question already has answers here:
How can I show only corner borders?
(20 answers)
Closed 4 years ago.
I can't seem to figure out how to put corner borders around responsive text.
Screenshot of what I'm trying to achieve using green corners:
Here is the domain of where the text resides.
div {
position: relative;
width: 380px;
height: 0px;
margin: 6px;
}
div:after {
display: block;
content: "";
width: 75px;
height: 75px;
position: absolute;
top: -5px;
right: -5px;
border-top: 4px solid green;
border-right: 4px solid green;
}
a p:before {
display: block;
content: "";
width: 75px;
height: 75px;
position: absolute;
bottom: -70px;
left: -6px;
border-bottom: 4px solid green;
border-left: 4px solid green;
}
h1 {
display: inline-block;
position: relative;
padding: 10px;
}
h1:before,
h1:after {
height: 14px;
width: 14px;
position: absolute;
content: '';
}
h1:before {
right: 0;
top: 0;
border-right: 3px solid #9b59b6;
border-top: 3px solid #9b59b6;
}
h1:after {
left: 0;
bottom: 0;
border-left: 3px solid black;
border-bottom: 3px solid black;
}
<h1>TEXT</h1>
Absolute positioning and height & width of before and after are the key.
Change a p:before to div:before and that should get you on the right path.

Draw dashed border inside the custom shape using HTML & CSS

I have to code a shape(below image) in HTML
And below is the code what I tried so far:
body {
font: 13px Verdana;
}
h3 {
height: 100px;
background: #72bbab;
border-radius: 50px 10px 10px 50px;
display: flex;
margin-top: 50px;
position: relative;
line-height: 100px;
color: #ffffff;
font-size: 13px;
font-weight: normal;
}
h3 i {
width: 130px;
height: 130px;
transform: translateY(-15px);
background: #71bbab;
border-radius: 50%;
position: relative;
margin-right: 20px;
}
h3:before {
content: "";
position: absolute;
border: 1px dashed #fff;
top: 5px;
bottom: 5px;
left: 20px;
right: 2px;
border-radius: 10px;
}
h3 i:before {
content: "";
position: absolute;
top: 5px;
bottom: 5px;
left: 5px;
right: 5px;
border: 1px dashed #fff;
border-radius: 50%;
}
<h3><i></i>Text</h3>
Now the issue is I am not able to remove dashed border of circle from right side. I tried border-top:0 and border-right:0 but didn't work.
Thanks in advance
Note: Don't want to use any king of image
If you need to get the output by keeping same HTML mark-up then you have to use many pseudo selectors, CSS calc() function to calculate h2 tag width and many such properties to get output using CSS.
You have too even use position and z-index to hide circle border backside of h2 tag. And using margin you could arrange the remaining, so at one point whole diagram connects.
body {
font: 13px Verdana;
}
h3{
background:#72bbab;
width:calc(100% - 95px);
height:85px;
margin-left:95px;
margin-top:21px;
display:flex;
justify-content:flex-start;
align-items:center;
border-top-right-radius:10px;
border-bottom-right-radius:10px;
padding-left:20px;
box-sizing:border-box;
color:#fff;
}
h3 i{
width:120px;
height:120px;
background:#72bbab;
border-radius:50%;
display:inline-block;
top:2px;
left:2px;
position:absolute;
z-index:-1;
overflow:hidden;
}
h3 i:before{
content:"";
width:100px;
height:100px;
border:2px dashed #fff;
position:absolute;
top:8px;
left:8px;
border-radius:50%;
}
h3:before{
content:"";
width:calc(100% - 120px);
height:65px;
border:2px dashed #fff;
position:absolute;
right:15px;
border-top-right-radius:10px;
border-bottom-right-radius:10px;
}
h3:after{
content:"";
width:3px;
height:68px;
background:#72bbab;
position:absolute;
top:28px;
margin-left:-61px;
}
<h3><i></i>Text</h3>
See if this helps.
https://jsfiddle.net/induprakash/8ofLjqxm/
I added a higher z-index to rectangle border.
body {
font: 13px Verdana;
}
h3 {
height: 100px;
background: #72bbab;
border-radius: 50px 10px 10px 50px;
display: flex;
margin-top: 50px;
position: relative;
line-height: 100px;
color: #ffffff;
font-size: 13px;
font-weight: normal;
}
h3 i {
width: 130px;
height: 130px;
transform: translateY(-15px);
background: #71bbab;
border-radius: 50%;
position: relative;
margin-right: 20px;
}
h3:before {
content: "";
position: absolute;
border: 1px dashed #fff;
top: 5px;
bottom: 5px;
left: 105px;
z-index: 10;
right: 2px;
border-radius: 0px;
border-left: 0;
}
h3 i:before {
content: "";
position: absolute;
top: 5px;
bottom: 5px;
left: 5px;
right: 5px;
border: 1px dashed #fff;
border-radius: 50%;
border-right : 1px solid #72bbab;
}
Try this one, its running as per your image. I have tried a simple and different approach.
JSFiddle Link - https://jsfiddle.net/deepak104080/uwx873x1/
.circle {
width:130px;
height:130px;
border-radius:65px;
position:absolute;
z-index:100;
background:#71bbab;
margin:0px;
padding:0px;
}
.innercircle {
width:110px;
height:110px;
border-radius:55px;
position:absolute;
top:9px;
left:9px;
z-index:100;
background:#71bbab;
border: 1px dashed #fff;
}
.tab {
height: 100px;
position:absolute;
margin-top:15px;
margin-left:105px;
z-index:1000;
width:350px;
background:#71bbab;
border-top-right-radius:10px;
border-bottom-right-radius:10px;
}
.innertab {
height: 78px;
position:absolute;
margin-top:10px;
margin-left:0px;
z-index:1000;
width:340px;
background:#71bbab;
border-top-right-radius:10px;
border-bottom-right-radius:10px;
border-top: 1px dashed #fff;
border-bottom: 1px dashed #fff;
border-right: 1px dashed #fff;
}
<div>
<div class="circle">
<div class="innercircle">
</div>
</div>
<div class="tab">
<div class="innertab">
</div>
</div>
</div>
Use the ::after pseudo for h3 element.
h3:after {
z-index: 9999;
position:absolute;
max-width: 100%;
width: 100px;
height: 87px;
background: #71bbab;
content: '';
left: 35px;
margin-top: 6px;
}
https://jsfiddle.net/apyupfwo/

How to make rectangle's border different?

HTML:
<div class="rectangle">Some text</div>
CSS:
.rectangle {
width: 300px;
height: 80px;
border: 5px solid red;
}
Is there any way to make div looks like in the photo?
You can use ::after and ::before to achieve the result.
.rectangle {
width: 300px;
height: 80px;
border: 5px solid red;
border-right: none;
position: relative;
}
/* for the triangular shape */
.rectangle::after {
content: "";
position: absolute;
right:-45px;
bottom: 0;
top:-5px;
width: 0;
height: 0;
border-left: 45px solid red;
border-top: 45px solid transparent;
border-bottom: 45px solid transparent;
z-index:1000;
}
/* for hiding the portion except the border
of the triangle shape */
.rectangle::before {
content: "";
position: absolute;
right:-40px;
bottom: 0;
top:0;
width: 0;
height: 0;
border-left: 40px solid white;
border-top: 40px solid transparent;
border-bottom: 40px solid transparent;
z-index:1001;
}
<div class="rectangle">Some text</div>
In case you don't need border like structure then you can avoid ::before portion and set background color to main div.
.rectangle {
width: 300px;
height: 80px;
border: 5px solid red;
border-right: none;
position: relative;
background:red;
}
.rectangle::after {
content: "";
position: absolute;
right:-45px;
bottom: 0;
top:-5px;
width: 0;
height: 0;
border-left: 45px solid red;
border-top: 45px solid transparent;
border-bottom: 45px solid transparent;
}
<div class="rectangle">Some text</div>
For more shapes refer : CSS Tricks
To keep only the border without filling the div, You can try using ::before and ::after.
Something like this:
.rectangle {
width: 200px;
height: 40px;
position: relative;
border-top: 2px solid red;
border-bottom: 2px solid red;
border-left: 2px solid red;
-moz-border-radius: 3px 0 0 3px;
-webkit-border-radius: 3px 0 0 3px;
border-radius: 3px 0 0 3px;
margin-left: 50px;
}
.rectangle::after {
content: "";
position: absolute;
left: 100%;
width: 0;
height: 0;
top: 2px;
border-top: 18px solid transparent;
border-left: 10px solid #fff;
border-bottom: 17px solid transparent;
}
.rectangle::before {
content: "";
position: absolute;
left: 100%;
width: 0;
top: -2px;
height: 0;
border-top: 22px solid transparent;
border-left: 14px solid red;
border-bottom: 22px solid transparent;
}
<div class="rectangle">Some text</div>
Consider rotating a pseudo-element by declaring a transform: rotate() property value, as demonstrated in the code snippet embedded below.
As an alternative to achieving the same behaviour declaring border property rules, this method allows borders to be declared on the element in an intuitive manner using only one pseudo-element.
Rotating an element in this way also gives you the option to fill in the element with a solid colour - allowing you more freedom in customization.
Code Snippet Demonstration:
.rectangle {
width: 300px;
height: 80px;
border: 5px solid red;
/* additional */
border-right: 0;
box-sizing: border-box;
position: relative; /* required */
}
/* Additional */
.rectangle:after {
content: "";
position: absolute;
width: 55px;
height: 55px;
border-right: 5px solid red;
border-top: 5px solid red;
box-sizing: inherit;
right: -28px;
top: 7px;
transform: rotate(45deg);
}
<div class="rectangle">Some text</div>
Check CSS Shapes
#pointer {
width: 200px;
height: 40px;
position: relative;
background: red;
}
#pointer:after {
position: absolute;
left: 0;
bottom: 0;
width: 0;
height: 0;
border-left: 20px solid white;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
}
#pointer:before {
content: "";
position: absolute;
right: -20px;
bottom: 0;
width: 0;
height: 0;
border-left: 20px solid red;
border-top: 20px solid transparent;
border-bottom: 20px solid transparent;
}
<div id="pointer">
</div>
you have to use the pseudo class after
.rectangle {
position: relative;
width:200px;
height:40px;
margin-left:40px;
color:#FFFFFF;
background-color:red;
text-align:center;
line-height:40px;
}
.rectangle:after {
content:"";
position: absolute;
left: 100%;
top:0px;
width:0px;
height:0px;
border-top:20px solid transparent;
border-left:40px solid red;
border-bottom:20px solid transparent;
}
<div class="rectangle">Some text</div>
You can do it using :before and :after
.rectangle {
width: 300px;
height: 80px;
border: 5px solid blue;
border-right: none;
position: relative;
}
.rectangle::before {
content: '';
border-top: 5px solid blue;
width: 120px;
position: absolute;
right: -115px;
bottom: 16px;
transform: rotate(-21deg);
}
.rectangle::after {
content: '';
border-top: 5px solid blue;
width: 120px;
position: absolute;
right: -115px;
top: 16px;
transform: rotate(21deg);
}
<div class="rectangle">Some text</div>

Double inner border over image with offsets

I am trying to recreate these borders over an image with CSS.
I have been able to create one border by using this CSS:
.bordered-image {
position: relative;
outline: 1px double white;
outline-offset: -10px;
}
But I have been unable to create the second border. Is it possible using CSS?
Hope the below code helps
body{
padding:50px;
}
.box{
width:300px;
height:200px;
border:1px solid red;
position:relative;
}
.box:after{
content:"";
position:absolute;
top:-4px;
bottom:-4px;
left:2px;
right:2px;
border:1px solid green;
}
<div class="box" >
</div>
Try the below code
<div class="module">
</div>
-
body {
padding: 20px;
}
.module {
width: 300px;
height: 200px;
position: relative;
border: 1px solid blue;
margin: auto;
}
.module:after {
content: "";
position: absolute;
top: -3px;
left: 1px;
right: 1px;
bottom: -3px;
border: 1px solid black;
margin:auto;
}
img {
border: 1px double black;
padding: 64px;
outline: 1px solid black;
box-sizing: border-box;
outline-offset: 20px;
}
something like this should work for you. You might have to play with the dimensions
body {
background: black;
}
.bordered-image {
position: relative;
height: 300px;
width: 300px;
border: 1px solid white;
margin: auto;
}
.bordered-image:before {
position: absolute;
left:-6px;
top: 4px;
display: block;
content: ' ';
margin: auto;
height: 290px;
width: 310px;
border: 1px solid white;
}
Try this:
.bordered-image {
background:black;
width:300px;
outline: 1px double white;
outline-offset: -10px;
}
.one {
width:300px;
height:300px;
position:relative;
border:1px solid white;
}
.one:after {
content: "";
width: 273px;
position: absolute;
top: 5px;
bottom: 5px;
left: 11px;
right: 2px;
border: 1px solid white;
}
<div class="bordered-image">
<div class="one">
</div>
</div>

How to make custom shape div, or manipulate divs

I want to make a div that is like that, but i have no clue. I can do it with svg or images, but that is not how i want it. Here is my code
HTML
<div class="FooterWhite"> </div>
CSS
.FooterWhite {
background-color:white;
height:50%;
width:100%;
}
try this :
.shape {
width: 200px;
height: 70px;
background: #000;
margin: 50px;
position: relative;
}
.shape:before {
display: block;
content: "";
height: 0;
width: 0;
border: 50px solid #f00;
border-bottom:50px solid transparent;
border-left: 50px solid transparent;
position: absolute;
top: 70px;
}.shape:after {
display: block;
content: "";
height: 0;
width: 0;
border: 50px solid #f00;
border-bottom: 50px solid transparent;
border-right:50px solid transparent;
position: absolute;
top: 70px;
left:100px;
}
JSFIDDLE DEMO