Make button group that flows vertically to horizontally cleanly - css

I've used a normal bootstrap 3 button group in a size one column, e.g.
<div class="col-sm-1">
<div class="btn-group">
<button class="btn btn-default"><span class="glyphicon glyphicon-home"></span></button>
<button class="btn btn-default"><span class="glyphicon glyphicon-circle-arrow-left"></span></button>
<button class="btn btn-default"><span class="glyphicon glyphicon-volume-down"></span></button>
<button class="btn btn-default"><span class="glyphicon glyphicon-volume-up"></span></button>
<button class="btn btn-default"><span class="glyphicon glyphicon-off"></span></button>
<button class="btn btn-default"><span class="glyphicon glyphicon-zoom-out"></span></button>
<button class="btn btn-default"><span class="glyphicon glyphicon-zoom-in"></span></button>
</div>
</div>
This is vertical when there is space, but when it drops to a new row it becomes horizontal. My only problem is that when vertical it looks a bit odd. I've tried playing with the CSS to no avail, does anyone have advice? I don't mind making it fully square so horizontal/vertical are similar, but my efforts to do this have not worked

If fully square buttons are ok to you, something like this should work:
CSS:
#group button:first-child, #group button:last-child {
border-radius: 0;
}
#group button:first-child {
margin-left: -1px;
}
HTML:
<div class="col-sm-1">
<div id="group" class="btn-group">
<button class="btn btn-default"><span class="glyphicon glyphicon-home"></span></button>
<button class="btn btn-default"><span class="glyphicon glyphicon-circle-arrow-left"></span></button>
<button class="btn btn-default"><span class="glyphicon glyphicon-volume-down"></span></button>
<button class="btn btn-default"><span class="glyphicon glyphicon-volume-up"></span></button>
<button class="btn btn-default"><span class="glyphicon glyphicon-off"></span></button>
<button class="btn btn-default"><span class="glyphicon glyphicon-zoom-out"></span></button>
<button class="btn btn-default"><span class="glyphicon glyphicon-zoom-in"></span></button>
</div>
</div>

I had created something like this before.
DEMO: http://jsbin.com/vahaq/1/
Assumes vertical on 768px and up, which is what it is, so I've just modified the styles below that min-width.
HTML (same as yours but with btn-group-vertical and btn-group-custom)
<div class="col-sm-1">
<div class="btn-group-vertical btn-group-custom">
<button class="btn btn-default"><span class="glyphicon glyphicon-home"></span></button>
<button class="btn btn-default"><span class="glyphicon glyphicon-circle-arrow-left"></span></button>
<button class="btn btn-default"><span class="glyphicon glyphicon-volume-down"></span></button>
<button class="btn btn-default"><span class="glyphicon glyphicon-volume-up"></span></button>
<button class="btn btn-default"><span class="glyphicon glyphicon-off"></span></button>
<button class="btn btn-default"><span class="glyphicon glyphicon-zoom-out"></span></button>
<button class="btn btn-default"><span class="glyphicon glyphicon-zoom-in"></span></button>
</div>
</div>
This is more elaborate as it kicks in and kicks off for really good responsiveness:
#media (max-width:299px) {
.btn-group-vertical.btn-group-custom > .btn {
float: left;
width: auto;
width: 25%;
min-height: 50px;
min-width: 50px;
margin-top: -1px!important;
}
.btn-group-vertical.btn-group-custom .btn + .btn {
margin-left: -1px;
margin-top: 0;
}
.btn-group-vertical.btn-group-custom > .btn:first-child {
margin-top: 0;
margin-left: -1px;
border-radius: 0;
}
.btn-group-vertical.btn-group-custom > .btn:last-child {
border-radius: 0
}
}
#media (min-width:300px) and (max-width:767px) {
.btn-group-vertical.btn-group-custom > .btn {
float: left;
width: auto;
border-top: 1px solid #ccc;
}
.btn-group-vertical.btn-group-custom .btn + .btn {
margin-left: -1px;
margin-top: 0;
}
.btn-group-vertical.btn-group-custom > .btn:first-child {
border-radius: 4px 0 0 4px
}
.btn-group-vertical.btn-group-custom > .btn:last-child {
border-radius: 0 4px 4px 0
}
}

Related

Creating bootstrap glow buttons with correct color

I want to give my bootstrap buttons a glow effect. I know I can use box-shadow for this, but since it requires a color specified, I was hoping there was some way I could inherit it from the button itself, so that each different button (success, primary, warning, etc) glowed with its respective color. For example, here's what it would look like for btn-primary, but I'd like to make the color dynamically inherited:
.glow-button {
box-shadow: 0 0 30px #007bff;
}
.btn-lg {
margin: 1em;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"/>
<button type="button" class="btn btn-block btn-lg glow-button btn-primary">Primary</button>
A pseudo element where you apply filter can do this relying on inheriting the background color:
.glow-button {
position:relative;
}
.glow-button::before {
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
right:0;
bottom:0;
background:inherit;
filter:blur(15px);
transition:0.5s;
}
.glow-button:focus::before {
filter:blur(1px);
}
.btn-lg {
margin: 1em;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-6">
<div class="form-group">
<button type="button" class="btn btn-block btn-lg glow-button btn-primary">Primary</button>
<button type="button" class="btn btn-block btn-lg glow-button btn-secondary">Secondary</button>
<button type="button" class="btn btn-block btn-lg glow-button btn-success">Success</button>
<button type="button" class="btn btn-block btn-lg glow-button btn-danger">Danger</button>
<button type="button" class="btn btn-block btn-lg glow-button btn-warning">Warning</button>
<button type="button" class="btn btn-block btn-lg glow-button btn-info">Info</button>
<button type="button" class="btn btn-block btn-lg glow-button btn-light">Light</button>
<button type="button" class="btn btn-block btn-lg glow-button btn-dark">Dark</button>
</div>
</div>
</div>
</div>
Here's what I ultimately came up with. If someone has a way to do it without manually specifying the color for each button type I'd love to hear it!
.glow-button {
--box-shadow-color: black;
box-shadow: 0 0 30px var(--box-shadow-color);
}
.btn-primary.glow-button {
--box-shadow-color: #007bff;
}
.btn-secondary.glow-button {
--box-shadow-color: #6c757d;
}
.btn-success.glow-button {
--box-shadow-color: #28a745;
}
.btn-danger.glow-button {
--box-shadow-color: #dc3545;
}
.btn-warning.glow-button {
--box-shadow-color: #ffc107;
}
.btn-info.glow-button {
--box-shadow-color: #17a2b8;
}
.btn-light.glow-button {
--box-shadow-color: #f8f9fa;
}
.btn-dark.glow-button {
--box-shadow-color: #343a40;
}
.btn-lg {
margin: 1em;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-6">
<div class="form-group">
<button type="button" class="btn btn-block btn-lg glow-button btn-primary">Primary</button>
<button type="button" class="btn btn-block btn-lg glow-button btn-secondary">Secondary</button>
<button type="button" class="btn btn-block btn-lg glow-button btn-success">Success</button>
<button type="button" class="btn btn-block btn-lg glow-button btn-danger">Danger</button>
<button type="button" class="btn btn-block btn-lg glow-button btn-warning">Warning</button>
<button type="button" class="btn btn-block btn-lg glow-button btn-info">Info</button>
<button type="button" class="btn btn-block btn-lg glow-button btn-light">Light</button>
<button type="button" class="btn btn-block btn-lg glow-button btn-dark">Dark</button>
</div>
</div>
</div>
</div>

How to put the x inside text field?

I was trying to put clickable times (x) from font Awesome inside the text field but I could not do it also there lack of documentation for all the classes...
here a link to what I have got
<input type="text" class="form-control" id="copy-text">
<span>
<i class="fa fa-times xicon" aria-hidden="true"></i>
</span>
<span class="input-group-btn">
<button id="copy-emoji" data-clear-btn="true" class="form-control btn-large btn-lg btn btn-success" type="button" onclick="copyall()">COPY</button>
</span>
</div>
https://jsfiddle.net/2Lm6fup1/
thanks
You can position the icon relative to .input-group.
.xicon.over {
position: relative;
top: 11px;
left: -24px;
width: 0;
z-index: 999;
cursor: pointer;
}
https://jsfiddle.net/2Lm6fup1/5/

Bootstrap button text is not responsive

I tried many things to get the button text responsive, but it is not working.
Here's my html code
<button style="margin-top : 5px;"
type="submit" class="btn btn-primary cd-admin-create-modal-btn" ng-disabled = "form.$invalid"
ng-click="submitRouterDtls(router);">Submit
</button>
<button style="margin-top : 5px;"
type="submit" class="btn btn-primary cd-admin-create-modal-btn"
ng-click="cancelOperation();">Cancel
</button>
Here's my css code
.cd-admin-create-modal-btn {
width: 5vw;
margin: 0 1vw;
font-size : 1.5vw;
}
Can someone help me?
try it
.cd-admin-create-modal-btn {
min-width: 10vw;
margin: 0 1vw;
font-size : 1.5vw;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<button style="margin-top : 5px;"
type="submit" class="btn btn-primary cd-admin-create-modal-btn" ng-disabled = "form.$invalid"
ng-click="submitRouterDtls(router);">Submit
</button>
<button style="margin-top : 5px;"
type="submit" class="btn btn-primary cd-admin-create-modal-btn"
ng-click="cancelOperation();">Cancel
</button>

Modal Footer-Ajax message centering in the modal footer

I have this modal footer with a <label></label> which displays message on successful operation. But, the properties are inherited so the style for centering is not working. I am using Bootstrap 3.3.7
<div class="modal-footer">
<label type="text" id="resultmessage" style="color: white; vertical-align:middle;"></label>
<button type="button" id="updateWorksStatus" class="btn btn-success btn-sm">Update Status</button>
<button type="button" class="btn btn-danger btn-sm" data-dismiss="modal">Close</button>
</div>
Add a more specific CSS selector to override bootstrap styles (.modal-footer is set to text-align: right by default.).
div.modal-footer {
text-align: center;
}
Also, you can switch label order to last element inside of .modal-footer if you wish for it to be on the right side of buttons (changed color to gray just for visibility).
Snippet:
div.modal-footer {
text-align: center;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="modal-footer">
<button type="button" id="updateWorksStatus" class="btn btn-success btn-sm">Update Status</button>
<button type="button" class="btn btn-danger btn-sm" data-dismiss="modal">Close</button>
<label type="text" id="resultmessage" style="color: gray; vertical-align:middle;">Database updated</label>
</div>
If you wish to only center the message, you can do (tweak values to your benefit):
.modal-footer button {
margin-top: -48px;
}
#resultmessage {
display: inline-block;
width: 100%;
text-align: center;
}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="modal-footer">
<label type="text" id="resultmessage" style="color: gray; vertical-align:middle;">Database updated</label>
<button type="button" id="updateWorksStatus" class="btn btn-success btn-sm">Update Status</button>
<button type="button" class="btn btn-danger btn-sm" data-dismiss="modal">Close</button>
</div>
In my opinion, using label as not label for nothing is not good pratice. I'm quessing that u want this information ('Database updated') aligne vertically (you have tried to use vertical-align - it only works for tables). Instead of using label, better is to use for example span.
I did it like below:
https://codepen.io/Czeran/pen/BdWbjg
HTML
<div class="modal-footer">
<span id="resultmessage">Database updated</span>
<div class="tools">
<button type="button" id="updateWorksStatus" class="btn btn-success btn-sm">Update Status</button>
<button type="button" class="btn btn-danger btn-sm" data-dismiss="modal">Close</button>
</div>
<span></span>
</div>
CSS (edited)
.modal-footer {
position: relative;
display: flex;
flex-direction: row-reverse;
align-items: center;
justify-content: center;
}
#resultmessage {
font-weight: bold;
}
.tools {
position: absolute;
right: 15px;
}

fontawesome icon not rendering the same in Chrome and Firefox

In Chrome/Safari my icon within a bootstrap button looks fine:
But in Firefox, the icon drops down a line:
I have the fontawesome icon floated right within the <button>.
<!--html-->
<div class="btn-group btn-group-justified" role="group" aria-label="...">
<div class="btn-group" role="group">
<button type="button" class="btn btn-default btn-small">Cached logs<i class="fa fa-money"></i></button>
</div>
<div class="btn-group" role="group">
<button type="button" class="btn btn-default btn-small">Logs on mount<i class="fa fa-database"></i></button>
</div>
</div>
<!--style-->
i.fa {
float: right;
top: 2px;
position: relative;
font-size: 12pt;
}
.glyphicon, i.fa {
color: rgb(90, 90, 90);
top: 1px;
}
How can I make the Firefox version one-line like the Chrome?
JSBIN
Move the icon to the left of the text. I'm not sure of the underlying cause of it not being consistent how you've got it - but this does make both browsers render it consistently.
<button type="button" class="btn btn-default btn-small"><i class="fa fa-database"></i>Logs on mount</button>
Instead of
<button type="button" class="btn btn-default btn-small">Logs on mount<i class="fa fa-database"></i></button>

Resources