border not working properly when applying padding - css

I was applying a border to this input field along with a gradient:
(https://i.stack.imgur.com/eTqQP.png)
,however because i applied some padding now it is very thick on the left side of the border when i hover the input
Here is the css code:
#input2:hover {
border:2px double transparent;
border-radius: 5px;
background-image: linear-gradient(white,white),
linear-gradient(45deg, #63589A,#5e138d);
background-origin: border-box;
background-clip: content-box,border-box;
cursor: pointer;
}
input {
padding-left: 5px;
border-radius: 5px;
border-color: rgba(237, 237, 237, 255);
}
I want the left- side to look the same as the other border-sides.
Would appreciate it if someone helped me on this!

Use padding-box inside the background-clip instead of content-box
input {
border: 3px solid transparent;
border-radius: 5px;
background-image:
linear-gradient(white, white),
linear-gradient(45deg, #63589A, #5e138d);
background-origin: border-box;
background-clip: padding-box, border-box;
cursor: pointer;
padding: 5px 30px;
font-size: 20px;
outline-offset: 4px;
}
<input type="text" placeholder="some text">

Is this what you were trying to achieve?
#input2 {
padding-left: 5px;
cursor: pointer;
font-family: monospace;
width: 200px;
height: 30px;
}
.input-container {
display: flex;
border-radius: 5px;
width: max-content;
border-color: rgba(237, 237, 237, 255);
padding: 2px;
}
.input-container:hover {
border: none;
background-image: linear-gradient(white, white), linear-gradient(45deg, #63589A, #5e138d);
background-origin: border-box;
background-clip: content-box,border-box;
}
<div class="input-container">
<input id="input2" type="text" placeholder="e.g. 1234 5678 9123 0000"/>
</div>

Related

Creating a button with pure css

I'm trying to create a button like this:
This needs to be done in pure css.
I tried to do, nothing happened, it does not work correctly:
display: inline-block;
width: 165px;
text-align: center;
color: #fff;
background: linear-gradient(180deg, #4b3529 21%, #4c2e1a 100%);
border-radius: 5px;
border: 1px solid #ffffff;
font-family: Arial;
font-weight: normal;
border-left: 2px solid #e5ccaf;
border-image: linear-gradient(to bottom, #ffd400,rgba(0, 0, 0, 0)) 0 100%;
border-top: 1px solid #ffd400;
How can I do that?!
You can add the CSS properties inside a class. Then add the class to an HTML element with text-decoration: none; property as follows:
.pure_css_button {
display: inline-block;
width: 165px;
text-align: center;
color: #fff;
text-decoration: none;
background: linear-gradient(180deg, #4b3529 21%, #4c2e1a 100%);
border-radius: 5px;
border: 1px solid #ffffff;
font-family: Arial;
font-weight: normal;
border-left: 2px solid #e5ccaf;
border-image: linear-gradient(to bottom, #ffd400, rgba(0, 0, 0, 0)) 0 100%;
border-top: 1px solid #ffd400;
}
<a href="#" class="pure_css_button">
Button</a>
button {
cursor: pointer;
font-size: x-large;
padding: 0.6rem 2rem;
font-weight: bold;
overflow: hidden;
color: #fff;
background: linear-gradient(180deg, #4b3529 21%, #4c2e1a 100%);
border:0;
border-radius: .3rem;
position: relative;
border-top: 2px solid hsl(24, 49%, 15%);
border-bottom: 2px solid hsl(24, 49%, 15%);
}
button::after,button::before{
content: '';
height: 100%;
width: .15rem;
position: absolute;
top:0;
background:linear-gradient(to bottom, #ffd400, rgba(0, 0, 0, 0)) ;
}
button::before{
left: 0;
}
button::after{
right: 0;
}
<button>
Pure Css</button>
it's possible using body::after content "text" and style it

Gradient border with border radius and gradient text

I am trying to achieve the below design! I have managed to achieve the border radius with gradient border but if i try to use -webkit-background-clip & -webkit-text-fill-color for gradient text then the border radius doesn't work and the whole button gets the gradient color.
I am using this as reference for gradient text and attaching the code for gradient border
.btn {
background-image: linear-gradient(to right, #006175 0%, #00a950 100%);
border-radius: 40px;
box-sizing: border-box;
color: #00a84f;
display: block;
font: 1.125rem 'Oswald', Arial, sans-serif;
/*18*/
height: 80px;
letter-spacing: 1px;
margin: 0 auto;
padding: 4px;
position: relative;
text-decoration: none;
text-transform: uppercase;
width: 264px;
z-index: 2;
}
.btn:hover {
color: #fff;
}
.btn span {
align-items: center;
background: #e7e8e9;
border-radius: 40px;
display: flex;
justify-content: center;
height: 100%;
transition: background .5s ease;
width: 100%;
}
.btn:hover span {
background: transparent;
}
<a class="btn" href="#">
<span>Click Here!</span>
</a>
Any kind of help would be greatly appreciated! Please feel free to give some suggestions. TIA
I will consider this previous answer to build the rounded gradient using pseudo element so that you can use background-clip:text on the main element. I have used the mask version by you can also consider the SVG one:
.btn {
--r:40px; /* radius */
--b:5px; /* border width */
background: linear-gradient(to right, #006175 0%, #00a950 100%);
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
color: transparent;
border-radius: var(--r);
display: flex;
align-items: center;
justify-content: center;
font: 1.5rem 'Oswald', Arial, sans-serif;
height: 80px;
margin: 0 auto;
position: relative;
z-index:0;
text-decoration: none;
width: 264px;
}
/* check lined question for the detail of the below code */
.btn::before {
content:"";
position:absolute;
z-index:-1;
inset: 0;
border: var(--b) solid transparent;
border-radius: var(--r);
background: inherit;
background-origin: border-box;
background-clip: border-box;
-webkit-mask:
linear-gradient(#fff 0 0) padding-box,
linear-gradient(#fff 0 0);
-webkit-mask-composite: xor;
mask-composite: exclude;
-webkit-mask-repeat: no-repeat;
}
/**/
.btn:hover {
color: #fff;
-webkit-text-fill-color: #fff;
-webkit-background-clip: border-box;
background-clip: border-box;
}
.btn:hover::before {
-webkit-mask:none;
}
body {
background:pink;
}
<a class="btn" href="#">
Click Here!
</a>
I got this answer from another post and it worked out for me:
border-bottom: 6px solid transparent;
border-image: linear-gradient(to right, red , yellow);
border-image-slice: 1;
and from my experience, I would use &:after to insert &:hover options to the desired hover effects.

Whitespace in wrapped form element

I'm creating a form with gradient borders. To protect against the borders being removed by the browser on autocomplete I've had to wrap all of the elements in a DIV containing their border. box-sizing is used to include the padding in the element size because there's a textarea too. My issue is now with the submit button.
.input-container {
background-image: linear-gradient(white, white), radial-gradient(circle at top right, #006699, #9900CC);
background-origin: border-box;
background-clip: padding-box, border-box;
border: solid 5px transparent;
border-radius: 30px;
margin-bottom: 10px;
overflow: hidden;
box-sizing: border-box;
}
input[type=submit] {
width: 100%;
padding: 15px;
display: inline-block;
border: none;
outline: none;
border-radius: 30px;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
font-size: 15px;
background: #FFFFFF;
}
input[type=submit]:hover {
background-image: linear-gradient(-45deg, #006699, #9900CC);
color: #FFFFFF;
}
<div class="input-container">
<input type="submit" name="submit" id="submit" value="Submit" required>
</div>
When a user hovers over the button there's an issue where there's a slight edge. For ease having the border there all of the time makes more sense. Having the border there always means the button only needs to fill rather than having no border and being entirely fill (it causes size to momentarily change)
Any ideas for how to get rid of this small outline on the edges would be appreciated so that the button looks truly filled.
You can see the outline appear occasionally below.
And static here
Is it ok?
.input-container:hover {
border: none;
}
.input-container {
background-image: linear-gradient(white, white), radial-gradient(circle at top right, #006699, #9900CC);
background-origin: border-box;
background-clip: padding-box, border-box;
border-radius: 30px;
margin-bottom: 10px;
overflow: hidden;
border: solid 5px transparent;
box-sizing: border-box;
}
input[type=submit] {
width: 100%;
padding: 15px;
display: inline-block;
border: none;
outline: none;
border-radius: 30px;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
font-size: 15px;
background: #FFFFFF;
}
.input-container:hover input[type=submit] {
background-image: linear-gradient(-45deg, #006699, #9900CC);
color: #FFFFFF;
padding:30px 15px;
padding: 20px 15px;
}
<div class="input-container">
<input type="submit" name="submit" id="submit" value="Submit" required>
</div>
As we can see. the border causes this part background-image: linear-gradient(white, white) in .input-container. So lets manipulate it. Added an additional class to parent container .submit-container.
.input-container {
background-image: linear-gradient(white, white), radial-gradient(circle at top right, #006699, #9900CC);
background-origin: border-box;
background-clip: padding-box, border-box;
border: solid 5px transparent;
border-radius: 30px;
margin-bottom: 10px;
overflow: hidden;
box-sizing: border-box;
}
.submit-container:hover {
background-image: linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 0)), radial-gradient(circle at top right, #006699, #9900CC);
}
input[type=submit] {
width: 100%;
padding: 15px;
display: inline-block;
border: none;
outline: none;
border-radius: 30px;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
font-size: 15px;
background: none;
}
.submit-container:hover input[type=submit] {
color: #FFFFFF;
}
<div class="input-container submit-container">
<input type="submit" name="submit" id="submit" value="Submit" required>
</div>
This white border comes because of padding of outer div. You can do different way like removing div.
input[type=submit] {
width: 100%;
padding: 15px;
display: inline-block;
font-family: 'Roboto', sans-serif;
font-size: 15px;
background-image: linear-gradient(white, white), radial-gradient(circle at top right, #006699, #9900CC);
background-origin: border-box;
background-clip: padding-box, border-box;
border: solid 5px transparent;
border-radius: 30px;
margin-bottom: 10px;
overflow: hidden;
box-sizing: border-box;
}
input[type=submit]:hover {
background-image: linear-gradient(-45deg, #006699, #9900CC);
color: #FFFFFF;
padding: 18px;
border: solid 5px transparent;
}
<input type="submit" name="submit" id="submit" value="Submit" required>
it's because the white linear-gradient on the wrapper background.
below I gave to the gradient the colors of the button and it's look fine now
.input-container {
background-image: linear-gradient(-45deg, #006699, #9900CC), radial-gradient(circle at top right, #006699, #9900CC);
background-origin: border-box;
background-clip: padding-box, border-box;
border: solid 5px transparent;
border-radius: 30px;
margin-bottom: 10px;
overflow: hidden;
box-sizing: border-box;
}
input[type=submit] {
width: 100%;
padding: 15px;
display: inline-block;
border: none;
outline: none;
border-radius: 30px;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
font-size: 15px;
background: #FFFFFF;
}
input[type=submit]:hover {
background-image: linear-gradient(-45deg, #006699, #9900CC);
color: #FFFFFF;
}
<div class="input-container">
<input type="submit" name="submit" id="submit" value="Submit" required>
</div>

Text inside inputfield is too close to the border

I have an input field that has a gradient border, but the text inside is too close to it.
And I have already tried padding-left, but that made the border on the left bigger, and the text was still close to the border.
The picture of the input field:
.inputfield {
margin-top: 5px;
-moz-appearance: none;
outline:0;
width: 170px;
height: 40px;
font-family: 'Montserrat', sans-serif;
color: white;
position: relative;
padding: 5px;
background-color: rgb(11, 15, 31);
border: solid 0.5px transparent;
border-radius: 80px;
background-image: linear-gradient(rgb(11, 15, 31), rgb(11, 15, 31)), radial-gradient(circle at top
left, rgb(76, 133, 242),rgb(144, 104, 235));
background-origin: border-box;
background-clip: content-box, border-box;
}
This is what it does when add padding-left
You could introduce a wrapper element around your input. A quick example built into your existing code would look something like this:
.input-wrapper {
width: 170px;
height: 40px;
padding: 5px;
border-radius: 80px;
background-image: linear-gradient(rgb(11, 15, 31), rgb(11, 15, 31)), radial-gradient(circle at top
left, rgb(76, 133, 242),rgb(144, 104, 235));
background-clip: content-box, border-box;
display: flex;
align-items: center;
}
.input-field {
outline: 0;
background-color: transparent;
color: white;
border: none;
width: 100%;
margin: 0 10px;
font-size: 16px;
}
<div class="input-wrapper">
<input class="input-field" value="TEXT">
</div>
Simply add padding-left to input[type=text].

Why can't I get a CSS button with Icon and no image?

I try to make into my button a css icon and not with image, and here is my css button :
Button :
<div>
<b>
<asp:Button ID="bt_VaildID" runat="server" Text="Valider" OnClick="bt_VaildID_Click" ValidationGroup="auGoup" CausesValidation="true" CssClass="bt_Valider" />
</b>
</div>
CSS:
.bt_Valider {
display: inline-block;
border: 2px solid #903E71;
color: #000000;
border-radius: 0;
-webkit-border-radius: 0;
-moz-border-radius: 0;
font-family: Verdana;
width: auto;
height: auto;
font-size: 16px;
padding: 6px 25px;
background-image: linear-gradient(to top, #903E71, #903E71);
background-image: -webkit-linear-gradient(to top, #903E71, #903E71); /* for safari */
background-color: #903E71;
float:right;
}
.bt_Valider:hover, .bt_Valider:after {
border: 2px solid #903E71;
color: #903E71;
background-image: linear-gradient(to top, #FFF, #FFF);
background-image: -webkit-linear-gradient(to top, #FFF, #FFF); /* for safari */
cursor:pointer;
content: "\279C"; /* I found that with this i can make some icon */
}
This code gives me this result : Output image
But I want to get it like this : Desired
not sure if this is your desired result.
be aware that with content: "\279C"; you are using an unicode character, se more here http://tutorialzine.com/2014/12/you-dont-need-icons-here-are-100-unicode-symbols-that-you-can-use/
.bt_Valider {
display: inline-block;
border: 2px solid #903E71;
color: #000000;
border-radius: 0;
-webkit-border-radius: 0;
-moz-border-radius: 0;
font-family: Verdana;
width: auto;
height: auto;
font-size: 16px;
padding: 6px 25px;
background-image: linear-gradient(to top, #903E71, #903E71);
background-image: -webkit-linear-gradient(to top, #903E71, #903E71); /* for safari */
background-color: #903E71;
/* float:right; */
}
.bt_Valider:hover, .bt_Valider:after {
/* border: 2px solid #903E71; */
color: #000000;
cursor:pointer; background:transparent;
content: "\279C"; /* I found that with this i can make some icon */
}
<div>
<b>
<Button ID="bt_VaildID" runat="server" Text="Valider" OnClick="bt_VaildID_Click" ValidationGroup="auGoup" CausesValidation="true" Class="bt_Valider" >Valider</Button>
</b>
</div>

Resources