Getting a Custom Checkbox to Display Correctly - css

I am planning a page with about 20 or more checkboxes and I want to use a particular style of custom checkbox to match other things in other places on the website. Essentially, the aim is for an unchecked box to look like this
and the checked version will be coloured. At the moment I can colour the icon and the text but I'm drawing a blank with the border.
The HTML and PHP code is this:
<?php foreach ($amenity_array as $key => $value) {?>
<label class="amenity">
<input name="<?php echo $key ?>" type="checkbox" value="<?php echo $key ?>"><i class="icon-<?php echo $key ?>"></i><span><?php echo $value ?></span>
</label>
<?php }?>
The CSS is this:
.amenity{position:relative;border:1px solid #ccc;color:#ccc;padding:.25em;width:14.5em;margin:0 .5em .5em 0;float:left;white-space:nowrap;overflow:hidden; cursor:pointer}
.amenity input{z-index:-1;opacity:0;width:0}
.amenity i{color:#ccc}
/* Hover and focus states */
.amenity:hover input ~ i{color:#3498db}
/* Checked state */
.amenity input:checked ~ i{color:#5470a3}
.amenity input:checked ~ span{color:#007aba}
Obviously I need a third line under the checked state with
.amenity {border:1px solid #007aba}
but how do I invoke it only when the input is checked?

Considering basic documentation on html element :
The tag defines a label for an element.
The element does not render as anything special for the user. However, it provides a usability improvement for mouse users, because if the user clicks on the text within the element, it toggles the control.
The element does not render as anything special for the user. However, it provides a usability improvement for mouse users, because if the user clicks on the text within the element, it toggles the control.
The for attribute of the tag should be equal to the id attribute of the related element to bind them together.
EDIT :
The idea of your question is : "Can I apply a CSS property depending on the child state ?".
The answer is NO. It is impossible, and it has been answered many times on Stack Overflow already.
Thus, there are two mains solutions :
1) Use Javascript !
I too prefer making beautiful CSS solutions all the time, but in your case, javascript solves the problem in a second with any framework.
For instance in AngularJS but don't import this MVC for that, go for native javascript or the framework you are using:
ng-style="{'border' : disabled ? '1px solid red' : '1px solid blue'}"
Pros : Very fast, very simple, don't change your html structure at all.
Cons: Some people may feel dishonoured not succeeding in doing a pure CSS solution.
2) A CSS trick.
I just did one, you can see it on this fiddle. The idea was to create a sibling .absolute positioned div with the dimensions of the .amenity div, remove the border of the .amenity div and then apply it to absolute div.
As it is a sibling, we don't have the parent problem anymore and the trick is done.
Pros : Fast and understandable too, pure CSS solution.
Cons : You can use width 100%, but the height need to be hardcoded somehow. If you use SASS, it can be okay, but if the height of your icon or font change with the screen dimension, you'll need to use media queries or just put every height in em.
Don't forget to remove some pixels to height and width to keep some place for the border pixels !
Absolute div class :
.amenity .borderer {width : 100%; position: absolute; top: 0; left : 0; height : calc(37px - 4px); width : calc(100% - 2px); border:1px solid #ccc;}
Border change :
.amenity input:checked ~ div{border:1px solid #007aba}
New HTML :
<div class="amenity">
<label>
<input name="disabled" type="checkbox" value="disabled"><i
class="icon">D </i><span>Disabled Access</span>
<div class="borderer">
</div>
</label>
</div>

Related

how to make screen reader read document loading and document loaded?

What to do so that screen reader reads document loading while loading the document and document loaded when document component gets loaded in react?
Adding aria-busy="true" and aria-hidden="true" attributes to the component while loading will hide the content from screen readers temporarily.
For the announcement, somewhere else, create a <div role="status"> and add/remove child elements to it that will be announced when loading/loaded.
End result:
<main>
<Document
aria-busy={isLoading ? 'true' : null}
aria-hidden={isLoading ? 'true' : null}>
</Document>
<div role="status" class="visually-hidden">
{isLoading ? (
<span key="loading">
Document loading
</span>
) : (
<span key="loaded">
Document loaded
</span>
)}
</div>
</main>
The key props are there to make sure React doesn't reuse the same <span> element.
The .visually-hidden class makes it invisible except to screen readers:
.visually-hidden {
clip: rect(0 0 0 0);
clip-path: inset(50%);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}
You will need to see how to do the following in React, but the principles for AJAX page loading carry across to all SPAs.
The only difference between this and what you asked for is you don't announce "document loaded" instead you focus the <h1> on the page as that is more useful to screen reader users.
Before Loading
You need to signal to a user that a page is loading if you are using a SPA pattern (and therefore interrupting normal navigation).
e.g. I click your link you need to let me know that an action is being performed (loading.....) as you intercept the normal browser behaviour with e.preventDefault() or equivalent.
The simplest way is to use aria-live=assertive on a region that explains the page is loading.
You may want to visually hide this aria-live region (so that only screen readers can access it) so I have included a class to do this in the snippet below, however for the demo I have left the region visible. Here is a link to my original discussion on why to use this class to hide content.
After Loading
Additionally when the new page loads you need to manage focus.
The best way to do this is to add a level 1 heading (<h1>) to each page that has tabindex="-1".
Once the page loads the last action you perform in your JavaScript navigation function is to place the focus onto this heading and then clear the aria-live region
This has two benefits:
it lets the user know where they are now
it also lets them know when the page load is complete (as AJAX navigation doesn't announce when the page is loaded in most screen readers).
By using tabindex="-1" it means that the heading won't be focusable by anything other than your JavaScript so won't interfere with the normal document flow.
Example
var link = document.querySelector('a');
var liveRegion = document.querySelector('p');
var originalPage = document.querySelector('.currentPage');
var newPage = document.querySelector('.newPage');
link.addEventListener('click', function(e){
e.preventDefault();
liveRegion.innerHTML = "loading";
simulateLoading();
});
//this function simulates loading a new page
function simulateLoading(){
window.setTimeout(function(){
//this bit just hides the old page and shows the new page to simulate a page load
originalPage.style.display = "none";
newPage.style.display = "block";
//////////////ACTUAL CODE/////////////////
// grab the heading on the new page (after the new page has loaded fully)
var mainHeading = document.querySelector('.newPage h1');
//focus the main heading
mainHeading.focus();
// reset the aria-live region ready for further navigation
liveRegion.innerHTML = "";
}, 1000);
}
.newPage{
display:none;
}
<div class="currentPage">
<h1>Current Page</h1>
Click me to navigate
<p class="live-region visually-hidden" aria-live="assertive"></p>
</div>
<div class="newPage">
<h1 tabindex="-1">New Page Heading Focused Once Loaded</h1>
<button>Just a button for something to focus so you can see you can't refocus the H1 using the Tab key (or shift + Tab)</button>
<p>Below is the visually hidden class I mentioned, this can be used to hide the aria-live region visually if you wish, I have left it visible for demonstration purposes.</p>
<pre>
.visually-hidden {
border: 0;
padding: 0;
margin: 0;
position: absolute !important;
height: 1px;
width: 1px;
overflow: hidden;
clip: rect(1px 1px 1px 1px); /* IE6, IE7 - a 0 height clip, off to the bottom right of the visible 1px box */
clip: rect(1px, 1px, 1px, 1px); /*maybe deprecated but we need to support legacy browsers */
clip-path: inset(50%); /*modern browsers, clip-path works inwards from each corner*/
white-space: nowrap; /* added line to stop words getting smushed together (as they go onto seperate lines and some screen readers do not understand line feeds as a space */
}
</pre>
</div>

ngx-gallery width and height options missing

I'm wondering, how to give ngx-gallery (https://github.com/MurhafSousli/ngx-gallery) a new height. It has a fixed value of 500px and changing the parent divs height is not changing anything.
I was looking either for some attribute in the template like this
<gallery
[height] = '250px'>
</gallery>
Stackblitz: https://stackblitz.com/edit/angular-osh1vu
Followup-question: In the Stackblitz, the behaviour is fit-height (regarding the black background) and in my application it is fit-width, so the black stripes are above and under the image. How can i change this too?
(which was possible on older? version , but is no more a valid attribute)
or
some css code (looking in the dev tools, the sliding images are labeled div.g-template.g-item-template), which is also not possible to overwrite:
div.g-template.g-item-template {
height: 200px !important;
}
Demo add class to galery element
<div class="basic-container">
<h2>Gallery component</h2>
<gallery class="custom"
[items]="items"
[dots]=true
[thumb]=false
[loop]=false
[playerInterval] = 5000
[autoPlay]=true
[loadingStrategy]=preload>
</gallery>
</div>
in css change
.custom{
height:200px;
}

Make the width 100% of textarea inside an xeditable using angularJS

In this example when the user want to edit the row or to add a new one, you can see the width of text-area(Description column) don't follow the width of the td, so I added some CSS, but no changes. So how can I make the width take the 100% of the td using CSS ?
This is the code :
<span style="width:100%" editable-textarea="user.status" e-name="" e-form="rowform" e-ng-options="s.value as s.text for s in statuses">
{{ showStatus(user) }}
</span>
This is the EXAMPLE.
The span that you are adding width: 100% to actually gets hidden. What you need to do is update the CSS for the class of the span that appears that wraps the inputs. Seems to be .editable-wrap
http://jsfiddle.net/NfPcH/660/

Left-Positioning A Bootstrap Popover

I have a popover that appears to the left of a label:
$('label').hover(function () {
$(this).popover({
offset: 10,
placement: 'left'
}).popover('show');
The popover is currently blocking a radio button and I want to move it left, say, 10px. I can't seem to figure out how to do this. offset seems to do nothing at all (If I add 10 or 10000 it doesn't make a difference). Here is the HTML for one such label:
<label for="MainContent_Wizard1_rbLeader" id="MainContent_Wizard1_lblLeader" class="radio" data-original-title="Visionary Giving Level" data-content="Diamond (full-page ad) + 2 dinner tickets">Visionary ($250,000)<span class="radio" name="rbLeader"><input id="MainContent_Wizard1_rbLeader" type="radio" name="ctl00$MainContent$Wizard1$GivingLevel" value="rbLeader" onclick="WizardStep1_Click();" /></span></label>
I can try to set the popover position by overriding the class in CSS with something like:
.popover {
left: 380px !important;
}
but this is far from ideal as it appears in different spots using different browsers.
There must be a way of adding a small right margin, yes?
Thanks.
It seems rather impossible to style a single popover, and - as Sara mention - there is no such option as offset (you may think of qtip?). However, you can use the undocumented option template, "derived" from the tooltip options (in fact, popover only introduces content).
By modifying template you can individually style each popover! It seems to me your problem is the arrow more than the popover itself, so you can try to move the arrow up or down from the middle, simply by adding a style for arrow to the template, like this
$('label').hover(function() {
$(this).popover({
placement: 'left',
template: '<div class="popover"><div class="arrow" style="top:65px;"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"><p></p></div></div></div>'
}).popover('show');
});
of course, here the arrows for all popovers set for all labels will be modified due to the $('label').hover, but popovers can be styled individually without CSS if you want, those without radio buttons may not need to.
UPDATE - style the whole popover +10px to the left
...
template: '<div class="popover" style="margin-left:-10px;"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"><p></p></div></div></div>'
...
Try this to add the right margin:
.popover.left{
left: calc(100% - 10px) !important;
}
You can add data-placement='left' to the element.

opa textarea width

I'm using bootstrap and opa to display a textarea, and I don't manage to span my textarea over all the screen width.
I'm using the following simple code :
import stdlib.themes.bootstrap;
import stdlib.widgets.bootstrap;
WB = WBootstrap;
textInput = <textarea style="width=30%" rows=30> This is a text area </textarea>
text2Input = <textarea style="width=100%" rows=1> another textarea </textarea>
content = WB.Grid.row([{span:4, offset:none, content: text2Input}]) <+>
WB.Grid.row([{span:16, offset:none, content: textInput}])
Server.start(
Server.http,
[
{page: function() {content}, title: "test" }
]
)
I also try to use the following css :
textarea
{
border:1px solid #999999;
width:10%;
margin:5px 0;
padding:3px;
}
But it doesn't work either.
It seems that WBoostrap override all my change. The "width:100%" style doesn't appear in the xhtml generated by opa.
What is the correct way for doing that ?
Thanks
Well there are multiple problems in your code :
First, there is a typo : it is style="width:100%"
Second, Twitter Bootstrap 2.0 is now 12 columns width, so span16 has no meaning, you can write span12 at most (if you looked at http://bootstrap.opalang.org, it says up to 16 because it was written for BS <= 1.4)
Third, where did you write you CSS ? If it's directly in Opa (css = ...), it is indeed overwritten by Bootstrap CSS (since Opa CSS will be included before all other resources), so you will probably need to include an external CSS (you can have a look at https://github.com/Aqua-Ye/OpaChat)
Finally, WBootstrap.Grid does not really seem to be adapted to make 100% width elements.

Resources