Standardized way of graying out normal HTML text - html

Is there a standardized way of graying (greying) out text that is meant to be ignored, either in HTML, or bootstrap?
I tried looking at both how Slack styles the "(edited)" text, and how Twitter itself (twitter.com) styles timestamps, and it seems they just change the font color. It just seems strange to me that an arbitrary font color is chosen without any semantic information is attached to it, or even a standardized shade of gray.
The bootstrap documentation mentions some semantic colors, but gray isn't included in them - gray is only mentioned in grayscale.

There is actually a standard way to do it, in bootstrap, which is to use to use text-muted.
In fact, there is a list of standard text shades and colors that are applied directly.
http://www.w3schools.com/bootstrap/bootstrap_ref_css_helpers.asp
As for HTML, having a CSS with a disabled class and applying that to any of your text would be a better option.

Standard HTML Input Forms
An example of this is disabling HTML input elements, though there's not a standard display of that across browsers.
http://codepen.io/anthonyastige/pen/dXNEmx
<input type=button value="I can do all the things">
<input type=button value="I'm disabled" disabled>
Bootstrap Input Forms
There's also the concept of disabling input elements here with the .disabled class
https://getbootstrap.com/css/#checkboxes-and-radios
Bootstrap text
The .text-muted class implies disabled, though the specs don't say exactly what it means.
https://getbootstrap.com/css/#helper-classes

See samples below:
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<fieldset disabled>
<div class="form-group">
<label for="inputText">Disabled input</label>
<input class="form-control" id="inputText" type="text" placeholder="Disabled Input" disabled>
<p class="help-block">Example block-level help-block class text here.</p>
<p class="text-muted">Example block-level with text-muted class.</p>
</div>
<div class="form-group">
<label for="optionSelect">Disabled select menu</label>
<select id="optionSelect" class="form-control">
<option>Select Value</option>
</select>
</div>
<div class="checkbox">
<label>
<input type="checkbox">Disabled Checkbox
</label>
</div>
<button type="submit" class="btn btn-primary">Disabled Button</button>
</fieldset>

Related

Make bootstrap CHECKBOX look like bootstrap BADGE

I'd like to make bootstrap checkboxes that look like bootstrap badges, while retaining the checkbox functionality. I thought maybe I could simply style the checkbox label as a badge, but it didn't work.
<head>
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css'>
<script src='https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js'></script>
</head>
<div class='form-check m-1' style='display:inline-block;'>
<input id='".$tagDAT[1]."' name='".$tagDAT[1]."' type='checkbox' class='form-check-input form-check-inline'>
<label class='tag form-check-label text-capitalize' for='".$tagDAT[1]."'>
<span class='badge badge-secondary'>".$tagDAT[1]."</span></label>
</div>
This code is being echoed from PHP. The checkboxes look like regular checkboxes. It's ignoring the 'badge' code. I thought maybe since it was being echoed via ajax, the bootstrap in the html page wasn't affecting the echoed code. That's why i added the 'head' tag with the bootstrap. Still didn't work.
Anybody have ideas? Or a better way of getting the same result?
Move the checkbox inside the label
Remove the nested <span>
Apply .badge .badge-secondary directly to the <label>
Apply .form-check-inline to the wrapper not the input
Click anywhere on the .badge to check/uncheck the box.
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css'>
<div class='form-check form-check-inline m-1'>
<label class='tag form-check-label text-capitalize badge badge-secondary' for='myTag'>
<input id='myTag' name='myTag' type='checkbox' class='form-check-input'>myTag
</label>
</div>
Bootstrap 5 has got Toggle Buttons
<input type="checkbox" class="btn-check" id="btn-check" autocomplete="off">
<label class="btn btn-primary" for="btn-check">Single toggle</label>
<input type="checkbox" class="btn-check" id="btn-check-2" checked autocomplete="off">
<label class="btn btn-primary" for="btn-check-2">Checked</label>

Transforming a form to a read-only layout

I'm trying to create the layout for a profile page.
When the user is editing his profile, I want to display a form such as this one from the Bootstrap library: https://getbootstrap.com/docs/4.4/components/forms/#form-row . When the user is done editing, I want to convert the form to a read-only layout, by replacing the input fields with the text that has been entered.
I found an example on bootsnipp: https://bootsnipp.com/snippets/QoM7g (tab "Education&Career", for example). But when looking at the code, I noticed that this layout was constructed using the form-group class, and by replacing the input field with a paragraph field.
Is there a cleaner solution? I can't imagine this is how this kind of layout is meant to be written?
I would do something like this.
Add a fieldset with disabled attribute, all form element will be disabled.
Now add style to default form-control elements so that it will look like text.
Example below
fieldset[disabled] .form-control {
color:red;
border: none;
background-color:inherit;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="p-3">
<form>
<fieldset disabled>
<input class="form-control" type='text' value='John' />
<input class="form-control" type='text' value='John' />
<input class="form-control" type='text' value='John' />
<input class="form-control" type='text' value='John' />
</fieldset>
</form>
</div>
If you want to have elements in your form styled as plain text, use the .form-control-plaintext class to remove the default form field styling and preserve the correct margin and padding.
for Example:
<form>
<div class="form-group row">
<label for="staticEmail" class="col-sm-2 col-form-label">Email</label>
<div class="col-sm-10">
<input type="text" readonly class="form-control-plaintext" id="staticEmail" value="email#example.com">
</div>
</div>
<div class="form-group row">
<label for="inputPassword" class="col-sm-2 col-form-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="inputPassword">
</div>
</div>
</form>
Refer to this: https://getbootstrap.com/docs/4.4/components/forms/#readonly-plain-text
There is no need to replace the fields. You can just style them to look as text: hide the border and outline, make it read-only, make the background same as the outer background.
Example:
<input value="Regular input" />
<br>
<input class="like-text" value="I look like a text" readonly />
.like-text {
border: none;
outline: none;
}
https://jsfiddle.net/z879pbcn/

Working around <legend> as a direct child of <fieldset>

TLDR: see last example, it doesn't validate. Halp.
I'm using Bootstrap 3 to layout a form, in 2 columns like this:
<div class="form-group row">
<div class="col-sm-3">
<label for="c_title">Survey title</label>
</div>
<div class="col-sm-9">
<input name="c_title" id="c_title" >
</div>
</div>
So far so good. This looks right, and also validates.
Then, later in the form I have row which is a collection of options...
<div class="form-group row">
<div class="col-sm-3">Survey options</div>
<div class="col-sm-6">
<label><input type="checkbox" name="opt1" >option #1</label>
<label><input type="checkbox" name="opt2" >option #2</label>
<label><input type="checkbox" name="opt3" >option #3</label>
</div>
</div>
I think I really should use <fieldset> and <legend> there, to be nice...
<fieldset class="form-group row">
<legend class="col-sm-3">Survey options</legend>
<div class="col-sm-9">
<label><input type="checkbox" name="opt1" >option #1</label>
<label><input type="checkbox" name="opt2" >option #2</label>
<label><input type="checkbox" name="opt3" >option #3</label>
</div>
</fieldset>
With a bit of CSS to make it look sensible this also looks right and validates.
However I also want to drop an extra element or two into the left hand column. These might be a little popup text bubble, or some extra text noting constraints (e.g. "(max 200 chars)").
I don't think those bits belong inside the <legend> as such, and my understanding is that the whole <legend> gets read out for each form-control within the fieldset .. so that would be quite tedious to a11y users. (BTW, I'll probably link the legend to the span text via aria-describedby).
So I code it like this:
<fieldset class="form-group row">
<div class="col-sm-3">
<legend>Survey options</legend>
<span class="muted">(see HR manual page 321)</span>
<button type="button" id="beta2"></button>
</div>
<div class="col-sm-9">
<label><input type="checkbox" name="opt1" >option #1</label>
<label><input type="checkbox" name="opt2" >option #2</label>
<label><input type="checkbox" name="opt3" >option #3</label>
</div>
</fieldset>
This still looks right in the browser, however it does not validate. Apparently, the <legend> must be the first and immediate child of <fieldset>.
Any suggestions on how I might handle this? Is the html5 spec overly fussy on this point?
This might just work...
<fieldset class="form-group row">
<legend class="sr-only">Survey options</legend>
<div class="col-sm-3">
<div aria-hidden="true" role="presentation" class="fake-legend">
Survey options
</div>
<span class="muted">(see HR manual page 321)</span>
<button type="button" id="beta2">?</button>
</div>
<div class="col-sm-9">
<label><input type="checkbox" name="opt1">option #1</label>
<label><input type="checkbox" name="opt2">option #2</label>
<label><input type="checkbox" name="opt3">option #3</label>
</div>
</fieldset>
Here, the <legend> is now the first immediate child element of the fieldset (so it validates), but is then prevented from being visible on screen with Bootstrap's class="sr-only" (so is still available as an actual <legend> semantic element for screen readers).
Then, the text of the legend is repeated within the first column div, formatted to appear as if it were a legend (.fake-legend), and then removed for screen readers via aria-hidden="true" role="presentation".
aria-hidden is defined as
aria-hidden: Indicates that the element and all of its descendants are not visible or perceivable (i.e.presentable to users in ways they can sense) to any user as implemented by the author. (See related aria-disabled).
Authors MAY, with caution, use aria-hidden to hide visibly rendered content from assistive technologies only if the act of hiding this content is intended to improve the experience for users of assistive technologies by removing redundant or extraneous content. Authors using aria-hidden to hide visible content from screen readers MUST ensure that identical or equivalent meaning and functionality is exposed to assistive technologies.
role="presentation" is defined as
presentation (role): An element whose implicit native role semantics will not be mapped to the accessibility API.
The intended use is when an element is used to change the look of the page but does not have all the functional, interactive, or structural relevance implied by the element type, or may be used to provide for an accessible fallback in older browsers that do not support WAI-ARIA.

Bootstrap checkbox & radio lose the style

I use the codes same as the bootstrap3 sample as below:
<div class="checkbox">
<label>
<input ng-model="user.rememberMe" type="checkbox"> Remember Me
</label>
</div>
and got the style like:
not like its style in bootstrap sample
Bootstrap adds no special styles to a checkbox. We can easily verify this with a live example:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<form>
<div class="checkbox">
<label>
<input type="checkbox"> Check me out
</label>
</div>
</form>
You probably found a theme, fork or non-official example that adds special styles to the checkbox.

Bootstrap rendering inconsistency

I have a rendering inconsistency between Chrome (correct) and Firefox (incorrect) when using Bootstrap. This is my code (fiddle here):
<div class='container'>
<form class='form-horizontal well span6 offset3'>
<label class='control-label'>Testy</label>
<div class='controls'>
<select></select>
</div>
</form>
<legend>Hello!</legend>
</div>
What is the cause of the inconsistency? How can I fix the Firefox rendering so that it matches Chrome's?
It appears to be the way that Firefox and Chrome render the fieldset tag, at least with the non-responsive version of Bootstrap you're referencing. In an effort to eliminate variables, I removed the reference to Bootstrap and linked to bootstrapcdn.com's version, which seemes to fix the problem.
If nothing else, you could always add a bit of CSS to the fieldset tag to ensure it renders the same across all modern browsers.
fieldset { clear: both; }
Update: Looks like I was not paying attention, I've updated this answer to reflect CSS on the legend tag, rather than fieldset. JSFiddle Here.
legend { clear: both; }
The legend tag should be placed within the form tag and it should also have a fieldset tag placed around it.
See this example from Bootstrap:
<form>
<fieldset>
<legend>Legend</legend>
<label>Label name</label>
<input type="text" placeholder="Type something…">
<span class="help-block">Example block-level help text here.</span>
<label class="checkbox">
<input type="checkbox"> Check me out
</label>
<button type="submit" class="btn">Submit</button>
</fieldset>
</form>
And for your code it would be:
<div class='container'>
<form class='form-horizontal well span6 offset3'>
<fieldset>
<label class='control-label'>Testy</label>
<div class='controls'>
<select></select>
</div>
<legend>Hello!</legend>
</fieldset>
</form>
</div>