Putting css borders around radio buttons - css

I'm trying to get a garish red border around some radio buttons, but it is not showing up in Firefox latest or Chrome latest. Work fine in IE9/IE8.
Each of the input element on my form that are required has a data-val-required attribute put in by MVC3. All browsers puts in the red borders just dandy when we have a text or textarea inputs, but am struggling with the radio button. For IE, it works, but other browsers won't put the red border around it.
css:
input[data-val-required], select[data-val-required], textarea[data-val-required]
{
background-color: #F0FFFF;
border: 1px solid red;
}
view-source:
<label for="WaiveSelect">Do you waive confidentiality?</label><br />
<input data-val="true" data-val-number="The field WaiveSelect must be a number." data-val-required="Please select waive." id="WaiveSelect" name="WaiveSelect" type="radio" value="0" /> No, I do not waive confidentiality<br />
<input id="WaiveSelect_2" name="WaiveSelect" type="radio" value="2" /> Yes, I waive confidentiality<br />
<input id="WaiveSelect_3" name="WaiveSelect" type="radio" value="3" /> Yes, I waive confidentiality except to the client<br />
<span class="field-validation-valid" data-valmsg-for="WaiveSelect" data-valmsg-replace="true"></span>
What it looks like in IE (Firefox and Chrome shows no borders):

input[type=radio]{
outline: 1px solid red
}

I know this is four years old, but I came up with a nice solution using CSS Pseudo elements.
My requirement was to highlight an unchecked checkbox, or radio button in validation.
<input type="radio" class="required" name="radio1"/>
/* Radio button and Checkbox .required needs an after to show */
input[type=radio].required::after, input[type=checkbox].required::after {
display: block;
width: 100%;
height: 100%;
background: transparent;
content: '';
border: 2px solid red !important;
box-sizing: border-box;
}
/* Radio buttons are round, so add 100% border radius. */
input[type=radio].required::after {
border-radius:100%;
}

You could accomplish by wrapping each input element with div tag and give it a border and a float left... like this:
<div style="border:1px solid red;float:left">
<input type="radio".. />
</div>
No, I do not waive confidentiality

Not all browsers support borders around radio buttons and checkboxes. I voted for a bug years ago to have this included in Gecko but so far they haven't implemented it.

This may help you:
.style {
border: 1px solid red;
width: 20px;
height: 20px;
text-align: center;
margin-top: 2px;
background-color: #f0ffff;
}
<div class="style">
<input type="radio" />
</div>
<div class="style">
<input type="radio" />
</div>
<div class="style">
<input type="radio" />
</div>
<div class="style">
<input type="radio" />
</div>
View on JSFiddle

Complete code using jquery
https://jsfiddle.net/xcb26Lzx/
$(function(){
$('.layer').css('border',0);
$('input:radio').change(
function(){
if ($(this).is(':checked')) {
$('.layer').css('border','1px solid red');
}
});
});

Try this...
Put a div around the input and assign a class to the div like so:
<div class="custom"><input type="radio"></div>
Then open your custom css file and add this CSS
.custom {border: 1px solid red; border-radius: 30px; padding: 3px 3px 0 3px; background: red;}
This should create a nice red border around the radio button. If you're using a check box you would simply remove the border-radius: 30px from the css. Depending you may need to play with the padding a bit to center the button, but this worked for me.
Edit: You will also want to assign the following CSS to the div so it lines up correctly.
.custom {display: inline;}
fiddle link

Related

firefox button remove padding in firefox 77

I tried using the solutions found on stackoverflow to do this but it does not seem to work in newer versions of firefox. I want the red background to take up the entire button but this only works in the chrome, not firefox. I added the button::-moz-focus-inner css rules that should resolve this. Does anyone know how to do this in newer versions of firefox?
<style>
button {
padding: 0px;
}
label {
display: block;
padding: 1px 6px;
background-color: red;
}
button::-moz-focus-inner {
padding: 0;
border: 0;
}
</style>
<button>
<label for="myId">My Button</label>
</button>
<br />
<button>My Button</button>
<input id="myId" type="checkbox" />
You've put a label into a button, and are applying the red background to the label, not the button. You'd be better off not using a label tag, but if you need to, put the button in the label tag.
<style>
button {
/* Padding is pretty important for buttons */
padding: 3px 5px;
border: 0;
background-color: red;
cursor: pointer;
margin: 0px;
}
</style>
<button>My Button</button>
<!-- It is good practice to put labels right before what they are labeling -->
<label for="myId"><button>My Button</button></label>
<input id="myId" type="checkbox" />
I may be wrong, and by all means im not trying to be rude. But it looks like you're pretty new to web dev. Look up any css property or tag you're having trouble with on W3Schools. It's a great website.
Cheers, Isaac.

How to display red borders on required or invalid value input element in Chrome just like Firefox behaviour for HTML5 validation?

I have to bring red borders around the input element in chrome on HTML5 validation like as that of Firefox.
I have search it a lot but unable to find precise answer.
Any help of how to do it using css is greatly appreciated.
Thank you.
You use the :valid pseudo class.
To shamelessly copy the code from https://developer.mozilla.org/en-US/docs/Web/CSS/:valid:
input:invalid {
background-color: #ffdddd;
}
form:invalid {
border: 5px solid #ffdddd;
}
input:valid {
background-color: #ddffdd;
}
form:valid {
border: 5px solid #ddffdd;
}
input:required {
border-color: #800000;
border-width: 3px;
}
<form>
<label>Enter a URL:</label>
<input type="url" />
<br />
<br />
<label>Enter an email address:</label>
<input type="email" required/>
</form>
Try adding 'required' in the DOM element
<input name="heading" type="text" class="form-control" placeholder="heading" maxlength="35" required />

Why is a trailing <br> tag in one floating div able to push down another floating div on my page?

Currently the page is just two divs sitting side by side inside a containing section. I had two trailing <br> tags on qtr_calc, which were pushing down sem_calc. Shouldn't qtr_calc be able to have as many newlines at the bottom as I like without affecting sem_calc? If not, is there a workaround?
Somebody had a similar issue here, but there no explanation of why this is able to occur and the answer that helped them does not help me.
The divs' html:
<section id="content">
<div id="qtr_calc">
<label for="qtr_cred_hrs">Quarter class credit hours:</label><br />
<input type="text" id="qtr_cred_hours" /><br /><br />
<label for="qtr_grade">Letter grade:</label><br />
<input type="text" id="qtr_grade" /></div>
</div>
<div id="sem_calc">
<label for="sem_cred_hrs">Semester class credit hours:</label><br />
<input type="text" id="sem_cred_hours" /><br /><br />
<label for="sem_grade">Letter grade:</label><br />
<input type="text" id="sem_grade" /></div>
</div>
</section>
The divs' CSS:
#qtr_calc {
float: left;
margin: 3em;
padding: 2em;
border: 1px double #F2F2F2; /* inside border */
outline: 1px solid #BFBFBF; /* outside border */
}
#sem_calc {
float: left;
top: 0;
margin: 3em;
padding: 2em;
border: 1px double #F2F2F2; /* inside border */
outline: 1px solid #BFBFBF; /* outside border */
}
And here's a pastebin with the rest of the page, in case it helps somehow.
You have an extra closing div tag here:
<input type="text" id="qtr_grade" /></div>
Demo
Remove extra closing Div's and top:0; and try to give them width say 20%. That should solve you problem.

searchbox with jquery ui

I am trying to get my searchbox to look like that of facebook, where the button looks like it's inside the textbox. Please see the facebook home page.
I am using jquery ui and the graphics with it, for the button, problem is I think it adds borders to the button is creates, hence there is this separation between the text input and the button, anyway to get around this?
Here is my search form
<div class="div-search-form" style="display: inline; float: right;"><form method="get" id="search_form" class="" action="/searches">
<input type="text" value="Search" name="q" id="q" class="search-term" style="border: medium none;">
<span class="small-button"><a id="search_button" href="#" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only" role="button" aria-disabled="false" title="Search"><span class="ui-button-icon-primary ui-icon ui-icon-search"></span><span class="ui-button-text">Search</span></a></span>
</form>
</div>
UPDATE
I think I am getting there.
Here is my css
.search-button {
background-position: -160px -112px;
display: block; text-indent: -99999px; overflow: hidden; background-repeat: no-repeat;
background-image: url(images/ui-icons_ff0084_256x240.png);
float:left;
border-left: 0 !important;
background-color: white;
width:16px;
}
.search-term {
padding:1px 5px 1px 20px;
border: 0 !important;
float:left;
background-image: url(images/ui-bg_flat_0_eeeeee_40x100.png);
}
.search-term:focus{
background-image: none;
}
.div-search-form {
margin-right: 0;
float:right;
margin-top:5px;
}
AND THE markup
<div class="div-search-form"><form method="get" id="search_form" class="" action="/searches">
<input type="text" value="Search" name="q" id="q" class="search-term">
<a class="search-button" id="search-button" href="#"> </a>
</form>
</div>
Notice that unless I put a &nbps; the background image of the anchor tag doesn't show up. wonder why?
Also, Not sure how to make them both the same size and bigger in height. Right now they are both 16px in height, but If I play with the padding the alignment goes out of whack.
Essentially what you need to do is create an image that mirrors the style of the input field on the left.
You will float the input field next to the button.
For the input field on the left control the CSS so there is not a right border, also make sure you add some padding, so that the text doesn't run into the button.
input.search-term { float:left; border:1px solid #CCCCCC; border-right:none; padding:5px; }
On your image do not have a left border
.smallbutton a { float:left; border:1px solid #CCCCCC; border-left:none; background:url(../imagepath); disiplay:block; height:XXpx; width:XXpx; }
The trick isn't as much about a technical way to do it, rather being creative with the images and CSS you use to accomplish the goal.

Display image outside html element with CSS

is it possible to display an image outside of textbox with CSS only?
Please see my example below:
Of course, with CSS2 it is completely possible (although it is not supported by IE):
input.test:before
{
padding: 4px;
content: url(images/your_image.gif);
}
For more info, check out the following links:
http://www.quirksmode.org/css/beforeafter.html
http://www.w3.org/TR/CSS2/generate.html
If you want something that works in IE as well, you will have to do it with javascript, I'm afraid.
Why not make use of the label element? i.e:
<style>
.required { padding-right: 20px; background: url(...) no-repeat 50% 100%; }
</style>
<label class="required" title="This is a required field"><dfn>My Field:</dfn> <input type="text" /></label>
You could use a container:
CSS
#field-container
{
padding-right: 10px;
background: transparent url(images/dot.gif) middle right no-repeat;
}
HTML
<div id="field-container" class="form-row">
<label for="field">Field:</label>
<input type="text" value="" id="field" name="field" />
</div>

Resources