My navbar has dropdown "fieldsets" for login and search like this:
<div class="nav-button" id="nav-box">
<a class="inside-link">
<span id="inside-text">Sign in</span>
</a>
<fieldset id="menu-box" class="menu-box">
<form method="post" id="forms" class="forms" action="checklogin.php">
<label for="username">Username or email</label>
<input type="text" id="username" name="username" value="" title="username" tabindex="4">
<label for="password">Password</label>
<input type="password" id="password" name="password" value="" title="password" tabindex="5">
<input type="submit" id="small-btn" value="Sign in" tabindex="6">
<input type="checkbox" id="remember" name="remember_me" value="1" tabindex="7">
<label for="remember">Remember me</label>
<br />
Forgot your password?
<a id='forgot_username_link' title="If you remember your password, try logging in with your email" href="#">Forgot your username?</a>
</form>
</fieldset>
</div>
I have a fiddle here: http://jsfiddle.net/WBrns/5/
While input boxes like "search" "username" and "password" are focused, I'd like the associated dropdown to not disappear so users don't have to keep their mouse within the dropdown while typing.
Line 288 in the CSS was our first attempt which obviously doesn't work. My site already includes jQuery so any js/jquery solution is acceptable (since I think it's not possible with pure css)
Thanks!
On your hover style, make sure the attributes have the !important command and then use the code below while remembering to substitute the id's and classes to what you need:
$("input").focus(function () { that=this;
$(this).parent(".drop").css("display", "block");
$(this).blur(function() {
$(that).parent(".drop").css("display", "none");
});
})
You can take a look at an example here: http://jsfiddle.net/WBrns/12/
If a user begins to type, the drop down should not disappear even if they move their mouse away. However, if they click outside of the drop down, it will be hidden.
To improve upon Shaz's answer, you can name the blur event to prevent multiple blur events from being attached to the same input. I also recommend using a class name and CSS to show and hide the drop down so that you can take advantage of CSS transitions.
JS
$('input').focus(function () {
var $this = $(this);
var $drop = $this.parents('.drop');
$drop.addClass('open');
$this.bind('blur.closeDrop', function () {
$drop.removeClass('open');
$this.unbind('blur.closeDrop');
});
});
CSS
.drop {
opacity: 0;
pointer-events: none;
transition: opacity 0.2s ease;
}
.drop.open {
opacity: 1;
pointer-events: auto;
}
Related
I have this piece of HTML which is updated dynamically with JS. The screen reader only reads out the new value when they get updated. It doesn't say the label of the input who was updated.
<ul class="points-transfer-detail-points-calculation clearfix">
<li>
<label for="points-to-transfer">{{{ pointsToTransferLabel }}}</label>
<input id="points-to-transfer" type="text" aria-controls="brand-points points-left-after-transfer" placeholder="XXX,XXX" {{#if disabled }}disabled{{/if}}>
<p id="points-to-transfer-error" class="points-transfer-detail-form-error" aria-hidden="true" role="alert">{{{ pointsToTransferErrorMessage }}}</p>
</li>
<li>
<label for="brand-points">{{{ brandPointsLabel }}}</label>
<input id="brand-points" type="text" aria-live="polite" aria-atomic="true" disabled>
</li>
<li>
<label for="points-left-after-transfer">{{{ pointsLeftLabel }}}</label>
<input id="points-left-after-transfer" type="text" aria-live="polite" aria-atomic="true" disabled>
</li>
</ul>
I have tried to use aria-labelledby, aria-describedby, role="alert" and aria-label but no results, only the value of the input and never his label.
From all my research on Google and StackOverflow, I didn't manage to found a proper answer.
I'm using NVDA in Firefox as a screen reader.
Thank you for your help.
The only time a label should be read by a screen-reader is when focus is placed on its corresponding field.
Your input fields are all disabled. Therefore the labels wouldn't be read since you can't focus into the fields.
Remove your aria-live and aria-atomic from your input fields. They are unusable on input fields. Aria-live is triggered on DOM change within the container it's assigned to. An input field is not a container. Also, labels shouldn't be announced that way anyway.
If you want to announce a change to the DOM I would suggest injecting content into an empty aria-live div at the bottom of your page and hide it accessibly.
Here is a working example with one static label and 3 dynamic labels. One uses the "disabled" attribute, and one uses aria-disabled so that it can still receive focus. An announcement about the rendering of the new labels is also featured using an accessibly-hidden aria-live container.
This has been tested in NVDA in FF, JAWS in IE, and VO in Safari.
(function () {
function populateLabels () {
document.querySelector('[for="dogsName"]').appendChild(document.createTextNode('Dog\'s Name'));
document.querySelector('[for="catsName"]').appendChild(document.createTextNode('Cat\'s Name'));
document.querySelector('[for="lastName"]').appendChild(document.createTextNode('Last Name'));
}
function announceChange () {
var announcement = "Some new labels have appeared. They are Last Name, Dog's Name, and Cat's Name.",
ariaLiveContainer = document.querySelector('[aria-live]');
ariaLiveContainer.appendChild(document.createTextNode(announcement));
setTimeout(function () {
ariaLiveContainer.innerHTML("");
}, 2000);
}
setTimeout(function () {
populateLabels();
announceChange();
}, 3000);
}());
input {
border: 1px solid black;
}
[disabled],
[aria-disabled="true"] {
border: 1px solid #ccc;
background-color: #eee;
}
.acc-hidden { /* Hide only visually, but have it available for screenreaders */
position: absolute !important;
display: block;
visibility: visible;
overflow: hidden;
width: 1px;
height: 1px;
margin: -1px;
border: 0;
padding: 0;
clip: rect(0 0 0 0);
}
<p>The first label is there on DOM load. The other three labels come in 3 seconds after DOM load. An announcement is made about the updated labels.</p>
<form action="">
<ul>
<li>
<label for="firstName">First Name</label>
<input type="text" name="first-name" id="firstName" />
</li>
<li>
<label for="lastName"></label>
<input type="text" name="last-name" id="lastName" />
</li>
<li>
<label for="dogsName"></label>
<input type="text" name="dogs-name" id="dogsName" disabled /> (uses the disabled attribute -- doesn't receive focus)
</li>
<li>
<label for="catsName"></label>
<input type="text" name="cats-name" id="catsName" aria-disabled="true" /> (uses the aria-disabled="true" attribute -- can receive focus)
</li>
</ul>
</form>
<div class="acc-hidden" aria-live="polite"></div>
<s:checkboxlist list="fruits" name="selectfruits" listKey="id" listValue="description" id="fruitsid">
Suppose I have the above checkboxlist that contains multiple checkboxes. I would like to change the background color to grey and the color of the label to white when the mouse hovers upon the respective checkbox or its label. How would I achieve this by changing its style in the css?
I tried the following in the css file by referring the checkboxlist's id but it does not work:
#fruitsid:hover {
color:white;
background-color:grey;
}
The generated HTML for the above code:
<input type="checkbox" name="selectfruits" value="Apple" id="selectfruits-1">Apple
<br/><br/></input>
<input type="checkbox" name="selectfruits" value="Melon" id="selectfruits-2">Guava
<br/><br/></input>
<input type="checkbox" name="selectfruits" value="Orange" id="selectfruits-3">Orange
<br/><br/></input>
<input type="checkbox" name="selectfruits" value="Guava" id="selectfruits-4">Grapefruit
<br/><br/></input>
<input type="checkbox" name="selectfruits" value="Pineapple" id="selectfruits-5">Melon
<br/><br/></input>
Is there any way where you can refer each label and change its css style like the one mentioned above?
Thanks!
You can use CSS3 startswith selector:
input[id^="selectfruits"]:hover{
/* your custom style here */
}
BTW checkboxes (and radiobuttons too) are special items, rendered differently basing on Browser / Operative System, and hard to style with CSS only.
The snippet above is correct to target an item (even a checkbox or a radiobutton), but the problem is that then you can't do what you ask. You could change the size or the position, for example, but not the color / background-color, because they don't have those properties.
There are several solutions to this, but the two most famous are:
Hiding the real checkbox and then showing another element (a span with an image, usually):
This is used when a crossbrowser/cross-OS rendering is mandatory, and/or when there is the need to show a better / different graphical object (I've used checkboxes with lock/unlock symbols, for example). But I guess it's not your case.
Wrapping the checkbox in another element (eg. a div) and then styling that element:
this appears to be your case. There is no need to wrap it in a div, btw, a label element next to the checkbox is enough for your case. The problem is that <s:checkboxlist/> tag is generating the HTML for you, without the labels, then you should avoid using this tag in order to be able to add your custom HTML;
change your tag with single checkboxes tags generated inside an iterator... or just with plain HTML elements, to keep it simple:
<s:iterator value="fruits" status="ctr">
<input type="checkbox"
name="selectfruits"
class="chkFruits"
value="<s:property value='%{id}'/>"
id="selectfruits-<s:property value='%{#ctr.count}'/>">
<label for="selectfruits-<s:property value='%{#ctr.count}'/>" class="lblFruits">
<s:property value='%{description}'/>
</label>
<br/><br/>
</s:iterator>
that will generate the following output, that you can style with standard selectors:
.chkFruits:hover + .lblFruits {
background-color: blue;
color: white;
}
<input type="checkbox" name="selectfruits" value="AWARD"
id="selectfruits-1" class="chkFruits" />
<label for="selectfruits-1" class="lblFruits">Apple</label>
<br/><br/>
<input type="checkbox" name="selectfruits" value="CLIST"
id="selectfruits-2" class="chkFruits" />
<label for="selectfruits-2" class="lblFruits">Guava</label>
<br/><br/>
<input type="checkbox" name="selectfruits" value="HAN"
id="selectfruits-3" class="chkFruits" />
<label for="selectfruits-3" class="lblFruits">Orange</label>
<br/><br/>
<input type="checkbox" name="selectfruits" value="POS"
id="selectfruits-4" class="chkFruits" />
<label for="selectfruits-4" class="lblFruits">Melon</label>
<br/><br/>
This answer works for all check in my webpages!
input[type="checkbox"]:hover + label {
color: #fff;
border-color: #1b7aa9;
background-color: #239fdb;
}
I have a form field box with class CCPPDisplayTD.
I'm trying to make it's length longer with CSS styling.
How do I use CSS to accomplish this?
<form>
<input type="text" /><br />
<input type="text" class="CCPPDisplayTD" />
</form>
.CCPPDisplayTD{
width: 200px;
}
See here: http://jsfiddle.net/GT8jD/
In your stylehseet you need the following:
.CCPPDisplayTD{
width: 250px; // whatever size you need.
}
Your HTML needs to resemble something similar to:
<form>
<label> /* Label elements are required for better accessibility */
<input type="text" class="CCPPDisplayTD" />
</label>
</form>
Or the following:
<form>
<label for="input-name"> /* Label elements are required for better accessibility */
<input type="text" class="CCPPDisplayTD" id="input-name" name="input-name" />
</label>
</form>
OK, I am really embarrassed that I cannot figure this out but...
I have form labels that are followed by a "required" asterisk. The asterisk simply drops to the next line under the label text instead of aligning next to the text.
I want the required asterisk to end up on the same line as the label text. I shouldn't have to use floats for this right? They are in the same div so I am not sure why they just don't lay next to each other.
Thanks!
<div id="letsGetStarted">
#using (Html.BeginForm())
{
#Html.ValidationSummary(true)
<div>#Html.LabelFor(model => model.NewClub.NewClubName) <span class="required">*</span></div>
#Html.EditorFor(model =>model.NewClub.NewClubName)
#Html.ValidationMessageFor(model => model.NewClub.NewClubName)
<div>
#Html.LabelFor(model => model.ClubTypes) <span class="required">*</span>
</div>
#Html.DropDownListFor(model => model.ClubTypes, Model.ClubTypes)
#Html.ValidationMessageFor(model => model.ClubTypes)
<p>
<input type="submit" name="submit" value="Submit" class="btn"/> <input type="reset" name="reset" value="Cancel" class="btn ltgrey" />
</p>
}
</div>
I have a working example of the issue here:
Wrap span into the <label></label>
<div>
<label for="NewClub_NewClubName">Name your club <span class="required">*</span></label>
</div>
you can set margin to move it to left according to your need:
Example
Updated Fiddle
Update
As you are using #LabelFor() so give this to your label:
display:inline;
If you cannot mess with HTML, but you can with CSS>
label{display:inline; clear:both;}
be careful, because this will affect all labels...
In plain HTML5 and CSS3, you can use the following rule. I don't know how to translate this to ASP.net:
.required:after {
content: "*";
}
Then, just write your HTML as
<div>
<label for="NewClub_NewClubName" class="required">Name your club.</label>
<input ...>
</div>
On the other hand, you can use the HTML5 required attribute, which I don't know how to translate to ASP. With placeholder, you might not need a label.
<div>
<input type="text" name="newClub" placeholder="New club name" required/>
</div>
You can style this using the pseudoclass :required. If you put the label afterwards so you can use the CSS3 adjacent selector, you can even try:
<div>
<input type="text" id="newClub" name="newClub"
placeholder="New club name" required/>
<label for="newClub">New club name.</label>
</div>
and
input:required + label:before {
content: "*";
color: red;
}
But again, I don't know ASP.
Try This
#letsgetStarted {
overflow:hidden;
}
#letsgetStarted label {
float:left;
width:auto;
}
#letsgetStarted span.required {
float:left;
}
Place your html text inside label tags.
I did not try it though. It should work for you.
I have a form with a textbox for email input and a button. The button is technically a HTML button here. The Form's HTML is like this:
<form class="form-wrapper cf">
<input type="text" placeholder="Enter your email here..." required>
<button type="submit">
Submit
</button>
</form>
JSFiddle Code: http://jsfiddle.net/ahmadka/aDhUL/
I'd like to convert the button type="submit" control to an input type="submit", while also keeping all the current CSS, so that visually there's no change. CSS would need to be updated I guess. I tried to do this myself, but I couldn't update the CSS correctly.
Can someone help me with this please ?
The basic solution requires changing the following everywhere in your CSS
button -> input[type=button]
input -> input[type=text]
I'd prefer to add a CSS class, instead of referencing the tag names, you could just use
<input type="text" class="text" />
<input type="submit" class="btn" />
That would require changing the following everywhere in your CSS
button -> input.btn
input -> input.text
This is not fully finished but almost works http://jsfiddle.net/aDhUL/7/
The problem is that the input:before directive inserts an element inside of the input. That is allowed for button, but not allowed for input , since input can't have child elements. http://coding.smashingmagazine.com/2011/07/13/learning-to-use-the-before-and-after-pseudo-elements-in-css/
So (if you want to use :before) you have to go back to a button, inserting a span element between the text field and the button won't allow you to have a hover effect on both the arrow and the button.
Why do you want to use input type="submit" in the first place?
You just need to change button to input[type=submit] in your stylesheets. If that doesn't work, then you'll need to be more specific about what problems you're having.
You will have to edit CSS, don't be lazy mate :)
<form class="form-wrapper cf">
<input type="text" placeholder="Enter your email here..." required>
<input type="submit" class="btn" value="submit">
</form>
CSS
.btn{
color:green;
}
Now you can also use after adding the class in CSS
<form class="form-wrapper cf">
<input type="text" placeholder="Enter your email here..." required>
<button type="submit" class="btn">Button</button>
</form>
All of the style sheets have to be updated to do so:
What is now this:
/* Form submit button */
.form-wrapper button {
Needs to become this:
/* Form submit button */
.form-wrapper input[type=submit] {
there are a bunch more classes to be updated below that one..
EDIT: changed it from a class to the style as joe points out.