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;
}
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 .
This question already has answers here:
Two divs side by side - Fluid display [duplicate]
(9 answers)
In CSS Flexbox, why are there no "justify-items" and "justify-self" properties?
(6 answers)
Closed 1 year ago.
Just a simple css question. Trying to move the price next to the "Quick Shop" text. Basically trying to mirror this design:
.quick_shop_container{
width:100%;
}
.quick_shop{
background-color:white;
display:inline-block;
}
.quick_shop_text{
float:left;
}
.product-item-price{
float:left;
}
<div class="quick_shop_container" data-price-wrapper="">
<button class="quick_shop">
<span class="quick_shop_text">Quick Shop</span>
<div data-price-wrapper="">
<div class="product-item-price price" data-product-price="">| £51.95</div>
</div>
</button>
</div>
How do I move it?
Although flexbox is always better for 1D design. You can make your div inline-block so items it is inline.
Target it using > div, since you do not have a class. And add float : right to it.
.quick_shop_container{
width:40%;
}
.quick_shop{
background-color:white;
width: 100%;
}
.quick_shop > div{
display:inline-block;
float:right;
}
.quick_shop_text{
float:left;
}
<div class="quick_shop_container" data-price-wrapper="">
<button class="quick_shop">
<span class="quick_shop_text">Quick Shop</span>
<div data-price-wrapper="">
<div class="product-item-price price" data-product-price="">| £51.95</div>
</div>
</button>
</div>
I am not sure if you are supposed to use float, because of Browser Compatibility etc.. but if not, I guess this would be the solution.
.quick_shop_container{
width:100%;
}
.quick_shop{
background-color:white;
display:inline-block;
display: flex;
}
<div class="quick_shop_container" data-price-wrapper="">
<button class="quick_shop">
<span class="quick_shop_text">Quick Shop</span>
<div data-price-wrapper="">
<div class="product-item-price price" data-product-price="">| £51.95</div>
</div>
</button>
</div>
Add display:flex to the .quick_shop class
https://jsfiddle.net/k7jr4cwv/
Until you style it differently, a <div> is always a block-level element.
This leads an unstyled <div> to occupy its own vertical space within the document flow, beneath what has gone before.
In this case, we want to override that standard behaviour - so we can tell the <div> elements to display as if they are inline elements:
div[data-price-wrapper],
div[data-product-price] {
display: inline;
}
Working Example:
div[data-price-wrapper],
div[data-product-price] {
display: inline;
}
<div class="quick_shop_container" data-price-wrapper="">
<button class="quick_shop">
<span class="quick_shop_text">Quick Shop</span>
<div data-price-wrapper="">
<div class="product-item-price price" data-product-price="">| £51.95</div>
</div>
</button>
</div>
You can do it using flexbox.
.quick_shop {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
width: 500px;
padding: 20px;
background-color: white;
border: 2px solid #ccc;
font-size: 30px;
font-family: sans-serif;
}
.product-item-price {
border-left: 2px solid #ccc;
padding-left: 20px;
}
<button class="quick_shop">
<span class="quick_shop_text">Quick Shop</span>
<span class="product-item-price price">£51.95</span>
</button>
Try this. This will give you the same design without using the "|" character insertion.
.quick_shop_container{
width:200px; // this is container width
}
.quick_shop{
background-color:white;
display:inline-block;
width: 100%;
padding: 0.5rem;
border: solid 0.15rem #ccc;
}
.quick_shop_text{
float:left;
font-weight: bold;
float: left;
}
.product-item-price-wrapper {
}
.product-item-price {
padding-left: 0.5rem;
border-left: solid 0.15rem #ccc;
}
.product-item-price{
float: right;
font-weight: bold;
}
<div class="quick_shop_container" data-price-wrapper="">
<button class="quick_shop">
<span class="quick_shop_text">Quick Shop</span>
<div data-price-wrapper="" class="product-item-price-wrapper">
<div class="product-item-price price" data-product-price="">£51.95</div>
</div>
</button>
</div>
I have a button which is inside div
.calculateActivityBtn {
float: left;
margin-right: 1px;
cursor: pointer;
}
.pagination {
display: inline-block;
padding-left: 0;
margin: 20px 0;
border-radius: 4px;
cursor: pointer
}
<div class="calculateActivityBtn">
<div class="pagination centered">
<div class="btn btn-primary" id="getFilesButton" title="<%= language['UI.reports.tooltip.getFilesButton'] %>"><i class="glyphicon glyphicon-stats">button text</i></div>
</div>
</div>
when i hover on the div it gives me a hand cursor in chrome, but in firefox it does not show me a hand cursor till the pointer reaches the button icon .
I have tried changing z-index of the two div's and changing cursor:pointer in css.
I want a hand cursor when hovered on the div also in firefox.
Just use Padding instead of margin in pagination div..
check updated snippet...
.calculateActivityBtn {
float: left;
margin-right: 1px;
cursor: pointer;
}
.pagination {
display: inline-block;
padding-left: 0;
padding: 20px 0;
border-radius: 4px;
cursor: pointer;
background: red;
}
<div class="calculateActivityBtn">
<div class="pagination centered">
<div class="btn btn-primary" id="getFilesButton" title="<%= language['UI.reports.tooltip.getFilesButton'] %>">
<i class="glyphicon glyphicon-stats">button text</i>
</div>
</div>
</div>
use this css
.pagination:hover #getFilesButton{
cursor: pointer;
}
and be sure to support any specific browser for
browser support about cursor you can check it here
Caniuse cursor supported
Hope, it will work. let me know if you need more help
Using the attribute value in HTML, I can't make button text work in two lines as well as different font sizes
I have already tried whitespace in css but it's more like word wrap and that does not solve my problem. I also tried using ampersand-hash13; and ampersand-hash10; but it doesn't work as well.
#media (min-height: 280px) {
.divNumKeypad {
position: fixed;
bottom: 0;
width: 100%;
}
.numberBtn{
font-size: 30px;
height: 68px;
}
<div class="col-xs-4 ">
<input id="btnEight" type="button" tabindex="-1" value="HI HELLO" class="btn btn-primary btn-block numberBtn" onclick="buttonClick(8)" />
</div>
I expect to have a button with two lines of text. "HI" should be on the first line with bigger font and the bottom text "HELLO" should be smaller than the text on the top.
Try this below
#media (min-height: 280px) {
.line-1, {
display:block;
font-size: 20px
}
.line-2 {
display: block;
font-size: 10px;
}
}
<div class="col-xs-4 ">
<button>
<span class="line-1">HI</span>
<span class="line-2">HELLO</span>
</button>
</div>
Consider using button instead of input:
button {
font-size: 30px;
}
<button>HI<br><small>HELLO</small></button>
Try this.
label{
max-width: 150px;
font-size: 18px;
display: block;
padding:10px 20px;
border:1px solid black;
cursor: pointer;
}
label span{
display: block;
font-size: 14px;
}
label input{
background:none;
border:none;
}
input[value]{
font-size: 0;
display: none;
}
<div class="col-xs-4 ">
<label> <input id="btnEight" type="button" tabindex="-1" value="HI HELLO" class="btn btn-primary btn-block numberBtn" onclick="buttonClick(8)" />HI<span> HELLO</span></label>
</div>
I'm trying to vertically align a title header, an alert and two buttons.
My goal is to make the width of the alert bigger even if its content is short. My problem is that since I uses span for the alert, I need to put display: inline-block in its style but by doing that, the alignment with the header gets misaligned. BTW, I'm using Bootstrap.
Here's the image of what I want to happen:
Here's my HTML:
<h1>
<span>This will be a very long title</span>
<span class="alert custom">
This is notification!
</span>
<span class="pull-right">
<button class="btn button-round">O</button>
<button class="btn button-round">X</button>
</span>
</h1>
Here's my CSS:
.button-round {
border-radius: 50%;
color: white;
background: green;
}
.custom{
font-size: 12px;
vertical-align: middle;
background: green;
color: white;
}
Here's a jsfiddle of my current code:
JSFiddle of my current code
To make this easy, you should use flex :
.button-round {
border-radius: 50%;
color: white;
background: green;
margin: auto
}
.custom {
font-size: 12px;
vertical-align: middle;
background: green;
color: white;
/* added */
flex: 1;
margin: 0 0.25em;
}
h1 {
display: flex;
}
/* end added */
<!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>-->
<h1>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<span>This will be a very long title</span>
<span class="alert custom">
This is notification!
</span>
<span class="pull-right">
<button class="btn button-round">O</button>
<button class="btn button-round">X</button>
</span>
</h1>
https://jsfiddle.net/fczbe58L/1/