I've stumbled upon an interesting challenge in css which I can't seem to figure out.
I'm trying to make a form field, quite similar to what google does in their login form, where the label is moved relatively to to the top when the form field has focus, covering part of the form field's border. This is rather easy when the background is white, as I can just set background-color: #fff on the label.
In my case, however, I have a full-screen image background, which means my label background has to be transparent for the background-image, but has to cover the border of the form field. Is this possible?
This is my form markup:
<form>
<div class="form-field__container">
<div class="form-field__wrapper">
<label class="form-field__label input--active">Email</label>
<input class="form-field__input form-field__input--text"
type="text">
</div>
</div>
</form>
The form-field has a border around it:
.form-field__input {
border: 2px solid #e6e6e6;
}
The input--active class is set when the form field has focus, which adds the following styles to the label:
top: -10px;
left: 10px;
z-index: 1;
This moves my label over the top-border of the form field. Normally, I would then just add a background-color to the label which is the same as the page background, set a display: blockon that, and the label would cover the part of the form field border, which would solve my issue.
I do however have an image as a page background, which means I can't set a background-color on the label, because this would also cover a part of the page background. Is there any css property which allows me to have the label behave in a way that cuts out the part of the top border of the form-field which is below the label but doesn't cut away any of the background-image?
Below is an image of what I've got so far, for clarification:
I'd really appreciate the help.
Greetz derelektrischemoench
That's what you have fieldset and Legend for:
<fieldset>
<legend>
<label class="form-field__label input--active">Email</label>
</legend>
<input class="form-field__input form-field__input--text" type="text">
</fieldset>
here's an alternative hack that hides the top border completely and uses additional elements to create border to the left and right of the label text...
it's different than your approach and element structure, but it may give you some hints in how to use other elements to emulate a top border
body {
font-family: sans-serif;
background: linear-gradient(to top right, pink, orange);
}
input {
border: 2px solid black;
border-top: 0;
background: transparent;
}
input:focus {
outline: none;
border-color: blue;
}
label {
display: flex;
flex-direction: column;
}
label:focus-within .top-border-replacement:before,
label:focus-within .top-border-replacement:after {
border-color: blue;
}
label:focus-within .label-text {
color: blue;
}
.top-border-replacement {
display: flex;
}
.label-text {
position: relative;
bottom: -7px;
display: inline-block;
font-size: 12px;
padding: 0 4px;
font-weight: bold;
}
.top-border-replacement:before {
content: '';
width: 10px;
border-bottom: 2px solid black;
}
.top-border-replacement:after {
content: '';
width: 100%;
border-bottom: 2px solid black;
}
<label>
<span class="top-border-replacement">
<span class="label-text">TEST</span>
</span>
<input type="text" />
</label>
Related
Hello I want to set the light gray outline outside gray border line just like in the following image.either there is a border position set or blur effect the input text.
Please tell me how can I fix this issue? I am doing all of this in css.
.container {
background-color: aquamarine;
width: 100%;
height: auto;
}
input[type="text"],
textarea,
textarea.form-control {
background-color: #efeeef;
width: 396px;
height: 48px;
border-radius: 4px;
border: 3px solid #cecece;
}
textarea.form-control {
line-height: 50%;
font-size: 16px;
color: red;
font-weight: 500;
}
<div class="container">
<!--Form element-->
<form>
<fieldset>
<input type="text" name="form-email" placeholder="Enter Your email" class="form-email form-control textarea border-color outline" id="form-email">
</fieldset>
</form>
</div>
When I am using shade effects it is also useless.Is there any way to set the position of the border in this input area.
Borders cannot be set to blur (at least directly). If you are using some sort of CSS library, say Bootstrap then it may be adding box-shadow to the input elements.
Setting the box-shadow: none; on the required input should solve the problem.
I am not a expert but try
form{
border: 1px(thickness) outset(type of border) grey(color)
}
for more information go to this link:
https://www.w3schools.com/css/css_border.asp
I want to make a website more accessible by considering user with high contrast mode (or maybe just dark mode).
Now I have a problem with custom radio buttons which are just HTML elements that have a round border: when the user has set the default background color of his browser to black, the background-color of my elements is also black, making it look like a checked option, even though I set the background-color of this elements to white.
To prevent this I made the white border thicker, so it looks like a white background. But it also creates the problem, that sometimes there is a tiny black dot in the middle of my buttons at some zoom-levels or resolutions.
Is there any way to prevent the browser from overwriting the background-color I declared in my CSS?
Is there anything I missed out on like an attribute that prevents this behaviour?
I could also replace this elements or implement them in a different way, but at this point i am just curious if there isn't any simple solution to that.
The style of my radio buttons looks like this:
input.check + label:before {
display: inline-block;
content: "";
width: 1rem;
height: 1rem;
background: #fefefe;
border: 0.2rem solid #fefefe;
border-radius: 50%;
position: absolute;
left: -1rem;
}
input.check:checked + label:before {
background: #000000;
}
Here is a link to a picture of my radio when checked / or default black background-color
I make the 'checked' look of my radio button by setting the background-color to black - like the browser does in this case.
Edit
So far there are good answers for improving the accessability of custom radio buttons.
To be a little bit more specific on my problem:
I tested the page in Firefox with the following color settings
But this seems to overwrite every background-color no matter what you specified for each element. Is there a way to make an exception for this overwriting?
Using a pseudo element - which is already mooted in the question - it is possible to style the button exactly as you would like.
The main difference in this snippet and the CSS in the question is that we set the actual input element to opacity 0. This means it is still 'there' for accessibility purposes but it can't be actually seen.
Also, using radial-gradient for coloring the buttons we can have rings of different colors, or just one color as best suits the background chosen. As the code in the question does, we also size everything in terms of rems so that the user who has changed their browser setting for this gets the benefit.
body {
background-color: black;
}
input {
opacity: 0;/* keep the input element in the DOM for accessibility it's just not seen*/
}
/* a pseudo element - this is what the user actually sees and we can style it */
label > input[type="radio"] + *::before {
content: "";
display: inline-block;
width: 2rem;
height: 2rem;
margin-right: 1rem;
border-radius: 50%;
border-style: solid;
border-width: 0.2rem;
border-color: white;
background: radial-gradient(white 0%, white 100%);/* choose what you want - one color or rings */
border-color: white;
}
label > input[type="radio"]:checked + *::before {
background: radial-gradient(red 0%, red 50%, white 50%, white 100%);/* choose what you want here too */
border-color: red;
}
label {
font-size: 2rem;
color: white;
}
<label>
<input type="radio" name="mybutton" value="A" checked />
<span>A</span>
</label>
<label>
<input type="radio" name="mybutton" value="B" />
<span>B</span>
</label>
<label>
<input type="radio" name="mybutton" value="C" />
<span>C</span>
</label>
In order to remove the default browser styling for the radio buttons you need appearance: none;
You will find more on that here, and you can check browser support here.
From there, you can use the background property to create the checked effect, you don't even need to use ::before.
I created this fiddle to demonstrate.
The code looks like this:
:root {
--background-color: white;
--text-color: black;
--fill-color: black;
--border-color: black;
}
#media (prefers-color-scheme: dark) {
:root {
--background-color: black;
--text-color: white;
--fill-color: white;
--border-color: white;
}
}
body {
background: var(--background-color);
color: var(--text-color);
}
div {
display: flex;
align-items: center;
}
input[type=radio] {
appearance: none;
margin: 0 0.5rem 0 0;
border: 1px solid var(--border-color);
border-radius: 50%;
width: 1rem;
height: 1rem;
}
input[type=radio]:checked {
background: radial-gradient(var(--fill-color) 0%, var(--fill-color) 30%, var(--background-color) 31%);
}
<p>Select an option:</p>
<div>
<input class="check" type="radio" id="huey" name="duck" value="huey" checked>
<label for="huey">Huey</label>
</div>
<div>
<input class="check" type="radio" id="dewey" name="duck" value="dewey">
<label for="dewey">Dewey</label>
</div>
<div>
<input class="check" type="radio" id="louie" name="duck" value="louie">
<label for="louie">Louie</label>
</div>
I'm trying to remove the border from an alt tag text. I'm using a transparent image for a button in a paypal form, linked through css. The paypal button takes the alt tag as it's button text and puts a border around it. I'm not clear on why this happens but it's what I have to work with from paypal. Apparently I have to use an image. So I'm using a transparent image so I can style it in css to look like my other buttons rather than try and get screen shots of each button state.
I paired the code down to focus on just the border around the text 'View Cart'.
CSS
//link to my transparent button with no text on it
#vyc {
background-image: url(http://lakenney.com/kenney_lucille-final/images/vyc.png) no-repeat;
}
//the user agent that is controlling the outer border
user agent stylesheetinput[type="hidden" i], input[type="image" i], input[type="file" i] {
-webkit-appearance: initial;
padding: 20px;
background-color: initial;
border: dotted;
border-top-color: red;
}
//a couple of tags I'm using to try to access the alt tag border not working
#vyc img[alt] {
/*border: 1px dashed #3D8EA5;*/
border: transparent !important;
}
input#vyc img[alt] {
border: transparent !important;
}
HTML
Here is a jsfiddle link to this same code:
http://jsfiddle.net/lakenney/w0zpmutn/
The input(type = "image") expects an src image which missing and hence the border. Is it possible for you to put the transparent image as the src value?
<input type="image" src="http://lakenney.com/kenney_lucille-final/images/vyc.png" id="vyc" border="0" name="submit" value="View Cart" alt="View Cart">
http://jsfiddle.net/w0zpmutn/2/
You can use a transparent image as the source to get rid of the border, but then you have no alt-text, but you could overlay some text.
document.querySelector('#input1').onfocus = function() {
console.log('clicked');
this.blur();
}
label {
position: relative;
width: 100px;
display: inline-block;
line-height: 3rem;
height: 3rem;
background: blue;
border: 0;
border-radius: 5px;
}
input {
width: 100px;
height: 100%;
}
.overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
text-align: center;
color: #FFF;
text-decoration: none;
}
<label for="input1">
<input id="input1" type="image" src="http://upload.wikimedia.org/wikipedia/commons/c/ce/Transparent.gif" />
<a class="overlay" href="#input1">
Some Text
</a>
</label>
But the form action would no longer work. so you would have to submit the form/redirect the page using javascript.
I want to align the checkbox, label and text input in a same line using css. I can do it by using the default template of the browser.
However I really liked the simple theme given in this link. The theme has label and a input text. I wanted to add a checkbox as well at the beginning of the line. Somehow adding a checkbox inside the div makes the arrangement awry.
Though its better to look at the code in the link, I am providing a snapshot here:
HTML
<form>
<div>
<!--NEED TO ADD CHECKBOX HERE -->
<label for="pub_url">Public URL</label>
<input type="text" id="pub_url" name="pub_url" value="http://cssdeck.com">
</div>
</form>
CSS3
/* Onto the styling now. Some quick generic styles first. */
html, body {
width: 100%; height: 100%;
}
body {
font-size: 76%;
font-family: Verdana;
background: #eee;
padding: 50px 0;
}
form {
background: #fafafa;
padding: 20px;
width: 400px;
margin: 0 auto;
border: 1px solid #ffe2e3;
}
form div {
/* Float containment */
overflow: hidden;
}
/* Things are looking good now, onto the main input field
styling now! */
/*
Lets change the box model to make the label and input
contain into the 100% div.
You might want to specify the box sizing properties inside
`* {}` at the top.
Things are looking great now! Lets just spice it up a bit.
*/
form label, form input {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
form label {
font-weight: bold;
background: linear-gradient(#f1f1f1, #e2e2e2);
padding: 5px 10px;
color: #444;
border: 1px solid #d4d4d4;
/* lets remove the right border */
border-right: 0;
border-bottom-left-radius: 5px;
border-top-left-radius: 5px;
line-height: 1.5em;
width: 30%;
/* takes the width properly now and also the
spacing between the label and input field got removed. */
float: left;
text-align: center;
cursor: pointer;
}
/* The label is looking good now. Onto the input field! */
/*
Everything is broken now! But we can fix it. Lets see how.
*/
form input {
width: 70%;
padding: 5px;
border: 1px solid #d4d4d4;
border-bottom-right-radius: 5px;
border-top-right-radius: 4px;
line-height: 1.5em;
float: right;
/* some box shadow sauce :D */
box-shadow: inset 0px 2px 2px #ececec;
}
form input:focus {
/* No outline on focus */
outline: 0;
/* a darker border ? */
border: 1px solid #bbb;
}
/* Super! */
p.s: It will be delightful if someone can stylize the checkbox in the same way as the example
try this one,
form input[type="checkbox"] {
width:20px;
}
<div>
<input type="checkbox" >
<label for="pub_url">Public URL</label>
<input type="text" id="pub_url" name="pub_url" value="http://cssdeck.com">
</div>
http://jsfiddle.net/KW6AY/1/
Here you go \w quick styling:
http://codepen.io/daniesy/pen/puema
alter the css to input[type="text"] and lower the width to around 60% (so it won't affect your checkbox), add a checkbox with a float left
just rename class
form input into form input[type="text"]
Good luck.
I have an input box
<span class="arrowDate"><input type="text" value="<?php echo $inputValue; ?>" id="<?php echo $id; ?>" class="datePickBox" /></span>
What I want to achieve is to add via css and image with and arrow in the right hand corner of the input box. If I change properties to the image, the properties of the input box should remain the same. Basically the image should be a type of overlay for the input box, but do not know how to do this.
.datePickBox{
font-size: 0.9em;
border: 1px solid #DEDEDE;
width: 270px;
position:relative;
right:0px !important;
padding-right:20px;
}
.arrowDate{ background:url('../images/arrow.png') no-repeat right center; border:1px solid #DEDEDE; }
Give your <input> a transparent background so the background of the <span> can shine thru and remove the border, because the border comes from the <span> in your case;
.datePickBox {
background: none;
border: none;
}
But your text will be over the background image, if long enough, so you can additionaly add a right padding as large as the image is wide.
.datePickBox {
background: none;
border: none;
padding-right: 20px; /* bg image width */
}
Given the mark-up:
<span><input type="text" id="textInput" name="textInput" />→</span>
I used the CSS:
span {
display: block;
width: 150px;
height: 30px;
position: relative;
background-color: #ffa;
text-align: right;
overflow: hidden;
border-radius: 1em;
border: 1px solid #ccc;
line-height: 30px;
padding: 0 0.5em 0 0;
}
span > input {
position: absolute;
top: 0;
left: 0;
right: 2em;
bottom: 0;
background-color: transparent;
border-radius: 1em 0 0 1em;
border-width: 0;
border-right: none;
outline: none;
}
To give the following JS Fiddle demo.
It's worth noting that I explicitly chose to place the arrow alongside the input, instead of 'overlaying' it above the input. It's also possible to amend my answer from the a similar question to create a comparable layout with a submit button alongside the input.
Can't get the image to display within the input box, with overlay I mean floating above the input box
you won't be able to get it floating above the text with background-image.
One way to do this would be to place the image next to the input field, and using relative positioning to move it above it.
CSS:
.boximage { position: relative; left: -40px; z-index: 2 }
HTML:
<input type='text'><img class='boximage' src='image.gif'>
better use this
<span><input type='text' /><img src='datepicker.jpg' /></span>
change the css to meet your overlay.. remove the right border of the text box