I need a button group like the one shown in the code below and want to apply a border-shadow when the user hover's on top of a button.
The elements seem to be staking on top of each other from left to right, covering the right side's border-shadow.
How can I prevent this?
I tried z-index and doesn't work on my code but I can see it working on other people's code snippets...
.btn:hover {
box-shadow: 0 0 0 0.2rem red
}
div {
display: flex;
}
<div>
<button class="btn">
BTN
</button>
<button class="btn">
BTN
</button>
<button class="btn">
BTN
</button>
<button class="btn">
BTN
</button>
</div>
When you create a flex container with display: flex the <button> elements group together and the space in between each element is removed. To prevent this and allow your box-shadow to be more visibly seen, you could just add a bit of margin to each child <div> in the flex container.
If you don't want to add margin to separate the buttons, you can add the z-index property to the buttons hovered state so when you hover a <button> the box shadow appears and "stacks" above the other buttons. Remember, z-index only works on "positioned" elements:
postion: relative
position: absolute
position: fixed
position: sticky
From the Flexible Box Layout Spec, "Flex items do respect z-index" so if you have items in a flexbox container, they are eligible to utilize z-index without explicitly adding position.
.btn:hover {
box-shadow: 0 0 0 0.2rem red;
box-shadow: 0 0 0 0.2rem rgba(233, 181, 12, 0.6);
z-index: 99;
}
div {
display: flex;
}
div > button {
/* margin: 0 .5rem; */
/* position: relative; not necessary for flexbox children */
}
<div>
<button class="btn">
BTN
</button>
<button class="btn">
BTN
</button>
<button class="btn">
BTN
</button>
<button class="btn">
BTN
</button>
</div>
All you need to do is give a z-index to the hovered button
.btn:hover {
box-shadow: 0 0 0 0.2rem red;
z-index: 1000
}
div {
display: flex;
}
<div>
<button class="btn">
BTN
</button>
<button class="btn">
BTN
</button>
<button class="btn">
BTN
</button>
<button class="btn">
BTN
</button>
</div>
.btn{
margin:5px 10px;
}
.btn:hover {
box-shadow: 0 0 0 0.2rem red
}
div {
display: flex;
}
<div>
<button class="btn">
BTN
</button>
<button class="btn">
BTN
</button>
<button class="btn">
BTN
</button>
<button class="btn">
BTN
</button>
</div>
Give the button position relative. Then make the z-index: 100; on hover
button{
position: relative;
}
button:hover{
z-index: 100;
}
Related
A button name in my html has two text, when I click the second text only the button click is working. Need to make the entire button clickable and show pointer cursor when I mouse over.
<div class="d-flex">
<button (click)="myfunction()" type="button" class="btn btn-primary" *ngIf="currentPath!=
'/users/userlist'">Car List</button>
</div>
It's simple: cursor: pointer;
Just like this:
.d-flex {
display: flex;
justify-content: center;
align-items: center;
}
.d-flex .btn {
border: 1px solid #000;
background-color: #000;
color: #fff;
padding: 10px;
cursor: pointer;
}
<div class="d-flex">
<button (click)="myfunction()" type="button" class="btn btn-primary" *ngIf="currentPath!=
'/users/userlist'">Car List</button>
</div>
See more at: https://developer.mozilla.org/en-US/docs/Web/CSS/cursor .
I am a beginner to angular. What i have currently is a sidenav container with the content being a mat toolbar. Now my question is, as you can see, when it's viewed with a full sized desktop, the background colour of the toolbar stretched and filled the entire width, whereas when it's viewed with a phone, the background colour is not filled all the way leaving some gap that's not pleasant to look at.
I have tried setting mat sidenav content width to be 100% thinking that it would take up the entire space of the width
For further information, this is the html.
<mat-sidenav-container class="sidenav-container">
<mat-sidenav #drawer
class="sidenav"
fixedInViewport
[attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
[mode]="(isHandset$ | async) ? 'over' : 'side'"
[opened]="false">
<mat-toolbar>
<button mat-button
(click)="drawer.close()">
<mat-icon>close</mat-icon>
</button>
</mat-toolbar>
<mat-nav-list>
<a mat-list-item
routerLink="/"
(click)="drawer.close()">Home</a>
<a mat-list-item
routerLink="/products"
(click)="drawer.close()">Products</a>
</mat-nav-list>
</mat-sidenav>
<mat-sidenav-content>
<mat-toolbar>
<button type="button"
aria-label="Toggle Sidenav"
mat-icon-button
(click)="drawer.toggle()">
<mat-icon aria-label="Side nav toggle Icon">menu</mat-icon>
</button>
<span class="logo"
routerLink="/">
<img class="ww-logo"
src="assets/images/WWtrans.png" />
</span>
<div>
<button mat-button
class="button">
<mat-icon aria-label="Search for a product"
svgIcon="search"></mat-icon>
</button>
<button mat-button
class="button">
<mat-icon aria-label="Login if the user hasn't logged in yet"
svgIcon="login"></mat-icon>
</button>
<button mat-button
class="button">
<mat-icon aria-label="Show what's inside the cart"
svgIcon="shopping-cart"></mat-icon>
</button>
</div>
</mat-toolbar>
</mat-sidenav-content>
</mat-sidenav-container>
and here is the css
.logo {
display: flex;
margin: auto auto;
outline: none;
align-self: center;
justify-content: center;
align-self: center;
min-width: 100px;
max-width: 100px;
.ww-logo {
width: 60%;
cursor: pointer;
}
}
.button {
border: 1px solid red;
width: 10px;
}
.sidenav-container {
height: 100%;
width: 100%;
}
mat-sidenav-content {
width: 100%;
}
Thank you for any help in advance
You seem to be running into an issue with your mat-toolbar elements overflowing their horizontal space. You may be able to make some adjustments to the space your logo is taking up.
Also, I see that in your .button class you have added width: 10px; however it looks like this is not being applied. One reason for this is that mat-button comes with a style that specifies min-width: 64px; that you may need to override if you would like your buttons to scale down in size.
If the above approach works, you may also want to adjust the padding of your buttons as well. The following may be helpful, but I was not able to actually test it:
.button {
border: 1px solid red;
min-width: 32px !important;
padding: 2px !important;
}
I want to display set of buttons which I wrapped with a span element on a hovering effect, initially one button will be shown and when user hovers over the span element initially showed button will be hidden and other buttons will be shown.
.listbtn {
opacity: 0;
transition: opacity .35s ease;
}
.buttons:hover .listbtn {
opacity: 1;
}
.settingsbtn {
opacity: 1;
transition: opacity .35s ease;
}
.buttons:hover .settingsbtn {
opacity: 0;
}
.btn {
padding: 6px 12px;
display: inline-block;
margin-top: -10px;
text-transform: capitalize;
margin-left: 6px;
float: right;
}
.spaceTest {
margin-left: 32px;
}
.listbtn {
opacity: 0;
transition: opacity .35s ease;
}
<span class="buttons">
<button type="submit" class="btn btn-danger pull-right settingsbtn">
<i class="material-icons">settings</i>
</button>
<a routerLink="/errors/{{message.id}}">
<button type="submit" class="btn btn-danger pull-right listbtn">
<i class="material-icons">content_paste</i>
</button>
</a>
<button *ngIf="isScanning" type="submit" class="btn btn-danger pull-right spaceTest listbtn">
<i class="material-icons">refresh</i>
</button>
<button type="submit" class="btn btn-danger pull-right listbtn">
<i class="material-icons">delete</i>
</button>
<button type="submit" class="btn btn-danger pull-right listbtn">
<i class="material-icons">mode_edit</i>
</button>
</span>
The problem I am facing is when user moves mouse between delete and rescan buttons icons are disappearing which shouldn't be as I am using css hovering for the span. Could you please describe to me what I am doing wrong?
The issue you are encountering is caused by the pull-right classes that are added to your button elements. This causes the buttons to be floated to the right and therefore the wrapper span element cannot be hovered over when pointing your cursor between your floated buttons.
Here is a CodePen I made to demonstrate your issue: https://codepen.io/robertcooper_rc/pen/mqYGKN. I've got the functionality working as you desire at the moment, but if you uncomment the last three lines of CSS, you will see how the pull-right class affects the hovering of your buttons.
The styles for pull-right are added through Bootstrap. See the documentation for Bootstrap quick floats here: https://getbootstrap.com/docs/3.3/css/#helper-classes-floats
Solution - Clearfix
One way to solve this is by applying a "clearfix" to the span element to take care of all the floated elements inside of it. Here is what a clearfix looks like in CSS:
// Clearfix
.buttons:after {
content: "";
display: table;
clear: both;
}
The clearfix forces the span element to take up a width and height that is large enough to contain the floated elements. Without the clearfix, the span's height collapses to 0 if all child elements are floated and this is what is preventing you from hovering over the span.
I am wondering how can I make some buttons to stack vertically and not horizontally in css.
So, the html would be like:
<button>Test<button>
<button>Test<button>
<button>Test<button>
And those buttons will by default stack horizontally, what I want is to make them stack vertically (so everyone's on top of the next button).
Define the buttons as block-level elements. Also, note the use of the correct closing tag (</button>):
button {
display: block;
}
<button>Test</button>
<button>Test</button>
<button>Test</button>
<buttons> are inline-block elements by default. You can change that by styling the display to block instead:
button {
display: block;
}
<button>Test</button>
<button>Test</button>
<button>Test</button>
as they have explained above, buttons element come with inline display property by default. you need to make display: block; to achieve your desired result:
p{
font-family: arial;
font-weight: bold;
}
.button{
background-color: #2a609a;
width: 130px;
height: 60px;
color: white;
outline: none;
font-size: 16px;
border: none;
cursor: pointer;
}
.block-display button{
margin-bottom:5px;
display:block;
}
.button:hover{
background-color: #32CD32;
font-size: 20px;
transition: 0.5s;
}
<div class="default-display">
<p> buttons with defualt display: </p>
</br>
<button class="button">Button 1 </button>
<button class="button">Button 2 </button>
<button class="button">Button 3 </button>
</div>
</br>
<div class="block-display">
<p> buttons with block display: </p>
</br>
<button class="button">Button 1 </button>
<button class="button">Button 2 </button>
<button class="button">Button 3 </button>
</div>
You can do this with your css
button {
display: block;
}
I have a group of buttons:
<div class="row">
<button type="button" class="btn btn-warning btn-lg clearButton" onclick="resetSignature();"> Reset </button>
<button type="button" class="btn btn-warning btn-lg skipButton" onclick="skipQuestion();">Skip Question</button>
<button type="button" class="btn btn-success btn-lg nextQuestionButton" onclick="goToNextQuestion();"> Next Question → </button>
</div>
(I am using bootstrap). And I have some css:
.nextQuestionButton, .skipButton {
float: right;
margin: 5px 5px 5px 5px;
width: auto;
font-size:16px;
}
.clearButton {
float: left;
margin: 5px 5px 5px 5px;
font-size: 16px;
width: auto;
}
#media screen and (max-width: 500px) {
.clearButton, .skipButton, .nextQuestionButton {
width: 100%;
float: none;
}
}
This generates output like so:
My problem is that I want the green button to be the farthest to the right on a wide screen, and the bottom button on a narrow screen. I tried re-ordering the buttons (among other things), but then it ruined the order on narrow screens. How can I get the green button to line up on the right of the yellow one?
EDIT: Here is a jsFiddle
See this fiddle
I've changed your HTML a little bit
<div class="row">
<button type="button" class="btn btn-warning btn-lg clearButton" onclick="resetSignature();">Reset</button>
<div class="pull-right">
<button type="button" class="btn btn-warning btn-lg skipButton" onclick="skipQuestion();">Skip Question</button>
<button type="button" class="btn btn-success btn-lg nextQuestionButton" onclick="goToNextQuestion();">Next Question →</button>
</div>
</div>
and your CSS as
.nextQuestionButton, .skipButton {
margin: 5px 5px 5px 5px;
width: auto;
font-size:16px;
}
.clearButton {
float: left;
margin: 5px 5px 5px 5px;
font-size: 16px;
width: auto;
}
#media screen and (max-width: 500px) {
.clearButton, .skipButton, .nextQuestionButton {
width: 100%;
float: none;
}
}
What I have done is that, i enclosed two of your buttons in a div which is floated right instead of the buttons. To float right the div, I used the bootstrap class pull-right.
UPDATE
See the updated fiddle
.green {
float:left;
}
#media screen and (max-width: 300px) {
.green {float:right;}
}
just float it in different collection when screen is small.