I have a form with some <button> elements in that I'm trying to get to work with the tab key for accessibility reasons. Each button has to be wrapped in a wrapper item, namely .item-wrapper.
I've added tabindex="0" to the button elements and to a .close <div> element that closes the component, and everything works as expected in Chromium based browsers.
However, in Safari when you tab through the form elements the focus is only applied to the .close element and then jumps outside of the form, and doesn't even get to the button elements. In Firefox the buttons tab as expected however the .close element doesn't take focus.
Is there no standard cross-browser behaviour for this in 2022 bearing in mind as humans we can also send rockets to Mars? And if not how do I have it so the when tabbing through the form, the focus goes from the .close through to each button in order as desired?
Codepen link: https://codepen.io/thechewy/pen/oNyzbJW
body {
margin: 0;
padding: 1rem;
display: flex;
justify-content: center;
}
form {
padding: 1rem;
background: #f7f7f7;
display: inline-block;
}
.close {
padding: 0.5rem;
background: lightblue;
display: inline-flex;
}
.item-wrapper {
margin: 1rem 0;
}
<form method="POST">
<div tabindex="0" class="close">X</div>
<div class="board-list">
<div class="item-wrapper">
<button tabindex="0" class="item" name="board-name">ITEM NAME 1</button>
</div>
<div class="item-wrapper">
<button tabindex="0" class="item" name="board-name">ITEM NAME 2</button>
</div>
<div class="item-wrapper">
<button tabindex="0" class="item" name="board-name">ITEM NAME 3</button>
</div>
<div class="item-wrapper">
<button tabindex="0" class="item" name="board-name">ITEM NAME 4</button>
</div>
</div>
</form>
Related
I am trying to make my two buttons appear on the far right of a piece of text. I want the text and two buttons to all be inline with each other but the text is on the left and the two buttons are on the right. I have seen multiple solutions and I could get it to work with only 1 button but when I have two buttons it does not work.
I run a for loop over 'weaknesses' and print out each weakness. Each weakness will have an update and delete action.
I tried to do margin-left but each weakness is a different length so my buttons would not line up
I also tried using some solutions from this post but could not seem to get the expected outcome: Place a button right aligned
Any help would be appreciated
HTML
<div *ngFor="let weakness of weaknesses | async">
<div class="flex-box">
<p>{{ weakness }}</p>
<a class="btn btn-light btn-sm pull-right" href="#">Update</a>
<button type="button" class="btn btn-danger btn-sm">Delete</button>
</div>
</div>
Try this:
#btnHolder {
position:fixed;
top:10px;
right:10px;
}
<p>Text is here</p>
<div id="btnHolder">
<button>Update</button>
<button>Delete</button>
</div>
I dont know why it was so hard. It should have been easier to fix this problem.
One solution is auto margin with flex
nav {
display: flex;
align-items: center;
}
nav button:first-of-type {
/* Key here is margin-left needs to be auto */
margin: 0 10px 0 auto
}
<nav>
<span>Text</span>
<button>Button 1</button>
<button>Button 2</button>
</nav>
You should do it like this:
.flex-box {
display: flex;
align-items: center;
justify-content: start;
}
#buttons{
margin-left: 10px;
}
<div class="flex-box">
<p>Text is here</p>
<div id="buttons">
<a>Update</a>
<button>Delete</button>
</div>
</div>
Currently the button is always below the last element that exists in the view.
Then I add bottom: 2px and position: absolute to the button and it goes to the bottom, but when I open the drop-down the screen is enlarged and the button is not at the bottom.
It currently works like this. I want it to continue working like this, but with the button at the bottom
Placing bottom: 2px and position: absolute the button goes to the bottom but when the drop-down is opened it overlaps.
<style>
.card-one{display:flex;}
.card-section{display:flex;margin:5px;text-align:center; min-height:300px;background:#000; flex-direction: column; width:33%;color:#fff;}
.card-section h2{color:#fff;}
.card-section .book-btn{margin-top:auto;}
</style>
<div class="card-one">
<div class="card-section">
<h2>Hello One</h2>
<button class="btn book-btn">Book Now</button>
</div>
<div class="card-section">
<h2>Hello One</h2>
<button class="btn book-btn">Book Now</button>
</div>
</div>
How do you position a button so it stays fixed?
I have an Angular app and when the 3rd option is displayed for a multiple choice, the next and back buttons move down.
Some of the questions only have 2 options and some have 3.
Is there a way to make it so that the buttons stay at one position? I tried using position property in css and margin-bottom, but no luck.
2 Options
3 Options
CSS
button {
background-color: #004273;
font-family: 'Roboto';
color: white;
border: 2px solid #93b9dd;
border-radius: 8px;
padding-top: 2%;
padding-bottom: 2%;
font-size: 1em;
}
.buttons2 {
width:48%;
float: right;
}
.buttons1 {
width: 48%;
float: left;
}
HTML
<h2 style="color: white;" align="center">{{statement}}</h2>
<h2 style="color: white;" align="center">{{question}}</h2>
<div class="radio-{{questionType}} col-sm-4 col-sm-offset-4 col-xs-offset-4">
<div class="form-check">
<mat-radio-group [(ngModel)]="selectedValue" class="options">
<mat-radio-button value="{{radio1}}">{{radio1}}</mat-radio-button> <br>
<mat-radio-button value="{{radio2}}">{{radio2}}</mat-radio-button> <br>
<span *ngIf="radio3">
<mat-radio-button value="{{radio3}}">
{{radio3}}
</mat-radio-button>
</span>
</mat-radio-group>
</div>
</div>
<div class="row">
<div class="col-sm-6 col-sm-offset-3" style="padding-top: 2%;">
<button *ngIf="state !== 1; else disabled_btn" class="buttons1 btn btn-primary" (click)="onClickedBack.emit(selectedValue)">BACK</button>
<ng-template #disabled_btn>
<button class="buttons1 btn" (click)="onClickedBack.emit(selectedValue)" disabled>BACK</button>
</ng-template>
<button class="buttons2 btn btn-primary" (click)="onClickedNext.emit(selectedValue)">NEXT</button>
</div>
</div>
You can use the :nth-child() CSS selector to modify the behavior of the options.
.options > :nth-child(3) {
height: 0;
overflow-y: visible;
}
The above selects the 3rd direct child of .options class element group, removes the height, but ensures that it still shows. You may have to adjust this based on other CSS.
This might be quite easy but I'm having problems getting this to work the way I need.
I'm using bootstrap and below is my css and div structure. I'm having 3 divs hidden and 3 buttons to make them visible. My problem is how do I make the divs be in the same level? At the moment the 3 divs are one below the other.
For Better understanding I've created a Fiddle.
<div class="row">
<div class="col-xs-6 col-xs-offset-3 col-sm-6 col-sm-offset-3 col-md-6 col-md-offset-3 wrapper">
<div class="groupHolder">
<div id="xx" class="overlapDiv" Style="background-color:#F00;">Fruits</div> // need these overlaping
<div id="yy" class="overlapDiv" Style="background-color:#888;">Flowers</div> // need these overlaping
<div id="zz" class="overlapDiv" Style="background-color:#f60;">Veggies</div> // need these overlaping
</div>
<div class="buttonHolder">
<button type="button" id="aa" class="standardBtn">Btn 1</button>
<button type="button" id="bb" class="standardBtn">Btn 2</button>
<button type="button" id="cc" class="standardBtn">Btn 3</button>
</div>
</div>
</div>
CSS visibility property just hide/show the element keeping the space of this element. If you want to remove the space of the element when it is invisible, you should use display property with block/none value.
like that :
https://jsfiddle.net/6Lf9spha/3/
Use this
.overlapDiv {display: inline-block;}
Z-index could work aswell
From what I understand you need, one of the possibilities is to not only make them invisible but hide them completely by changing visibility: hidden to display: none
$("#aa").click(function(){
$('.overlapDiv').css('display', 'none');
$('#xx').css('display', 'block');
});
overlapDiv{
display: block;
}
/* Make all elements except the first one hidden by default */
.overlapDiv:nth-child(n+2){
display: none;
}
Visibility affects if the element is visible, but does not change its playe in layout. ex. Element with visibility: hidden will still take space on the page, display: none will not.
$("#aa").click(function(){
$('.overlapDiv').css('display', 'none');
$('#xx').css('display', 'block');
});
$("#bb").click(function(){
$('.overlapDiv').css('display', 'none');
$('#yy').css('display', 'block');
});
$("#cc").click(function(){
$('.overlapDiv').css('display', 'none');
$('#zz').css('display', 'block');
});
.wrapper{
margin-top: 25px;
position: relative;
text-align: center;
}
.buttonHolder{
position: relative;
}
.groupHolder{
overflow: hidden;
position: relative;
}
.overlapDiv{
display: block;
}
.overlapDiv:nth-child(n+2){
display: none;
}
.standardBtn{
display: inline-block;
cursor: pointer;
padding: 12px 8px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">
<div class="col-xs-6 col-xs-offset-3 col-sm-6 col-sm-offset-3 col-md-6 col-md-offset-3 wrapper">
<div class="groupHolder">
<div id="xx" class="overlapDiv" Style="background-color:#F00;">Fruits</div>
<div id="yy" class="overlapDiv" Style="background-color:#888;">Flowers</div>
<div id="zz" class="overlapDiv" Style="background-color:#f60;">Veggies</div>
</div>
<div class="buttonHolder">
<button type="button" id="aa" class="standardBtn">Btn 1</button>
<button type="button" id="bb" class="standardBtn">Btn 2</button>
<button type="button" id="cc" class="standardBtn">Btn 3</button>
</div>
</div>
</div>
I'm new to bootsrap, so this question might be trivial, but I'm having problem sizing labels.
Here is a simple code snippet:
<div class="container">
<div class="row">
<div class="col-xs-3">
<input type="submit" value="<< Back" class="btn btn-danger btn-block"></input>
</div>
<div class="col-xs-9">
<label class="label-info label col-xs-12">This label is too little!</label>
</div>
</div>
</div>
You can find a working JSFiddle here:
http://jsfiddle.net/DTcHh/2446/
As you can see the input occupies the 3 columns it is assigned correctly and is also taller than the label. I'd like the label to:
Be the same height as the button
Fill up all the available horizontal space (the 9 columns it is assigned, as opposed to only filling up the space needed for the text, as it is doing now).
The behavior is correct for the button thanks to the btn-block class which makes it fill the available 3 columns, but there isn't an equivalent for the label.
How can I achieve this? It's probably really simple but I'm a noob at web stuff and bootstrap in particular, can anybody enlighten me?
The base .label style won't allow that. My advice would be to define your own .label-block style which you can use in place of label. Something like this would work
.label-block {
font-weight: normal;
display: block;
padding: 6px 12px;
margin: 0;
border: 1px solid transparent;
color: #fff;
text-align: center;
white-space: nowrap;
vertical-align: baseline;
border-radius: .25em;
width: 100%;
}
And then within your html, just use that style instead of label
<div class="container">
<div class="row">
<div class="col-xs-3">
<input type="submit" value="<< Back" class="btn btn-danger btn-block"></input>
</div>
<div class="col-xs-9">
<label class="label-info label-block">This label is too little!</label>
</div>
</div>
</div>
JSFidlle for reference.