Button with gradient outside border - html

How can I achieve the next thing in CSS to a < a > element ?
Image1
I managed to do something like this:
https://jsfiddle.net/25abxak1/
-- first of , I need the content to be wider and second , I want the first color to go above the border , just like in the picture.
I'm a begginer in CSS and I really need help.
Thank you

You can use display: inline-block on a, and for black part you can use :before pseudo-element. You should also set padding-left on a to width of :before + padding-right so that text is centered.
a {
color: #C46439;
background: none;
border-radius: 10px;
border: 1px solid #D2D1D1;
position: relative;
overflow: hidden;
padding: 10px 30px;
padding-left: 70px;
display: inline-block;
text-decoration: none;
}
a:before {
content: '';
position: absolute;
left: 0;
top: 0;
height: 100%;
width: 40px;
background: black;
}
Centered text
You can also use linear-gradient and set black part to 20% or something similar.
a {
color: #C46439;
background: linear-gradient(to right, black 0%, black 20%, white 20%, white 100%);
border-radius: 10px;
border: 1px solid #D2D1D1;
position: relative;
overflow: hidden;
padding: 10px 30px;
padding-left: 70px;
display: inline-block;
text-decoration: none;
}
Centered text

Related

How to make an input text field like the one on the Tesla Cybertruck order website?

I want to make an input text field, like the one on https://www.tesla.com/en_gb/cybertruck/design#battery (it appears after clicking 'buy now') but I am unsure how to approach this.
I have tried adding border-radius but of course that only rounds the corners.
Below is my current code:
<style>
body {
background-color: black;
}
label {
color: white;
}
input {
width: 300px;
height: 40px;
border: solid white 1px;
background: transparent;
color: white;
font-family: 'Consolas';
font-size: 0.9em;
font-weight: bold;
padding: 10px 10px 10px 10px;
transition: border 0.3s ease-in-out;
box-sizing: border-box;
outline-width: 0;
border-radius: 10px 10px 10px 10px;
border-style: none;
border-width: 0 0 3px;
padding: 3px 10px;
}
input:focus {
border: solid white 3.5px;
}
</style>
<label>Test field</label>
<br>
<input type = "text">
I would like this to be responsive if possible, thanks in advance.
They are using clip-path and polygon to do this. See this page for details: https://css-tricks.com/notched-boxes/
As already mentioned, by looking at the source you can see that it's a clip path.
In particular the clip path is applied to a wrapper div as ::before pseudo element as opposed to on the input element. Here's a simple example using the exact same clip path on the website.
body,
html {
padding: 0;
margin: 0;
background-color: #333;
display: flex;
justify-content: center;
align-items: center;
height: 100%;
}
.wrapper {
width: 200px;
height: 40px;
position: relative;
display: block;
}
.wrapper::before {
content: "";
display: block;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: blue;
clip-path: polygon(0px 0px, 100% 0px, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0px 100%, 0px 1.5px, 1.5px 1.5px, 1.5px calc(100% - 1.5px), calc(100% - 11.5px) calc(100% - 1.5px), calc(100% - 1.5px) calc(100% - 11.5px), calc(100% - 1.5px) 1.5px, 0px 1.5px);
}
input {
background: transparent;
border-color: transparent;
border-radius: 0;
color: white;
width : 100%;
height: 100%;
outline: none;
}
<div class="wrapper">
<input type="text" />
</div>
The clip path is kind of too complicated to explain bit-by-bit, but it essentially cuts out the middle of a solid rectangle as well as a little corner. So in this case, the background color is what controls the "border color". In order to animate on hover, it probably changes some elements of the clipping path if I were to guess.

Transparency issue with pseudo-elements and background on unique button shape

I am attempting to have a unique button shape that is achieved using pseudo-elements become transparent on one end so the background will show through. If the background is set to a solid color, the desired result is easily achieved because I can change the ::after element to be the same color. Though, I'm struggling to come up with a solution if the background is an image or svg.
codepen: https://codepen.io/codingforthefuture/pen/YzKvGvq
I have the ::after element set to white to demonstrate the problem, though you can change it to pink to see the desired result.
Problem occurs if you change the color of the pseudo-element to transparent, you see the other pseudo-element in its place. If you remove that pseudo-element you remove the border on that end for the shape.
body{
background: pink;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
}
a .btn-flag {
padding: 0;
border: 0;
outline: none;
text-decoration: none;
}
a.btn-flag strong{
position: relative;
color: black;
font-size: 0.8rem;
bottom: -2px;
right: 10px;
}
.btn-flag {
display: inline-block;
font-size: 0.7rem;
min-width: 200px;
height: 35px;
box-sizing: content-box;
padding-top: 15px;
position: relative;
background: yellow;
color: black;
font-size: 7px;
letter-spacing: 0.2em;
text-align: center;
text-transform: uppercase;
border-top: 1px solid red;
border-bottom: 1px solid red;
border-left: 1px solid red;
margin-bottom: 20px;
}
.btn-flag::before,
.btn-flag::after {
content: "";
position: absolute;
top: -1px;
width: 0;
height: 0;
left: 87%;
/*should be transparent, Should acheive same effect as setting the color from #fff to pink but without knowing background set color, possible image or svg in background*/
border-right: 26px solid #fff;
border-top: 26px solid transparent;
border-bottom: 26px solid transparent;
}
.btn-flag::before{
/* other color to change, but changing gets rid of border on flag end */
border-right: 26px solid red;
border-top: 26px solid transparent;
border-bottom: 26px solid transparent;
left: 86.5%;
}
/****************************************************/
<body>
<a href="#" class="btn-flag">
<strong>Example Text</strong>
</a>
</body>
Try something like this! https://codepen.io/anonymousjoe/pen/wvwXJwz
Rather than trying to get pseudo elements to have crazy shapes and crazy borders, we can give each pseudo element the funny flag shape, and then fake the outlines on them using drop-shadows.
filter: drop-shadow(0 -1px 0 red) drop-shadow(1px 0 0 red);
Another option would be to use SVGs as background-images on each of the pseudo-elements positioned the same way I have them here.

CSS make right border diagonal

How can I create a vertically tilted line using css, like seen below?
Try playing with border
.progressbar{
position: relative;
overflow: hidden;
height: 10px;
background: #eee;
}
.progressbar > i{
position: absolute;
width: 60%;
border-top: 10px solid #0bf; /* same as parent height */
border-right: 3px solid transparent; /* diagonality :) */
}
<div class="progressbar"><i></i></div>

css border with triangle shape

Is there any way to create the border on the left with css ?
Here is a way to do it using CSS; you are just layering a Parallelogram and a Rectangle:
.espanolIcon
{
width: 300px;
height: 100px;
padding-left: 30px;
}
.rectangle {
position: absolute;
top: 0px;
left: 200px;
width: 200px;
height: 100px;
background-color: green;
border-radius: 0px 0px 30px 40px;
}
.arrow-left {
position: absolute;
top: 0px;
width: 300px;
height: 100px;
background-color: green;
-webkit-transform: skew(22deg);
transform: skew(22deg);
border-radius: 0px 0px 30px 40px;
}
h1 {
color: white;
}
<div class="espanolIcon">
<div class="rectangle"><h1>Espanol</h1></div>
<div class="arrow-left"></div>
</div>
Use a zero-dimension :before with thick, partial borders
By adjusting the top/bottom and left/right values of border-width on the :before pseudo-element, you can effectively change the skew of the triangle. The left position can then be changed to properly align the pseudo-element.
a {
display: inline-block;
position: relative;
margin-left: 14px; /* Should counter `left` value of `a:before` */
padding: .5em 1em;
color: #fff;
font: bold 1em/1 sans-serif;
text-decoration: none;
text-transform: uppercase;
border-radius: 0 0 10px 10px;
background: #75bf41;
}
a:before {
content: '\200B'; /* zero-width non-breaking space */
display: block;
position: absolute;
top: 0;
left: -14px; /* Adjust to align */
width: 0;
height: 0;
border-width: 14px 8px; /* Adjust top/bottom and left/right to skew */
border-style: solid;
border-color: #75bf41 #75bf41 transparent transparent; /* Triangle orientation. */
}
Español
Full css could work, but you should use .png as background-image or perhaps you could use .svg as you can animate and/or change every point or pixel. You might be able to use just CSSbut it would take a lot of leveling and positioning and alot of layers of absolute and relative positioning. As Css would only change the full width of the element, and it can only be used to change the width of elements. What you can do is use .svg, you could map every pixel which could be animated.
I accomplished it using borders and pseudo elements.
<ul>
<li class="lang-item lang-item-6 lang-item-es">
::before
<a>Español</a>
</li>
</ul>
ul {
position:relative;
}
.lang-item {
text-align: right;
position: relative;
}
.lang-item a {
background: #76c53f;
padding: 15px;
color: #fff;
text-transform: uppercase;
border-bottom-right-radius: 10px;
border-bottom-left-radius: 14px;
}
.lang-item::before {
position: absolute;
right: 101px;
top: -15px;
content: "";
display: inline-block;
border-top: 40px solid #76C541;
border-left: 40px solid transparent;
}
jsfiddle

A custom style with pure CSS and HTML

I am trying to create a style using CSS and HTML. My desire style is something similar to this.
Most of things of that style have been done with pure CSS and HTML.
This is my CSS -
.filter-box {
float: left;
margin: 0 3% 0 2%;
width :29%;
> .main-cat {
background-color: #FFFFFF;
display: block;
margin-top: 25px;
padding: 10px;
position: relative;
> h3 {
margin: 0;
}
}
> .main-cat:after {
border-bottom: 15px solid rgba(0, 0, 0, 0);
border-left: 15px solid #FFFFFF;
border-top: 15px solid rgba(0, 0, 0, 0);
content: "";
height: 0;
margin-top: -15px;
position: absolute;
right: -14px;
top: 50%;
width: 0;
}
> .main-cat:first-child {
margin-top: 0;
}
> .sub-cat {
background: #FF9000;
margin-left: 25px;
margin-top: 5px;
padding: 8px 10px;
text-align: right;
> h4 {
margin: 0;
}
}
}
My problem is when I am trying to display a let border with a bold circle bullet on the left side of the sub category DIV.
Can any body tell me is this possible with pure CSS and HTML without using any image?
This is my code so far: JS BIN
Any comments would be greatly welcome.
Thank You.
Another possibilities would be to use background-image (gradients) and bullets of list-item , resized via font-size : DEMO
The CSS update could be :(see comment for explanation )
.filter-box {
background:linear-gradient(to right,
transparent 15px,
white 15px,
white 17px,
transparent 17px); /* draws the vertical bar aside list-items */
}
background:linear-gradient( /* draw orange background */
to right,
transparent 40px ,
#FF9000 40px),
linear-gradient(/* draw middle white bar */
to bottom,
transparent 49%,
white 48%,
white 52%,
transparent 51%
) right no-repeat;
background-size:
auto auto/* no need to resize first gradient */,
95% 100% /*reduce width of second gradient */;
display:list-item;/* lests get a round bullet if this is not a li */
color:white; /* give color to bullet */
font-size:2.2em;/* resize bullet */
list-style-position:inside;/* keep bullet inside element */
}
.filter-box > .sub-cat > h4 {
margin: 0;
font-size:0.6em;/* resize to a normal font-size from em value inherited */
display:inline-block;/* stands aside bullet */
text-align: right;/* align to right */
width:85%;/* keep min/max-width under control*/
}
Notice: no pseudo elements involved, gradient can be image for better compatibilitie and dispatch within main container , sub container and title for the background-color to increase compatibiliti with old browser.
As mentionned earlier , this menu/list deserve to be build from an HTML list.
Demo: http://jsfiddle.net/abhitalks/4LB5t/
CSS:
.sub-cat:before {
content: ' ';
border-left: 1px solid white;
display: inline-block;
width: 16px; height: 42px;
position: absolute;
left: 40px; margin: 0px; margin-top: -8px;
z-index: 10;
}
.sub-cat:after {
content: '';
display: inline-block;
width: 8px; height: 8px;
background-color: white;
border-radius: 50%;
position: absolute;
left: 36px; margin-top: -8px;
}
Update:
Demo 2: http://jsfiddle.net/abhitalks/4LB5t/1/
Just increase the height on .sub-cat:before.
Update 2:
Demo 3: http://jsfiddle.net/abhitalks/4LB5t/2/
Added your horizontal border as well. The only changes in the css are:
.sub-cat:before {
...
border-bottom: 1px solid white;
margin-top: -26px;
z-index: -1;
}
You have to tweak and tune the styles to achieve what you want. Hope that helps.
You can use the :before and :after elements in the sub-category to design the circle and left border.
Use the :before to make the circle as #megha outlined, and position it with the vertical center of the sub-cat.
Put the position of the .subcat as position: relative, so that you can define the positions of the absolutely positioned :before and :after in relation to the left edge of .subcat
Then use the :after and style it as
width: 2px;
height: 100%;
top: 0;
left: -10px
Hope this helps
Look at this pen. I have modified some of the styles in the answer to make it work. (SCSS syntax)
http://codepen.io/anon/pen/dJepq
.sub-cat {
background: #FF9000;
margin-left: 25px;
margin-top: 5px;
padding: 8px 10px;
text-align: right;
position: relative;
&:before {
width: 10px;
height: 10px;
border-radius: 50%;
background-color: #ff9000;
content: "";
position: absolute;
top: 12px;
left: -20px;
}
&:after {
width: 2px;
top: -5px;
bottom: 0;
left: -16px;
content: "";
position: absolute;
background-color: #ff9000;
}
}
}
Using :after and :before pseudo element you can achieve the result.
Check the DEMO.
Here is the CSS would be required.
.sub-cat:before{
content: "";
position:absolute;
left:25px;
height: 10px;
width: 10px;
border-radius: 50%;
background:white;
margin-top: 5px;
}
.sub-cat:after{
content: "";
position:absolute;
top:55px;
left:29px;
height:21%;
border-right: 1px solid white;
}
.sub-cat h4:before{
content: " ";
position:absolute;
left:32px;
width: 10px;
height: 10px;
transform:rotate(90deg);
-webkit-transform:rotate(90deg);
border-right: 1px solid white;}
.sub-cat h4:after{
content: " ";
margin-left:10px;
margin-top:4px;
position:absolute;
border-bottom: 8px solid rgba(0, 0, 0, 0);
border-left: 8px solid #000000;
border-top: 8px solid rgba(0, 0, 0, 0);
}
A circular bullet can be created using the html :
<div id="circle"></div>
and its corresponding css
#circle
{
width:10px;
height:10px;
border-radius:5px;
background-color:white;
}
I am unable to understand what "let border" means.Hope this helps!