Bootstrap icon wrong positioning - html

I'm new to CSS and HTML, so I got stuck on a very stupid step. The thing is that fa-list-ul icon is wrong positioned. Without text-align:center it positions fine. Any way to fix it? Thanks for spending your time with my problem.
Here's the JSFiddle
And here is my code :
.player{padding:.75rem 1rem;margin-bottom:1rem;line-height:36px}
.player_play{font-size:36px;vertical-align:middle}
.radio_name{vertical-align:middle}
.radio_icon{padding-right:5px;vertical-align:middle}
.radio_select{font-size:20px;vertical-align:middle}
<nav class="player">
<div class="container">
<div class="float-left">
<i class="fa fa-play-circle player_play action"></i>
</div>
<div class="radio_volume">
<i class="fa fa-volume-down"></i>
<i class="fa fa-music radio_icon accent_color"></i><span class="radio_name"> Anison</span>
</div>
<div class="float-right">
<i class="fa fa-list-ul radio_select action"></i>
</div>
</div>
</nav>

Using display: flex will make every element inside that container have the same horizontal size so this should solve your problem:
.container {
display: flex;
}
.float-left {
flex: 1;
}
.radio_volume {
text-align: center;
flex: 1;
}
.float-right {
flex: 1;
}
.float-right i {
float: right;
margin-top: 10px;
}
also here's the jsfiddle: https://jsfiddle.net/fqkvv8es/3/

You can make use of Bootstrap's classes, which results in less code than what the chosen answer uses:
JSFiddle
HTML
<nav class="player">
<div class="container">
<div class="row justify-content-between align-items-center">
<i class="fa fa-play-circle player_play action"></i>
<div class="radio_volume">
<i class="fa fa-volume-down"></i>
<i class="fa fa-music radio_icon accent_color"></i><span class="radio_name"> Station</span>
</div>
<i class="fa fa-list-ul radio_select action"></i>
</div>
</div>
</nav>
CSS
.player {
padding: .75rem 1rem;
margin-bottom: 1rem;
line-height: 36px
}
.player_play {
font-size: 36px;
}
.radio_icon {
padding-right: 5px;
}
.radio_select {
font-size: 20px;
}
JSFiddle

Related

How to build a responsive CSS grid with square items to display images with multiple aspect ratios [duplicate]

This question already has answers here:
CSS grid square layout [duplicate]
(4 answers)
Closed 3 years ago.
I'm trying to build this responsive grid for an image gallery.
I want the grid items to be square-shaped at all times (aspect ratio 1:1), even though the pictures are coming in all sorts of aspect-ratios.
I'll probably display any picture inside the square items, using object-fit: cover.
I'm trying to get a solution that works well across browsers. Nothing too hacky. It's seems like a simple task but so far I couldn't wrap my head around it.
See an example on the code snippet that I've made.
Note: Every image needs to have an icon on top of it, just like the example.
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
grid-gap: 10px;
}
.gridItemContainer {
position: relative;
}
.grid img {
display: block;
object-fit: cover;
width: 100%;
}
.grid i {
font-size: 120%;
position: absolute;
top: 10px;
left: 10px;
}
<html>
<head>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
</head>
<body>
<div class="grid"/>
<div class="gridItemContainer"/>
<img src="https://images-na.ssl-images-amazon.com/images/I/41g1xjf4CpL.jpg"/>
<i class="fas fa-star"></i>
</div>
<div class="gridItemContainer"/>
<img src="https://images-na.ssl-images-amazon.com/images/I/4106U8dHTgL.jpg"/>
<i class="fas fa-star"></i>
</div>
<div class="gridItemContainer"/>
<img src="https://images-na.ssl-images-amazon.com/images/I/41cSJCJ%2BSaL.jpg"/>
<i class="fas fa-star"></i>
</div>
<div class="gridItemContainer"/>
<img src="https://images-na.ssl-images-amazon.com/images/I/41DpkMbHZZL.jpg"/>
<i class="fas fa-star"></i>
</div>
<div class="gridItemContainer"/>
<img src="https://images-na.ssl-images-amazon.com/images/I/41i-GWf875L.jpg"/>
<i class="fas fa-star"></i>
</div>
<div class="gridItemContainer"/>
<img src="https://images-na.ssl-images-amazon.com/images/I/51LUVEJQbjL.jpg"/>
<i class="fas fa-star"></i>
</div>
</div>
You can use padding-top: 100% to set the height of a grid item - this will make a square as padding in percentages is based on width in CSS.
Now make the image position: absolute so that it will be taken out of the flow and height will be fully dictated by padding-top set on the grid item (gridItemContainer) - see demo below:
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
grid-gap: 10px;
}
.gridItemContainer {
position: relative;
padding-top: 100%; /* added */
border: 1px solid;
background: cadetblue;
}
.grid img {
display: block;
object-fit: cover;
width: 100%;
height: 100%; /* image fills the grid item */
position: absolute; /* position absolutely */
top: 0;
left: 0;
}
.grid i {
font-size: 120%;
position: absolute;
top: 10px;
left: 10px;
}
<html>
<head>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.0/css/all.css" integrity="sha384-lZN37f5QGtY3VHgisS14W3ExzMWZxybE1SJSEsQp9S+oqd12jhcu+A56Ebc1zFSJ" crossorigin="anonymous">
</head>
<body>
<div class="grid"/>
<div class="gridItemContainer">
<img src="https://images-na.ssl-images-amazon.com/images/I/41g1xjf4CpL.jpg"/>
<i class="fas fa-star"></i>
</div>
<div class="gridItemContainer">
<img src="https://images-na.ssl-images-amazon.com/images/I/4106U8dHTgL.jpg"/>
<i class="fas fa-star"></i>
</div>
<div class="gridItemContainer">
<img src="https://images-na.ssl-images-amazon.com/images/I/41cSJCJ%2BSaL.jpg"/>
<i class="fas fa-star"></i>
</div>
<div class="gridItemContainer">
<img src="https://images-na.ssl-images-amazon.com/images/I/41DpkMbHZZL.jpg"/>
<i class="fas fa-star"></i>
</div>
<div class="gridItemContainer">
<img src="https://images-na.ssl-images-amazon.com/images/I/41i-GWf875L.jpg"/>
<i class="fas fa-star"></i>
</div>
<div class="gridItemContainer">
<img src="https://images-na.ssl-images-amazon.com/images/I/51LUVEJQbjL.jpg"/>
<i class="fas fa-star"></i>
</div>
</div>

Font awesome icon not centering

JS: http://jsfiddle.net/1cmtpnha/
I have this:
<div class="card-body">
<div class="padding_5">
<div class="icon-center">
<i class="fa fa-twitter" aria-hidden="true"></i>
</div>
</div>
</div>
padding_5 just contains padding css
card-body is bootstrap 4
I tried this:
[class*="icon-"] {
display: inline-block;
width: 100%;
}
.icon-center i {
text-align: center;
}
and this:
.icon-center {
margin: auto;
display: block;
}
and neither worked. Those were top checked responses i saw on SO.
What is wrong with my code?
I want it to be horizontally centered within a card-body.
It's not the bootstrap either. I tested it on a separate page with no css or card-body. Still same issue.
You have three options here
1. Parent: text-align: center
set text-align: center to body.
2. Child: display: block and text-align: center
set display: block to .icon-center.
3. Child display: block , set width and margin: auto
set display: block , width: 20px and margin: auto to .icon-center.
https://codepen.io/blackcityhenry/pen/WPexKp
.icon-center {
text-align:center;
}
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="card-body">
<div class="padding_5">
<div class="icon-center">
<i class="fa fa-twitter" aria-hidden="true"></i>
</div>
</div>
</div>
Just add text-align: center; to the parent card-body
.card-body{
border: 1px solid red;
text-align: center;
}
.padding_5 {
padding: 10px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" type="text/css" />
<div class="card-body">
<div class="padding_5">
<div class="icon-center">
<i class="fa fa-twitter" aria-hidden="true"></i>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.bundle.min.js"></script>

css align right and left at the same time

I have a problem with displaying this(check this picture)
I have a link on the left and icons with words under it on the right. What is the right way to display it? and how can I display the words under the icons? I need help with it. Please check the attached picture to see how I need it to look.
<div class="back-to-listing-clinic">
<div>
<a> < back </a>
</div>
<div class="right-icons-part">
<img class="clinic-top-icons"src="./assets/images/icons/forum.png">
<img class="clinic-top-icons" src="./assets/images/icons/forum.png">
<img class="clinic-top-icons" src="./assets/images/icons/forum.png">
</div>
<div>
<p> Icon1 </p>
<p> Icon2 </p>
<p> Icon3 </p>
</div>
</div>
There's a dozen ways to do this. I replaced your images with icons for demonstration purposes.
This method just sets the "left and right" parts to display: inline-block to place them next to each other, and then sets float: right on the right hand ones to separate them.
I'd consider using a CSS Framework of some kind instead - but this would be a simple way to do it with what you have.
No Framework:
* {
box-sizing: border-box;
}
.back-to-listing-clinic > div {
display: inline-block;
}
.right-icons-part {
float: right;
}
.right-icons-part:after {
content: " ";
display: block;
clear: both;
height: 0px;
}
.right-icons-part a {
text-align: center;
display: inline-block;
}
<script src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
<div class="back-to-listing-clinic">
<div class="left">
<a> < back </a>
</div>
<div class="right-icons-part">
<i class="fas fa-comment-alt"></i><br />Icon 1
<i class="fas fa-comment"></i><br />Icon 2
<i class="fas fa-comments"></i><br />Icon 3
</div>
</div>
Super simple Ungrid framework
#media (min-width: 30em) {
.row { width: 100%; display: table; table-layout: fixed; }
.col { display: table-cell; }
}
.right {
text-align: right;
}
.right-icons-part a {
display: inline-block;
text-align: center;
}
<script src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
<div class="row back-to-listing-clinic">
<div class="col left">
<a> < back </a>
</div>
<div class="col right right-icons-part">
<i class="fas fa-comment-alt"></i><br />Icon 1
<i class="fas fa-comment"></i><br />Icon 2
<i class="fas fa-comments"></i><br />Icon 3
</div>
</div>

Changing bootstrap grid margins

I'm a begginer coder and i'm learning to use bootstrap grid. Although, i didn't quite understand how the container margins work.
I wrote this piece of coding for a website footer and tried using bootstrap grid, but i wanted the social icons to be about 20px to the right and i can't get it. Inspecting the element at google chrome i can see there is a margin right but i can't seem to customize it and make it smaller.
take a look - this is my footer's html code:
<footer>
<div class="row container">
<div class="logo-rodape col-md-2">
<img src="img/logo-principal-white-gota.png" alt="Logo Picada Zero">
</div>
<div class="r-content col-md-4">
<p class="slogan-title">CLEAN AND PROTECTION</p>
<p class="slogan-sub">Proteção e limpeza para sua família</p>
</div>
<div class="r-social col-md-5">
<i class="fa fa-facebook fa-2x" aria-hidden="true" style="color:#fff"></i>
<i class="fa fa-vimeo fa-2x" aria-hidden="true" style="color:#fff"></i>
</div>
</div>
</footer>
Now, this is my CSS code:
footer{
background: url(../img/rodape-background.png);
clear: both;
padding: 50px 0;
}
footer .container{
position: relative;
margin-left: 80px;
box-sizing: border-box;
margin-top: 50px;
}
.logo-rodape {
padding: 0;
margin: 0 auto;
box-sizing: border-box;
display: inline-block;
}
.r-content {
padding: 0;
box-sizing: border-box;
display: inline-block;
text-align: left;
margin-left: 30px;
margin-top: 20px;
}
.slogan-title {
font-family: "avenir next condensed";
font-size: 0.3em;
font-size: calc(0.3em + 1vw);
#include screen-above(800px) {
font-size: 0.4em;
}
font-weight: 600;
letter-spacing: 1.5px;
margin-bottom: -2px;
color: #fff;
}
.slogan-sub {
font-family: 'Lato', sans-serif;
font-size: 0.2em;
font-size: calc(0.2em + 1vw);
#include screen-above(800px) {
font-size: 0.3em;
}
font-weight: 300;
letter-spacing: 1px;
color: #fff;
}
.r-social {
text-align: right;
box-sizing: border-box;
display: inline-block;
margin-top: 40px;
margin-left: 60px;
}
.fa-facebook {
padding-right: 20px;
}
a i.fa:hover {
color: #57cdf7; !important;
}
I'll be really glad with any suggestions, I tried out everything I know so far and couldn't get it right.
Thanks!
I'm assuming that your question means you want the social icons to sit on the FAR right of the screen, not necessarily in the confines of the grid that Bootstrap sets.
You would be messing with the Bootstrap grid to re-define .container like you did, and there are issues that go along with that (as you saw).
The best bet is to create an entirely separate component that you can move to wherever you want, independent of the Bootstrap grid.
HTML
<div class="social-icons">
<ul>
<li>Social Icon</li>
<li>Another Icon</li>
</ul>
</div>
CSS
.social-icons {
position: fixed;
bottom: -10px;
right: -5px;
}
ul {
list-style: none;
}
.social-icons li {
display: inline;
padding-right: 30px;
padding-bottom: 20px;
width: 100px;
}
CodePen
This in particular glues the social icons to the bottom of the page regardless of scrolling. But it gives you an idea of what to do.
First, you are supposed to wrap the whole content inside the container. Container is pre set class in bootstrap to keep your content in the appropriate place with appropriate width on different size screens.
<div class="container">
<footer>
<div class="row">
<div class="logo-rodape col-md-2">
<img src="img/logo-principal-white-gota.png" alt="Logo Picada Zero">
</div>
<div class="r-content col-md-4">
<p class="slogan-title">CLEAN AND PROTECTION</p>
<p class="slogan-sub">Proteção e limpeza para sua família</p>
</div>
<div class="r-social col-md-6">
<i class="fa fa-facebook fa-2x" aria-hidden="true" style="color:#fff"></i>
<i class="fa fa-vimeo fa-2x" aria-hidden="true" style="color:#fff"></i>
</div>
</div>
</footer>
</div> <!--end container-->
Also, the cols should equal to 12. col-md-2 + col-md-4 + col-md-6 = col-md-12.
col-md-12 is the full width of the page.
Here is a good read for you: http://getbootstrap.com/css/
And, what you are seeing in the inspector "margin right by social icons" is padding or the width that is pre set on your container in the bootstrap css.
First, Use row and container Class Separately.
Second, Your cols should equal to 12 as described in bootstrap grid system.
Third, you can also use offsetting columns which increases the left margin. example is given below
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.css"></script>
</head>
<footer>
<div class="container ">
<div class="row ">
<div class="col-md-2">
<img src="img/logo-principal-white-gota.png" alt="Logo Picada Zero">
</div>
<div class=" col-md-4">
<p class="slogan-title">CLEAN AND PROTECTION</p>
<p class="slogan-sub">Proteção e limpeza para sua família</p>
</div>
<div class=" col-md-3 col-md-offset-3">
<i class="fa fa-home fa-2x" aria-hidden="true" ></i>
<i class="fa fa-vimeo fa-2x" aria-hidden="true"></i>
</div>
</div>
</div>
</footer>

Unable to shift text upwards in HTML

I'm probably really sleepy and missing something easy here. I've tried every margin and padding available but I'm unable to lift a span (div or any other text containing element for that matter) that contains some text to the right level.
What's the best way to achieve this? In the fiddle below, i want to align it with the font-awesome icon.
.add-cohorts-button > a > i {
padding-top: 5px;
}
.add-cohorts-button > span {
padding-left: 8px;
/*any amount of bottom margin/padding doesn't work. Try it. Height didn't either */
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="col-xs-3 add-cohorts-button">
<a href="addcohort.form"><i class="fa fa-plus-square-o fa-2x" aria-hidden="true"></i>
<span>Hello from the other side </span></a>
</div>
Way out of this fix?
This Suits you?
Adjust the margin according to your icon height.
.add-cohorts-button > a > i {
padding-top: 5px;
}
.add-cohorts-button span {
position:absolute;
padding-left:8px;
margin-top:10px;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="col-xs-3 add-cohorts-button">
<a href="addcohort.form"><i class="fa fa-plus-square-o fa-2x" aria-hidden="true"></i>
<span>Hello from the other side </span></a>
</div>
Use display: inline-block on your link so that it can fit its height to its contents, then use vertical-align: middle, like this:
.add-cohorts-button a {
display: inline-block;
}
.add-cohorts-button > * {
vertical-align: middle;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="col-xs-3 add-cohorts-button">
<i class="fa fa-plus-square-o fa-2x" aria-hidden="true"></i>
<span>Hello from the other side </span>
</div>
Version with the whole thing as a link:
.add-cohorts-button {
text-decoration: none;
}
.add-cohorts-button i {
display: inline-block;
}
.add-cohorts-button > * {
vertical-align: middle;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/>
<a class="col-xs-3 add-cohorts-button" href="addcohort.form">
<i class="fa fa-plus-square-o fa-2x" aria-hidden="true"></i>
<span>Hello from the other side </span>
</a>