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>
Related
In my website in the same <div>, I have a <span> with three buttons. This is how it looks like in front-end:
This is my HTML:
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 noPadding" style="padding-bottom:15px;">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 noPadding">
<span id="horaPantalla"></span>
<i class="fa fa-cogs imgButton" aria-hidden="true"></i>
<i class="fa fa-camera imgButton" aria-hidden="true" id="configScan"></i>
<i class="fa fa-sign-out imgButton" aria-hidden="true""></i>
</div>
</div>
If I access from my mobile phone I got this:
Two buttons are on the first line and then the other button is on the second line.
My goal is to fit all three buttons together, if the resolution is small I want to put all three buttons in a new row below the <span>.
I have tried the below by adding a class called resolution to the <i> elements:
.imgButton {
font-size: 36px !important;
/*padding: 2px;*/
padding-bottom: 2px;
cursor:pointer;
background-color:#A3D1D4 !important;
border:none !important;
}
#media screen and (max-width: 900px) {
.resolution {
float: none;
width: 100%;
}
}
This is what I get:
How can I put three <i> elements inline below the <span> on mobile devices?
You can wrap the icons in a container div and make both the #hourPantella span and the container div display: inline-block.
For example:
.icon {
width: 25px;
height: 25px;
border: 1px solid black;
display: inline-block;
}
.date, .icon-container {
display: inline-block;
}
<div class="date">Date - Time</div>
<div class="icon-container">
<div class="icon"></div>
<div class="icon"></div>
<div class="icon"></div>
</div>
And a JSFiddle example: https://jsfiddle.net/5a8o7ykd/.
Note that this example is not exactly like what you showed. I just used placeholder divs instead of actual icons and I didn't actually put a date into the span. You should be able to adapt it to work with your code though.
Check if this is what you want?
#media (max-width: 900px) {
.block {
display: block;
}
}
<link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet"/>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 noPadding">
<span id="horaPantalla" class="block">Hour</span>
<i class="fa fa-cogs imgButton" aria-hidden="true"></i>
<i class="fa fa-camera imgButton" aria-hidden="true" id="configScan"></i>
</div>
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>
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>
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
I am trying to align an ionicon icon and text to its side in a vertical way inside a button using Bootstrap 3.
I want the text to be vertically aligned to the center of the button with the icon also vertically aligned.
The default seems to align the icon and the text using their lowest points.
My HTML is:
<div class="col-xs-4 text-right">
<a href="/signout" class="btn btn-xs btn-danger sign-out">
<i class="ion-power ion-fw"></i>
<span class="menu-label">Sign Out</span>
</a>
</div>
My CSS is:
.main-header .navbar .dropdown-menu li a.sign-out {
color: #fff !important;
vertical-align: middle;
}
.ion-fw {
width: 1.28571429em;
text-align: center;
}
My CSS targets the pair OK as their colors are correct. I have tried padding and margins on .menu-label but that moves the text and icon.
How do I adjust the text to the middle of the icon's height? Thanks!
Example:
Change this
.ion-fw {
width: 1.28571429em;
text-align: center;
}
to this
.ion-fw {
width: 1.28571429em;
text-align: center;
vertical-align: middle;
}
vertical-align works on elements in the same container and so must be applied to the contents...not the parent element.
.ion-fw {
width: 1.28571429em;
text-align: center;
vertical-align: middle;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-xs-4 text-right">
<a href="/signout" class="btn btn-xs btn-danger sign-out">
<i class="ion-power ion-fw"></i>
<span class="menu-label">Sign Out</span>
</a>
</div>
This works for me:
.ion-fw {
display: inline-block;
vertical-align: bottom;
height: 1.4em;
font-size: 1.1em;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-xs-4 text-right">
<a href="/signout" class="btn btn-xs btn-danger sign-out">
<i class="ion-power ion-fw"></i>
<span class="menu-label">Sign Out</span>
</a>
</div>