I am building a login page with social buttons using Font Awesome icons. On larger devices the buttons are displayed horizontally next to each other, but as I resize my screen the right-most button will wrap underneath the other two buttons when they get too wide for the column. I would like for the buttons to stack vertically and expand to fill the space of the column instead of having a misplaced button underneath. I've tried a method using media queries but it's a bit hacky and I'm afraid it won't be easy to maintain, so I scratched that idea.
Here's what I have so far:
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="form-group">
<div class="col-sm-offset-2 col-sm-8">
<div class="row">
<button id="login" class="btn btn-default">Login</button>
<button id="facebook" class="btn btn-default"><span class="fa fa-facebook fa-lg"></span> Facebook Login</button>
<button id="google" class="btn btn-default"><span class="fa fa-google fa-lg"></span> Google Login</button>
</div>
</div>
</div>
Any suggestions on how to tackle this?
You have two options. In my opinion media queries would be the cleanest but here are the options:
1) Adding a media query and targeting a special class that you can add to just those buttons:
#media screen and (max-width: 768px){
.loginBtns {
width:100%;
display:block;
margin: 10px 0;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-8 col-xs-12">
<div class="row">
<button id="login" class="btn btn-default loginBtns">Login</button>
<button id="facebook" class="btn btn-default loginBtns"><span class="fa fa-facebook fa-lg"></span> Facebook Login</button>
<button id="google" class="btn btn-default loginBtns"><span class="fa fa-google fa-lg"></span> Google Login</button>
</div>
</div>
</div>
2) Duplicating the buttons and hiding one version on small screens while showing the other. I'm not a big fan of duplicating code so I wouldn't recommend this option but if you don't like media queries it could be an option.
.loginBtns2 {
width:100%;
margin: 5px 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-8 hidden-xs">
<div class="row">
<button id="login" class="btn btn-default loginBtns">Login</button>
<button id="facebook" class="btn btn-default loginBtns"><span class="fa fa-facebook fa-lg"></span> Facebook Login</button>
<button id="google" class="btn btn-default loginBtns"><span class="fa fa-google fa-lg"></span> Google Login</button>
</div>
</div>
<div class="col-xs-12 visible-xs">
<div class="row">
<button id="login" class="btn btn-default loginBtns2">Login</button>
</div>
<div class="row">
<button id="facebook" class="btn btn-default loginBtns2"><span class="fa fa-facebook fa-lg"></span> Facebook Login</button>
</div>
<div class="row">
<button id="google" class="btn btn-default loginBtns2"><span class="fa fa-google fa-lg"></span> Google Login</button>
</div>
</div>
Here is a working codepen with both options too:
https://codepen.io/egerrard/pen/woVEJW
not sure if this helpful. but try this..
<div class="container">
<div class="row text-center">
<div class="col-md-6">
<button id="login" class="btn btn-default">Login</button>
<button id="facebook" class="btn btn-primary"><span class="fa fa-facebook fa-lg"></span> Facebook Login</button>
<button id="google" class="btn btn-danger"><span class="fa fa-google fa-lg"></span> Google Login</button>
</div>
</div>
</div>
Related
I want to add the Back and Next buttons at the bottom of the screen with a fixed position. For my code, the button moves to the top/bottom of the screen if I change the screen size (I have attached the screenshot for both). Please check my code and help me solve this.
Code
<div id="text-area">
<p class="mb-4">
<strong>Textarea</strong>
</p>
<textarea></textarea>
<p class="d-flex justify-content-between">
<button class="btn btn-link button" id="back">
<i class="fa fa-long-arrow-alt-left me-3"></i>
Back
</button>
<button class="btn btn-link button" id="next">
Next
<i class="fa fa-long-arrow-alt-right ms-3"></i>
</button>
</p>
</div>
This solved my problem. Thanks all for your time. Happy coding.
<div class="d-flex flex-column flex-grow-1" id="text-area">
<div class="flex-grow-1">
<p class="mb-4">
<strong>Textarea</strong>
</p>
<textarea></textarea>
</div>
<p class="d-flex justify-content-between">
<button class="btn btn-link button" id="back">
<i class="fa fa-long-arrow-alt-left me-3"></i>
Back
</button>
<button class="btn btn-link button" id="next">
Next
<i class="fa fa-long-arrow-alt-right ms-3"></i>
</button>
</p>
</div>
I would like to place an icon between two buttons. The icon is larger than the buttons and I would like their centers to be on a line. This means that the icon is a bit above and below the buttons.
A simple way to do this is a button group. Unfortunately, the icon is rounded off and buttons in a button group have sharp edges to neighbours in the group and the icon is rescaled to the same size as the buttons:
So I tried to get rid of the button-group. Bootstrap has an align-middle class for vertical alignment. But I can't get this to work. It looks like this:
I browsed and found this: How to center an element horizontally and vertically?
The answer lists a variety of approaches. I would like to stick with bootstrap and avoid custom css as far as possible. But one of the options sounded really good to me: Using justify and align in a flexbox container. Bootstrap containers are flexboxes, so I wrapped my buttons in a container and added align-items: center; justify-content: center;. Same result as the align-middle picture above.
I tried a variety of other css combinations, without any success. The three approaches above seem the cleanest to me, so I presented them here.
A fiddle: https://jsfiddle.net/aq9Laaew/285443/
html (assuming that you have bootstrap and fontawesome):
<!-- using a flexbox container + css -->
<div class="container" style="align-items: center; justify-content: center;">
<button type="button" class="btn btn-outline-secondary">
<i class="far fa-times-circle" style="color:red;"></i>
</button>
<i class="far fa-question-circle fa-3x" style="color: lightskyblue"></i>
<button type="button" class="btn btn-outline-secondary">
<i class="far fa-check-circle" style="color:green;"></i>
</button>
</div>
<br>
<!-- using the bootstrap align-middle class -->
<div class="align-middle">
<button type="button" class="btn btn-outline-secondary">
<i class="far fa-times-circle" style="color:red;"></i>
</button>
<i class="far fa-question-circle fa-3x" style="color: lightskyblue"></i>
<button type="button" class="btn btn-outline-secondary">
<i class="far fa-check-circle" style="color:green;"></i>
</button>
</div>
<br>
<!-- using a button group -->
<div class="btn-group" role="group" aria-label="Basic example">
<button type="button" class="btn btn-outline-secondary">
<i class="far fa-times-circle" style="color:red;"></i>
</button>
<span><i class="far fa-question-circle fa-3x" style="color: lightskyblue"></i></span>
<button type="button" class="btn btn-outline-secondary">
<i class="far fa-check-circle" style="color:green;"></i>
</button>
</div>
Potential duplicates (this is a very common question):
Bootstrap vertical align The answer works on a grid of rows and cols. I prefer not to introduce a grid.
Vertically align elements using CSS No answer has been accepted and the hints are similar to the answer I included in the main text.
Not 100% sure on what you want but if you want to align the buttons, then you can also use bootstrap flexbox and bootstrap text color instead of additional styling: (Edited: align-self-center vs align-items-center)
<div class="d-flex justify-content-start">...</div>
<div class="d-flex justify-content-end">...</div>
<div class="d-flex justify-content-center">...</div>
<div class="d-flex justify-content-between">...</div>
<div class="d-flex justify-content-around">...</div>
<link href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" rel="stylesheet"/>
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="d-flex justify-content-start align-items-center">
<button type="button" class="btn btn-outline-secondary">
<i class="far fa-times-circle text-danger"></i>
</button>
<i class="far fa-question-circle fa-5x" style="color: lightskyblue"></i>
<button type="button" class="btn btn-outline-secondary">
<i class="far fa-check-circle text-success"></i>
</button>
</div>
<br/>
<div class="d-flex justify-content-start">
<button type="button" class="btn btn-outline-secondary align-self-center">
<i class="far fa-times-circle text-danger"></i>
</button>
<i class="far fa-question-circle fa-4x" style="color: lightskyblue"></i>
<button type="button" class="btn btn-outline-secondary align-self-center">
<i class="far fa-check-circle text-success"></i>
</button>
</div>
I need some advice to make bootstrap panel header responsive. Panel has title with several buttons on the right side. It looks fine in large screen but looks ugly when browser size is small.
My full code here jsfiddle.
.panel {
margin: 15px;
}
.panel-title {
padding-top: 7px;
font-size: 20px;
}
.mr-10 {
margin-right: 10px;
}
<div class="panel panel-success panel-br-4">
<div class="panel-heading clearfix">
<h4 class="panel-title pull-left">
<i class="fa fa-file-text" aria-hidden="true"></i> <span>Documents</span>
</h4>
<a id="document-сreate-btn" class="btn btn-success pull-right">
<i class="fa fa-plus-circle"></i>
<span>Create new document</span>
</a>
<a class="btn btn-warning pull-right mr-10">
<i class="fa fa-chevron-circle-down" aria-hidden="true"></i>
</a>
<a class="btn btn-warning pull-right mr-10">
<span>Save new order</span>
</a>
</div>
<div class="panel-body">Some content</div>
</div>
When all items cannot fit in one line, I want to make header as in the next picture:
Is such things makes by flexbox or bootstrap grid system? Whats the better way? I will appreciate any examples! :)
This is just a quick example of how to use Bootstrap grid system. It's not gonna be as perfect as you want but it will give you an introduction to grid systems. Also, don't forget to read about media queries.
<div class="panel panel-success panel-br-4">
<div class="panel-heading">
<div class="row">
<div class="col-sm-6">
<h4 class="panel-title">
<i class="fa fa-file-text" aria-hidden="true"></i>
<span>Documents</span>
</h4>
</div>
<div class="col-sm-3" style="display: flex">
<a class="btn btn-warning mr-10">
<span>Save new order</span>
</a>
<a class="btn btn-warning">
<i class="fa fa-chevron-circle-down" aria-hidden="true"></i>
</a>
</div>
<div class="col-sm-3">
<a id="document-сreate-btn" class="btn btn-success mr-10" data-url="">
<i class="fa fa-plus-circle"></i>
<span>Create new document</span>
</a>
</div>
</div>
</div>
<div class="panel-body">Some content</div>
I am making a blog-type page to practice some web.py. I made a rough html file and I tried to apply a CSS bootstrapper/template but it is not working for me anymore. This is the HTML of the home page, in essence.
`
Home Feed
Profile
Messages
Friends
Communities
<li><span class="mdi mdi-bell"> </span> Notifications</li>
<li class="seperator"></li>
<li><span class="mdi mdi-settings"> </span> Settings</li>
<li><span class="mdi mdi-help-circle"> </span> Help</li>
</ul>
<div class="col-md-6">
<div class="post-box">
<form id="post-activity">
<textarea name="content" class="post-input" placeholder="What's new, $session['user']['name']?"></textarea>
<button id="post-button" class="btn btn-info btn-raised waves-effect" type="submit"><span class="mdi mdi-send"></span> Post</button>
</form>
</div>
<div class="post-card">
<div class="header">
<div class="avatar"></div>
Adrian Bernat
</div>
<div class="content">
Test Content
</div>
<div class="footer">
<button class="btn btn-round waves-effect btn-default btn-raised btn-like"><span class="mdi mdi-thumb-up-outline"></span> Like</button>
<button class="btn btn-round waves-effect btn-default btn-raised btn-comment"><span class="mdi mdi-comment-text-outline"></span> Comment</button>
</div>
</div>
</div>
</div>`
I'm not sure that pasted correctly, but the should apply those CSS profiles that I have, but when I run the cope, the HTML shows up raw and un-styled. Does anyone know why?
EDIT: here is what I am getting, and here is what it SHOULD look like.
Did you make sure to include the CSS files for bootstrap?
Even if you give the html elements bootstrap classes you still need to load bootstrap in order for the styling to work.
In the example below I loaded bootstrap using this:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
You may or may not want to do the same.
There many ways to include bootstrap files with your html.
I didn't edit your html. I only loaded bootstrap at the top.
Is this what you wanted?
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<ul>
<li><span class="mdi mdi-bell"></span> Notifications</li>
<li class="seperator"></li>
<li><span class="mdi mdi-settings"></span> Settings</li>
<li><span class="mdi mdi-help-circle"></span> Help</li>
</ul>
<div class="col-md-6">
<div class="post-box">
<form id="post-activity">
<textarea name="content" class="post-input" placeholder="What's new, $session['user']['name']?"></textarea>
<button id="post-button" class="btn btn-info btn-raised waves-effect" type="submit"><span class="mdi mdi-send"></span> Post</button>
</form>
</div>
<div class="post-card">
<div class="header">
<div class="avatar"></div>
Adrian Bernat
</div>
<div class="content">
Test Content
</div>
<div class="footer">
<button class="btn btn-round waves-effect btn-default btn-raised btn-like"><span class="mdi mdi-thumb-up-outline"></span> Like
</button>
<button class="btn btn-round waves-effect btn-default btn-raised btn-comment"><span class="mdi mdi-comment-text-outline"></span> Comment
</button>
</div>
</div>
I've a bootstrap button group which includes a text between the buttons:
#import url('http://twitter.github.com/bootstrap/assets/css/bootstrap.css');
#import url('https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css');
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="btn-group">
<div class="btn btn-primary">
<i class="fa fa-chevron-left"></i>
</div>
<div>2016</div>
<div class="btn btn-primary">
<i class="fa fa-chevron-right"></i>
</div>
</div>
</div>
</div>
</div>
How to avoid the line breaks, such that the buttons and the text are aligned in one line?
You need to display them in-line like:
#import url('http://twitter.github.com/bootstrap/assets/css/bootstrap.css');
#import url('https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css');
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="btn-group">
<div class="btn btn-primary" style="display: inline-block;">
<i class="fa fa-chevron-left"></i>
</div>
<div style="display: inline-block;">2016</div>
<div class="btn btn-primary" style="display: inline-block;">
<i class="fa fa-chevron-right"></i>
</div>
</div>
</div>
</div>
</div>
Edit: Alternatively, as Turnip proposed in his answer, you can change the elements from divs to to another kind of element that is naturally displayed in-line. Either way, you will reach the same result.
divs are block elements. Change your buttons to <a>s and the text div to a <span> or any other inline/inline-block element.
#import url('http://twitter.github.com/bootstrap/assets/css/bootstrap.css');
#import url('https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css');
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="btn-group">
<a class="btn btn-primary">
<i class="fa fa-chevron-left"></i>
</a>
<span>2016</span>
<a class="btn btn-primary">
<i class="fa fa-chevron-right"></i>
</a>
</div>
</div>
</div>
</div>