I need to create a dashed border gradient like in this picture. Here's my CSS code.
.Rectangle-5 {
margin: 51px 0px 0px 35px;
display: inline-block;
width: 370px;
height: 280px;
border-radius: 3px;
border: 1px dashed;
border-image-source: linear-gradient(to bottom, #4fc3f7, #ab5ca4 49%, #ff512f);
border-image-slice: 1;
}
New answer
Here is an improvement version of the initial answer with less of code. The idea is to rely on multiple background and adjust background-clip of each one.
.container {
display:inline-block;
height: 200px;
width: 200px;
margin: 20px;
border-radius:3px;
border: 2px dotted #fff;
background:
linear-gradient(#fff 0 0) padding-box,
linear-gradient(to bottom, #4fc3f7, #ab5ca4 49%, #ff512f) border-box;
}
.alt {
border: 2px dashed #fff;
}
<div class="container">
</div>
<div class="container alt">
</div>
Old answer
You can apply linear-gradient as a background to an extern container and then use dotted or dashed border on inner container. As per your needs you have to use the white as color for the border and also as the background of the content like this :
.container {
display:inline-block;
height: 200px;
width: 200px;
margin: 20px;
background-image: linear-gradient(to bottom, #4fc3f7, #ab5ca4 49%, #ff512f);
}
.inner {
border: 2px dotted #fff;
height: calc(100% - 4px);
}
.inner-alt {
border: 2px dashed #fff;
height: calc(100% - 4px);
}
.content {
background: #fff;
height: 100%;
}
<div class="container">
<div class="inner">
<div class="content"></div>
</div>
</div>
<div class="container">
<div class="inner-alt">
<div class="content"></div>
</div>
</div>
You need to pay attention to the height of the inner container. It should be 100% but don't forget the border in calculation, that's why i used calc(100% - 4px) (2px for top border and 2px for bottom border).
So if you change border height value you need also to update the height accordingly.
Add the following rule to your CSS
.Rectangle-5{
border: 2px dotted #fff;
background: linear-gradient(#fff,#fff) padding-box,
linear-gradient(92.35deg, #3370fe 1.28%, #00e599 98.95%) border-box;
}
Related
I am trying to create an element which is a half-circle with a complete circle border. Like this:
I have no problem doing it with using 2 elements, but don't fully understand how to do it within one DIV.
Right now all I have is a half circle:
.element {
height: 10px;
width: 10px;
border-bottom-left-radius: 20px;
border-top-left-radius: 20px;
background-color: #00a680;
}
You can simply use gradient:
.box {
width: 150px;
height: 150px;
border: 15px solid #00a680;
border-radius: 50%;
padding: 15px;
background: linear-gradient(to right, #00a680 50%, transparent 0) content-box;
box-sizing:border-box;
}
<div class="box">
</div>
<div style="border-radius:50px 10px;width:60%;border: 1px solid #123467;background:linear-gradient(to top, #88D3CE 0%, #6E45e2 100%);display:inline-block;float:right">
<div style="align:center;border-radius:10px 50px;margin-top:5%;text-align:center;width:60%;border: 1px solid #ffffff;background:linear-gradient(-225deg,#A445B2 0%, #D41872 52%, #FF0066 100%)">
<br/>
<h3 style="color:black">Running from</h3>
</div>
<br/>
</div>
The blue, pink, violet div isn't center despite I insert the align tag also in style (CSS). Why?
Thanks
Andrea
Your float: right is the main problem which forces the outer DIV to the right side. Remove that. To horizontally center it, you can make it a block element and add auto for margin-right and left.
So, you should apply display:block; margin: 0 auto; to both DIVs and remove the float (actually, to keep your 5% margin-top, the margin setting for the inner DIV has to be margin: 5% auto 0;)
<div style="border-radius:50px 10px;width:60%;border: 1px solid #123467;background:linear-gradient(to top, #88D3CE 0%, #6E45e2 100%);display:block;margin: 0 auto;">
<div style="align:center;border-radius:10px 50px;text-align:center;width:60%;border: 1px solid #ffffff;display:block;margin: 5% auto 0;background:linear-gradient(-225deg,#A445B2 0%, #D41872 52%, #FF0066 100%)">
<br/>
<h3 style="color:black">Running from</h3>
</div>
<br/>
</div>
There is no such CSS property "align". Instead, use the margin property and set its values to 0 (for top and bottom), as well as auto (for left and right). This will center the element.
.outer {
border-radius: 50px 10px;
width: 60%;
border: 1px solid #123467;
background: linear-gradient(to top, #88D3CE 0%, #6E45e2 100%);
display: inline-block;
float: right;
}
.inner {
margin: 0 auto;
border-radius: 10px 50px;
margin-top: 5%;
text-align: center;
width: 60%;
border: 1px solid #ffffff;
background: linear-gradient(-225deg,#A445B2 0%, #D41872 52%, #FF0066 100%);
}
<div class="outer">
<div class="inner">
<br/>
<h3 style="color:black">Running from</h3>
</div>
<br/>
</div>
you could add margin: 5% auto; to your inner DIV:
<style>
#firstDiv
{
border-radius:50px 10px;
width:60%;
border: 1px solid #123467;
background:linear-gradient(to top, #88D3CE 0%, #6E45e2 100%);
display:inline-block;
float:right;
}
#secondDiv {
border-radius:10px 50px;
margin: 5% auto;
width:60%;
border: 1px solid #ffffff;
background:linear-gradient(-225deg,#A445B2 0%, #D41872 52%, #FF0066 100%);
text-align: center;
}
#secondDiv h3 {
color: black;
}
</style>
<div id="firstDiv" style="">
<div id="secondDiv" style="">
<h3>Running from</h3>
</div>
</div>
However I suggest separating styles and html.
I'm trying to make a triangle in CSS that takes the whole width of the parent with a fixed height.
I successfully did so with a linear-gradient like this:
.triangle {
width: 100%;
height: 120px;
background: linear-gradient(to right bottom, blue 50%, transparent 50%);
}
<div class="triangle"></div>
But the diagonal doesn't look crisp. How could I do the same in CSS without using gradient?
You can blur the edge a bit
.triangle {
width: 100%;
height: 120px;
background: linear-gradient(to right bottom, blue 49.5%, transparent 50%);
}
<div class="triangle"></div>
the border approach as mention could be done this way to be similar :
.triangle {
width:0;
border-style:solid;
border-width: 0px 0px 120px 100vw;
border-color:transparent transparent transparent blue ;
}
<div class="triangle"></div>
Best is to use an SVG ....
The trick is to make a triangle out of the border. Since CSS does not allow using percentage in border-width, I'm using 100vh instead of 100%.
Please try this:
.triangle {
width: 0;
height: 0;
border-style: solid;
border-width: 0px 0px 120px 100vw;
border-color:transparent transparent transparent blue ;
}
Why dont you try without gradient property using border-width.I have implemented one using border-width which gives the boundaries more crisp. Here is the runable version.
.triangle {
width: 100%;
height: 120px;
background: linear-gradient(to right bottom, blue 50%, transparent 50%);
}
.container{
width : 300px;
}
.triangleUsingbordermethod {
border-top-color: blue;
border-top: 60px solid blue;
border-left: 50% solid black;
border-left: 150px solid blue;
border-right: 150px transparent solid;
border-bottom: 60px transparent solid;
}
<div class='container'>
<div class="triangleUsingbordermethod"></div>
</div>
I want to create the white border seen in the image below with CSS. White border that is set 25px inside the window. Iv'e tried to use box-shadow inset however was not able to create the space between the edge of the window.
I used this css:
border: 3px solid white; //took this out but still no luck
box-shadow: inset 0 0 0 5px #FFFFFF;
I also tried without the normal border as well.
I think I can create an overlay div that has a padding or margin and give it a border, but the problem is the content needs to be scrollable and clickable below it.
The goal:
The white box just above the icons.
Use a pseudo element
.parent {
position: relative;
height: 200px;
}
.wrapper {
height: 100%;
overflow-y: auto;
}
.content {
height: 600px;
background: url(http://lorempixel.com/600/600/abstract/1) no-repeat center center / cover;
}
.parent:after {
content: '';
position: absolute;
left: 25px;
top: 25px;
right: 40px;
bottom: 25px;
border: 2px solid white;
}
<div class="parent">
<div class="wrapper">
<div class="content">
</div>
</div>
</div>
Use a transparent border to set the shadow where you want it.
The remaining problem is to extend the image to the borders. Use background-origin for this.
.test {
height: 250px;
width: 400px;
background-image: url(http://lorempixel.com/600/400);
background-origin: border-box;
background-size: cover;
border: 50px transparent solid;
box-shadow: inset 0px 0px 5px 5px cyan;
}
<div class="test">
</div>
hope this help.
body{
background: #000;
}
.wrapper{
width: 500px;
padding: 25px;
border: 3px solid #CCC;
}
.content{
border: 1px solid #fff;
padding: 15px;
color: #fff;
height: 400px;
}
<div class="wrapper">
<div class="content">
this is your content div with white border
</div>
</div>
Hi all,
I would like to insert a <button> in my code that has a gap in border-top and border-bottom. I have seen some examples where it is possible to remove a part with it, but it's not exactly what I am looking for. Do you have an idea on how to get something like the above mentioned picture?
Thanks in advance for your replies!
EDIT:
I add more information: the best is that the background of the button is transparent and that the border-size is customisable.
Use pseudo elements
.brd {
font-size: 30px;
padding: 4px 20px;
position: relative;
border: none;
background-color: white;
}
.brd:before,
.brd:after {
content: ' ';
position: absolute;
border: 1px solid black;
top: 0;
bottom: 0;
width: 10px;
}
.brd:before {
border-right: 0;
left: 0;
}
.brd:after {
border-left: 0;
right: 0;
}
<span class="brd">Title</span>
<button class="brd">Title</button>
Another possible solution is to use gradient as border-image. Look at the snippet below
.box{
display:inline-block;
margin: auto;
padding: 10px;
border: 3px solid transparent;
-moz-border-image: -moz-linear-gradient(to right, #aaa 10%, #fff 10%, #fff 90%, #aaa 90%);
-webkit-border-image: -webkit-linear-gradient(to right, #aaa 10%, #fff 10%, #fff 90%, #aaa 90%);
border-image: linear-gradient(to right, #aaa 10%, #fff 10%, #fff 90%, #aaa 90%);
border-image-slice: 1;
}
<div class="box" >TITLE HERE</div>
If you want the top and bottom border parts to be exactly X pixels, you can change the percents with pixels like this:
border-image: linear-gradient(to right, #aaa 20px, #fff 20px, #fff calc(100% - 20px), #aaa calc(100% - 20px));
A simple way would be using a custom made image as the background of your button, tho it wouldn't scale well on different screen sizes.
Another idea would be to have a div underneath with a normal border, and then your smaller button on top of it, with the same height and a white border, so as to hide the top and bottom part.
I've created a JSFiddle for you: enter link description here
HTML:
<div class="back-with-border">
<div class="front-no-border">
Title Here
</div>
</div>
CSS:
.back-with-border{
border:1px solid gray;
width:200px;
height:100px;
position: relative;
}
.front-no-border{
display:flex;
justify-content:center;
align-items:center;
border:0px;
background-color:white;
position: absolute;
width:110px;
height:110px;
top:-1px;
left:45px
}
Check this [JSFiddle][1], hope this will solve your problem
body {
background-color: white;
}
.parent {
border: 1px solid black;
width: 200px;
height: 100px;
position: relative;
background-color: white;
}
.child {
display: flex;
justify-content: center;
align-items: center;
border: 0px;
background-color: white;
position: absolute;
width: 150px;
height: 103px;
top: -1px;
left: 25px
}
<div class="parent">
<div class="child">
Write your text here
</div>
</div>
[1]: https://jsfiddle.net/anshul24mehta/eocst0uv/3/