Bootstrap button icon not centered - html

I am using the boostrap social button for google but the google icon is not vertically centered.
How do i get the "G" to be centered vertically.
body {
background-color: #E8ECEF;
}
.centered {
padding-top: 200px;
text-align: center;
}
.secret-text {
text-align: center;
font-size: 2rem;
color: #fff;
background-color: #000;
}
<!-- just tried this part out also didn't change the G-->
.btn-google{
display: flex;
align-items: center;
justify-content: center;
}
<div class="container mt-5">
<h1>Login</h1>
<div class="row">
<div class="col-sm-8">
<div class="card">
<div class="card-body">
<!-- Makes POST request to /login route -->
<form action="/login" method="POST">
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" name="username">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" name="password">
</div>
<button type="submit" class="btn btn-dark">Login</button>
</form>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="card">
<div class="card-body">
<a class="btn btn-block btn-social btn-google" href="/auth/google" role="button">
<i class="fab fa-google"></i>
Sign In with Google
</a>
</div>
</div>
</div>
</div>
</div>
Added the full code for my login page minus the header/footer and included css as well as new image
I am using the bootstrap social css as well

All you need to do is use some flexbox magic.
.btn-google {
/* Since your button is a block button, otherwise use inline-flex */
display: flex;
align-items: center;
justify-content: center;
}
Try that and let me know if it works fine!

.className{
vertical-align: baseline;
}
try this class

You can use the flexbox to align the items horizontally and vertically center. If you want to adjust your icon relative to your text, you can use transform property.
Here is code.
HTML
<div class="card">
<div class="card-body">
<a class="btn btn-block btn-social btn-google" href="/auth/google" role="button">
<i class="fab fa-google"></i>
Sign In with Google
</a>
</div>
</div>
</div>
.card{
background-color:#DD4B39;
color:#fff;
width:300px;
margin:5px auto;
}
.card a{
color:#fff;
display:flex;
align-items:center;
justify-content:center;
font-size:20px;
}
.card a i{
margin-right:5px;
transform:translateY(2px)
}

All you have to do is adding a text-center class to your icon;
If that doesn't work too, add justify-content-center class to the div that contains col-sm-4.

This will center it CENTERING VERTICALLY
min-height: 10em;
display: table-cell;
vertical-align: middle
Let me know if this works for you :)

Related

How to align form elements next to image with CSS?

I want to align a label, a text-input and an X sign next to each other using Bootstrap 4.
I managed to align the label and text-input but can't seem to do that with the X sign.
JSFiddle: https://jsfiddle.net/jptyuv5n/
How can we align that X sign next to the input field? What am I missing here?
.collection {
display: flex;
}
.collection img {
float: left;
width: 150px;
}
.collection .form {
display: inline-block;
width: 100%;
margin: 0px 15px;
}
.collection .form input {
display: inline-block;
width: 100%;
}
<div class="row">
<div class="col-6 collection">
<img src="https://via.placeholder.com/150/771796">
<div class="form">
<label>Text</label>
<input type="text" name="text1">
<span>X</span>
</div>
</div>
<div class="col-6 collection">
<img src="https://via.placeholder.com/150/771796">
<div class="form">
<label>Text</label>
<input type="text" name="text2">
<span>X</span>
</div>
</div>
</div>
Edit: I just saw in your question that you mentioned Bootstrap 4. Same result can be achieved with using bootstrap styles and 0 css lines from you.
The classes used in the snippet below are documented here: https://getbootstrap.com/docs/4.0/components/forms/#overview
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="col-12 collection">
<div class="row">
<div class="col-3">
<img src="https://via.placeholder.com/150/771796">
</div>
<div class="col-9">
<div class="form-row align-items-center">
<div class="col-sm-3 my-1">
<label>text</label>
<div class="input-group">
<input type="text" class="form-control" />
<div class="input-group-append">
<div class="input-group-text">X</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Old answer:
You can wrap the <input> and the <span> holding x in a div and use flex on it.
.collection {
display: flex;
}
.collection img {
float: left;
width: 150px;
}
.collection .form {
display: inline-block;
width: 100%;
margin: 0px 15px;
flex-direction: column; /* <- changed flex direction of form */
}
.collection .form input {
display: inline-block;
width: 100%;
}
.input-with-x { /* <- new classes added */
display: flex;
}
<div class="row">
<div class="col-6 collection">
<img src="https://via.placeholder.com/150/771796">
<div class="form">
<label>Text</label>
<div class="input-with-x"> <!-- <- new class used -->
<input type="text" name="text2">
<span>X</span>
</div>
</div>
</div>
</div>

Developing float layout into Flex Display layout

I have been using float layout UI for my webpage. Recently i thought to convert the same layout into flex display layout. I havent been much into flex displays and i am a complete newbie into flex layout. I am struggling to convert my webpage layout into flex display. If any one could give just a gist to some properties for the UI would be helpful. I tried some with flex display but struggled with the left banner (expressed in a HTML skeleton below) as it is completely breaking the row system.
I have posted the HTML and CSS in a fiddle. Link to which is shared.
.left-block {
padding: 24px;
height: 100vh;
display: table-cell;
width: 41.66666667%;
margin: 0px;
background: #333;
/*padding: 24px 24px 0 24px;*/
}
.right-block {
padding: 24px 24px;
height: 100vh;
display: table-cell;
width: 58.33333333%;
}
.container-fluid {
max-width: 100%;
/*border-left: 1px solid #ccc;
border-right: 1px solid #ccc;*/
}
<div class="container-fluid">
<div class="row">
<div class="col-md-6 left-block">
<img src="~/images/logo.png" class="pull-left logo" />
<span class="pull-left company-name">Company Name<sup>TM</sup> </span>
<div class="clearfix"></div>
<p>
Sign in to your account.
</p>
</div>
<div class="col-md-6 right-block">
<div id="SignInBlock">
<p class="pull-right">
<span class="noacct">Don’t have an account?</span> Create account
</p>
<div class="clearfix"></div>
<div class="form-wrapper">
<h1>Sign in</h1>
<form action="#">
<div class="form-group">
<input type="email" class="form-control" id="work_email" required placeholder="Work Email">
</div>
<button type="submit" disabled class="btn btn-big btn-primary col-xs-12">Sign in</button>
</form>
<p class="forgot-password">
<strong>Forgot email?</strong>
</p>
</div>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
https://jsfiddle.net/u9wz18br/
<div class="left-block">
<!-- Full height banner with 40% width -->
// Some Text
</div>
<div class="right-block">
<!-- Create Account Link floating right -->
// Sign In Block Here
</div>

How to make image expand/shrink to available space while keeping aspect ratio

How do we make an image "fit" inside the second column below? This is Bootstrap 4 and I want the right column to take the same height as the left column and then the image to fit inside it while keeping the aspect ratio. I also want it to be centered horizontally and vertically.
The HTML currently looks like this:
<div class="form-row">
<div class="col">
<div class="form-group">
<!-- Upload Image option -->
</div>
<div class="form-group">
<!-- Image URL option -->
</div>
</div>
<div class="col-md-4">
<img src="leg.jpg" height="70px" />
</div>
</div>
I simply don't want to specify that height="70px" attribute. The image should expand/shrink to cover the available height (dictated by the left column). Width of the image should then adjust to keep aspect ratio intact. The image should finally be centered horizontally or vertically.
By the look of the screenshot there's CSS from other classes and more HTML layout than what's provided. Here are the following styles relevant to the img with a <figure> wrapped around it.
<figure class='figure'> <img class='figure-img fluid-img'...> </figure>
img {
object-fit:contain;
max-width:100%;
height:auto
}
.col {
display:flex;
flex-flow:column nowrap;
justify-content: center;
align-items:center
}
.form-row {
max-width: 540px;
}
img {
object-fit: contain;
max-width: 100%;
height: auto
}
.column {
display: flex;
flex-flow: column nowrap;
justify-content: center;
align-items: center
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
<main class='container'>
<section class="form-row">
<section class="column col-8">
<div class="form-group">
<div class="input-group mb-3">
<div class="input-group-prepend">
<div class="input-group-text">
<input type="radio">
</div>
</div>
<div class="custom-file">
<input type="file" class="custom-file-input form-control">
<label class="custom-file-label">Choose file</label>
</div>
</div>
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<div class="input-group-text">
<input type="radio">
</div>
</div>
<input type="url" class="custom-url-input form-control">
</div>
</section>
<section class="column col-4">
<figure class='figure'>
<img src="https://oehawkseye.org/wp-content/uploads/2017/01/chicken-leg.png" class='figure-img img-fluid'>
</figure>
</section>
</section>
</main>

Bootstrap 4 | Can't keep a search box on the same line with a custom navbar's items

I made a custom navbar using Bootstrap 4's grid. This navbar is split into two parts: left part contains navbar items and right part contains a search box.
The problem is that the search box doesn't stay in the right part of my navbar no matter what. It always goes under the navbar items (left part).
Here is my HTML & CSS code:
.custom-navbar-buttons p {
display: inline;
color: black;
margin-right: 0.4rem;
}
.custom-navbar-buttons {
padding-top: 0.4rem;
padding-bottom: 0.4rem;
}
<body>
<div class="container">
<div class="row">
<div class="custom-navbar col-12 bg-success">
<div class="custom-navbar-buttons col-8">
<p>Button</p>
<p>Button</p>
<p>Button</p>
<p>Button</p>
<p>Button</p>
</div>
<div class="custom-navbar-search col-4">
<input type="text" name="search" placeholder="search this site">
</div>
</div>
</div>
</div>
</body>
How do I properly position a search box on the same line with navbar's items?
P.S.:
There are no tags around the "input" because I tried with them and without them, both ways didn't work so I didn't change code since the last try.
P.P.S.:
I've searched Google and Stackoverflow before posting my own question. None of the suggested answers there were of help to me. Most of people suggest that the navbar has too many items and so it can't fit the search box, moving it on the next line instead, but I think that's silly because I've tried it even with only 2 items in my navbar.
Is this what you want?
If you want to have the searchbar pulled to the right, add:
class="float-right"
.custom-navbar-buttons p {
display: inline;
color: black;
margin-right: 0.4rem;
}
.custom-navbar-buttons {
padding-top: 0.4rem;
padding-bottom: 0.4rem;
}
<body>
<div class="container">
<div class="row">
<div class="custom-navbar col-12 bg-success">
<div class="custom-navbar-buttons col-8">
<p>Button</p>
<p>Button</p>
<p>Button</p>
<p>Button</p>
<p>Button</p>
<input type="text" name="search" placeholder="search this site">
</div>
</div>
</div>
</div>
</body>
The search box doesn't stay on the right part of your links because both the custom-navbar-buttons and custom-navbar-search are block level elements. So they both tend to arrange on top of each other taking up the whole width of their parent div which is custom-navbar.
You need to make them both inline.
.custom-navbar-buttons p {
display: inline;
color: black;
margin-right: 0.4rem;
}
.custom-navbar-buttons {
padding-top: 0.4rem;
padding-bottom: 0.4rem;
display:inline-block;
}
.custom-navbar-search {
display: inline-block;
}
<body>
<div class="container">
<div class="row">
<div class="custom-navbar col-12 bg-success">
<div class="custom-navbar-buttons col-8">
<p>Button</p>
<p>Button</p>
<p>Button</p>
<p>Button</p>
<p>Button</p>
</div>
<div class="custom-navbar-search col-4">
<input type="text" name="search" placeholder="search this site">
</div>
</div>
</div>
</div>
</body>
Or you can simply use flexbox which will give you more control over your navbar.
.custom-navbar {
display:flex;
flex-flow: row nowrap;
align-items: center;
justify-content: space-between;
}
.custom-navbar-buttons p {
display: inline;
color: black;
margin-right: 0.4rem;
}
.custom-navbar-buttons {
padding-top: 0.4rem;
padding-bottom: 0.4rem;
}
<body>
<div class="container">
<div class="row">
<div class="custom-navbar col-12 bg-success">
<div class="custom-navbar-buttons col-8">
<p>Button</p>
<p>Button</p>
<p>Button</p>
<p>Button</p>
<p>Button</p>
</div>
<div class="custom-navbar-search col-4">
<input type="text" name="search" placeholder="search this site">
</div>
</div>
</div>
</div>
</body>

Set background color for div

I have a grid created using bootstrap 3 divs. The collection of divs has 1 button, followed by a radio button, followed by another button. I would like to highlight these with a background color. The background color should not break in between and should be like a single row.
Here is the fiddle with my attempt - https://jsfiddle.net/oxfqvtds/2/
In this, there is some empty space on the bottom right side of the div. As a result, the highlighting is not consistent.
.highlight {
background-color: yellow;
}
.input-field {
height: 20px;
padding: 2px 10px;
}
.custom-label {
line-height: 3.3em !important;
}
.label-size {
font-size: 10px;
line-height: 2.1em;
}
label {
padding-right: 0px;
}
<head>
<link type="text/css" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
</head>
<body>
<div class="container-fluid">
<form class="form-horizontal">
<div class="col-md-12">...</div>
<div class="col-md-12">...</div>
<div class="col-md-10 highlight">
<div class="form-group">
<div class="col-md-3">
<button class="btn btn-primary btn-xs" type="button">Test</button>
</div>
<label class="col-md-2 label-size">Options</label>
<div class="radio" class="col-md-7 label-size">
<label class="label-size">
<input type="radio" name="opt" value="opt" >opt</label>
</div>
</div>
</div>
<div class="col-md-2 highlight form-group">
<button class="btn btn-info btn-xs pull-right">Test2</button>
</div>
</form>
</div>
</body>
Also, would like to have the buttons/radio buttons centered in the highlighted area. Right now they seem to be towards the top of the highlighted area.
With bootstrap you columns should be in a row. Apply the background color to the row once you have it in place. Remove form-groups, and you had class listed twice around the radio element so it wasn't reading the bootstrap column class.
.highlight.row {
background-color: yellow;
margin:0;
}
.input-field {
height: 20px;
padding: 2px 10px;
}
.custom-label {
line-height: 3.3em !important;
}
.label-size {
font-size: 10px;
line-height: 2.1em;
}
label {
padding-right: 0px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row highlight">
<form class="form-horizontal">
<div class="col-md-10 ">
<div class="">
<div class="col-md-3">
<button class="btn btn-primary btn-xs" type="button">Test</button>
</div>
<div class="col-md-2">
<label class="label-size">Options</label>
</div>
<div class="col-md-5 label-size">
<label class="label-size">
<input type="radio" name="opt" value="opt" >opt</label>
</div>
</div>
</div>
<div class="col-md-2">
<button class="btn btn-info btn-xs pull-right">Test2</button>
</div>
</form>
</div>
</div>
remove the margin-bottom from this particular form-group