Button with partial border on top and bottom - html

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/

Related

How can I create a dashed border with gradient?

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;
}

A triangle in CSS that takes the whole width with a fixed height?

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>

Text on div border with transparent background [duplicate]

This question already has answers here:
How to center the <legend> element - what to use instead of align:center attribute?
(10 answers)
Closed 7 years ago.
How to put some text on a border div so that text has a transparent background that it matches the image behind?
The problem is that the background-image has some shapes and multiple colors, so I can't put just some background color the the text because it won't fit.
Example:
html,
body {
width: 100%;
height: 100%;
}
body {
margin: 0;
background: url(http://wallpoper.com/images/00/45/05/47/green-background-2_00450547.jpg);
}
#main {
margin-top: 100px;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
border: 1px solid #000000;
}
#main h2 {
font-size: 60px;
font-weight: 700;
text-align: center;
margin: -40px 0 0;
background: transparent; /* somehow remove the border behind the text */
padding: 0 20px;
}
<div id="main">
<h2>Star players</h2>
<ul>
<li>foo</li>
<li>bar</li>
</ul>
</div>
JSFiddle
You can use a fieldset instead of a div:
HTML:
<fieldset>
<legend>Test</legend>
</fieldset>
CSS:
legend {
text-align: center;
width: 100%;
}
So you want to see one thing 2 layers behind the text but not the other thing that is between the two...that in itself is rather counter-intuitive. Not sure you will be able to do it unless you use a border image and css gradient which is always a little complicated and this won't be dependant on the size/width of the text.
e.g.
HTML
<div class="gradborder-box"><div class="inner"><h2>Hello WORLD</h2></div></div>
CSS
.gradborder-box{
margin: auto;
width: 350px;
background: transparent;
border: 2px solid transparent;
-webkit-border-image: -webkit-linear-gradient(left, rgba(0,0,0,1) 0%, rgba(0,0,0,0) 26%, rgba(0,0,0,0) 68%, rgba(0,0,0,1) 100%);
border-image: linear-gradient(to left, rgba(0,0,0,1) 0%, rgba(0,0,0,0) 26%, rgba(0,0,0,0) 68%, rgba(0,0,0,1) 100%);
border-image-slice: 1;
}
h2{font-size: 1.2em; text-align: center; margin-top: -10px;}
.inner{height: 150px; width: 100%; border-bottom: 2px solid #000; margin-bottom: -2px;}
CodePen
This has been done for CHROME - you will need to add in the correct border image tags for the other browsers (-moz-border-image, etc). This is CSS3 only.

Need help getting an effect on a header and with a button

I am trying to get a certain effect on a header for a mockup. It has white glow almost not noticeable. You will see it in this picture i provide behind the title and sub title. How can i get that glow effect with css? I do have a header with the entire thing but is that a good idea to use an image for an entire header? Also i want those two lines near the subtitle. Is it possible to code those lines? And last, the button "order now", will that be possible to make with css or should i just use an image of that and link it?
mockup
jsfiddle - http://jsfiddle.net/ezdr3xdg/1/ [what i currently have]
<header>
<h1>Taffies Cupcakes</h1>
<h2>Fresh and tasty</h2>
</header>
body{
background-color:#e7d2c9;
}
header h1{
font-family:georgia;
font-size:46px;
color:#784f3d;
text-align:center;
margin-top:50px;
}
header h2{
font-family:segoe script;
font-size:32px;
color:#846a5f;
text-align:center;
}
All of this is possible to do in CSS 3, I wouldn't recommend it though. Using an image for the button and the header is the best idea if you want it to look the same in all browsers. If you want to do it in CSS anyway try this:
HTML:
<header>
<div class="shadow"></div>
<h1>Taffies Cupcakes</h1>
<h2><div class="line"></div>Fresh and tasty<div class="line"></div></h2>
</header>
CSS:
header > .shadow {
width: 0px;
height: 0px;
margin: 0px 50%;
box-shadow: 0px 0px 200px 100px white;
}
header h2 > .line {
height: 1px;
width: 100px;
margin: 5px 20px;
background-color: #846a5f;
display: inline-block;
vertical-align: middle;
}
As the other answers have mentioned, radial-gradient is probably the way to go here. Just apply it to the header element instead of using my version with box-shadow (which might be a little hacky to some).
Update for the button:
HTML:
<button class="special"><div class="icon"></div><div class="headline">ORDER NOW</div><div class="description">We deliver in 24 hours</div></button>
CSS:
button.special {
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #784f3d), color-stop(1, #846a5f) );
background:-moz-linear-gradient( center top, #784f3d 5%, #846a5f 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#784f3d', endColorstr='#846a5f');
background-color:#784f3d;
color: #e7d2c9;
text-align: left;
border: 0;
outline: 0;
border-radius: 5px;
height: 42px;
}
button.special > .icon {
width: 27px;
height: 27px;
/*background-image: url('triangle-button.png')*/
position: absolute;
margin: 5px;
}
button.special > .headline {
margin-left: 42px;
font-size: 18px;
}
button.special > .description {
margin-left: 42px;
font-size: 12px;
}
http://jsfiddle.net/ezdr3xdg/17/
Use CSS radial-gradient()
DEMO 1:
body {
height: 100vh;
background-color: #e7d2c9;
background-image: -webkit-radial-gradient(center top, ellipse farthest-corner, #fff 0%, #e7d2c9 50%);
}
DEMO 2:
body{
height:100vh;
background-color:#e7d2c9;
background-image: -webkit-radial-gradient(center top, ellipse farthest-corner, #fff 0%, #e7d2c9 100%);
}
DEMO 3:
body {
height: 100vh;
background-color: #e7d2c9;
position:relative;
}
body:after {
content: '';
position: absolute;
left: 50%;
top: -150px;
margin-left: -100px;
width: 200px;
height: 200px;
border-radius: 50%;
z-index:-1;
background: rgba(255, 255, 255, 0.42);
box-shadow: 0 0 40px 64px rgba(255, 255, 255, 0.42);
}
I have update your jsfiddle with a starting template of sorts. Its CSS# gradients and border-radius. http://jsfiddle.net/ezdr3xdg/7/
the button:
<div id="order_now">
<div id="triangle-right"></div>
<div id="text">
ORDER NOW
<div id="sub_order">we deliver in 24hours</div>
</div>
</div>
CSS:
The Button:
#order_now{
background: linear-gradient(#846a5f, brown);
width: 200px;
border-radius: 5px;
padding: 5px;
color: white;
font-size: 12pt;
font-weight: bold;
}
#sub_order{
font-size: 10pt;
font-style: italic;
}
#triangle-right {
width: 0;
height: 0;
border-top: 25px solid transparent;
border-left: 50px solid white;
border-bottom: 25px solid transparent;
display: inline-block;
}
#text{
display: inline-block;
}
The Background:
body{
background:linear-gradient(to right, red, blue, red);
}
this should be enough to get you started.

How to make text underline css

I have two <a> tags and I need them to be underlined like this:
(notice that I can't use border-bottom: dashed 10px because lines are thin but the space between them is quite big.
HTML:
text1
text2
CSS:
.t1 {
color: #8bb09e;
}
.t2 {
color: #ffee90;
}
There is 2 approaches, but this approach would be the usage of the border-bottom: value;
.t1 {
border-bottom: 1px dashed #333;
}
If you want to use some other style that isn't going to happen. Like the space you're talking about. Then you're more likely to be using an image for the bottom border and create a border-like-effect.
If you can give the anchor a position:relative attribute, I would use an absolutely positioned pseudo element. You can use a background image or a linear gradient like I did in my demo
Demo: http://jsfiddle.net/6Jzu6/1
a {
position: relative;
...
display: block;
...
}
a:after {
content: '';
position:absolute;
height: 1px;
width: 100%;
top: 100%;
left: 0;
background-image: -webkit-linear-gradient(left, transparent 50%, #8b0 50%);
background-image: -moz-linear-gradient(left, transparent 50%, #8b0 50%);
background-image: -ms-linear-gradient(left, transparent 50%, #8b0 50%);
background-image: -o-linear-gradient(left, transparent 50%, #8b0 50%);
background-image: linear-gradient(left, transparent 50%, #8b0 50%);
background-size: 20px 20px;
}
Edit: Oops! credit where credit is due. I got the linear gradient concept from this source
This is all you need :)
.t1 {
display:inline-block; /* make width equal to link content */
padding-bottom:5px; /* margin between underline and text*/
border-bottom:1px dashed red; /* height type and color of underline */
}
Edit
What you need is an addition of min-width property added to your <a> styles.check the demo
Demo
Here's a method I've used in the past. It uses a pseudo element that acts as a border.
http://jsfiddle.net/h7Z9K/
p {
display: inline-block;
position: relative;
}
p::after {
content: "";
display: block;
width: 100%;
border-bottom: 1px dashed #000;
position: absolute;
left: 0;
bottom: -0.5em;
}
Adjust the position of the pseudo element border relative to the element by adjusting its bottom position.
.t1 {
color: #8bb09e;
border-bottom-style: dashed !important;
width:30%;
text-align:center;
display:inline-block;
}
.t2 {
color: #ffee90;
text-align:center;
border-bottom-style: dashed !important;
float:right;
width:30%;
}
text1
text2