Bootstrap - Align text and icons on sidebar - html

As we can see in the sidebar the icons are aligned left, but the text not.
So the question is: How can i align the icons and the text?
Example code is
<li [routerLinkActive]=" ['active']" [routerLinkActiveOptions]="{exact:true}">
<a [routerLink]="['/notificaciones/listado']">
<i class="fa fa-bell"></i> {{'notifications' | translate}}
</a>
</li>
<li [routerLinkActive]=" ['active']" [routerLinkActiveOptions]="{exact:true}">
<a [routerLink]="['/analitica-avanzada/grafica']">
<i class="fas fa-chart-line"></i> {{'advance-analytics' | translate}}
</a>
</li>

You are using FontAwesome in your example.
FontAwesome 5+ itself shows the solution:
Just use "fa-fw" in the icons-class.
https://fontawesome.com/how-to-use/on-the-web/styling/fixed-width-icons
<div><i class="fas fa-skating fa-fw" style="background:DodgerBlue"></i> Skating</div>
<div><i class="fas fa-skiing fa-fw" style="background:SkyBlue"></i> Skiing</div>
<div><i class="fas fa-skiing-nordic fa-fw" style="background:DodgerBlue"></i> Nordic Skiing</div>
<div><i class="fas fa-snowboarding fa-fw" style="background:SkyBlue"></i> Snowboarding</div>
<div><i class="fas fa-snowplow fa-fw" style="background:DodgerBlue"></i> Snowplow</div>

you should have the same width for all the icons, so in your css you can do something like:
i{
width: 12px;
margin-right: 4px;
}
Please change the values according your needs.

The best way is wrap the fontawesome <i> tag using another <span> tag, and apply a min-width value.
HTML
<li [routerLinkActive]=" ['active']" [routerLinkActiveOptions]="{exact:true}">
<a [routerLink]="['/notificaciones/listado']">
<span class="fa-icon">
<i class="fa fa-bell"></i>
</span>
{{'notifications' | translate}}
</a>
</li>
CSS
.fa-icon {
display: inline-flex;
min-width: 20px;
justify-content: flex-start;
}

Related

Flexbox "nowrap" value isn't working

This is the section of my code that doesn't work:
.copyright {
display: flex;
flex-wrap: nowrap;
/* This is not working */
color: red;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<p>Sample</p>
<span>
<li class="fa-stack">
<i class="fa fa-square fa-stack-2x" style="color:#3b5998"></i>
<i class="fa fa-facebook fa-stack-1x fa-inverse"></i>
</li>
<li class="fa-stack">
<i class="fa fa-square fa-stack-2x" style="color:#00aced"></i>
<i class="fa fa-twitter fa-stack-1x fa-inverse"></i>
</li>
</span>
<br><br>
<p class="copyright">
<span>I want this left from icons</span>
<span>
<li class="fa-stack">
<i class="fa fa-square fa-stack-2x" style="color:#3b5998"></i>
<i class="fa fa-facebook fa-stack-1x fa-inverse"></i>
</li>
<li class="fa-stack">
<i class="fa fa-square fa-stack-2x" style="color:#00aced"></i>
<i class="fa fa-twitter fa-stack-1x fa-inverse"></i>
</li>
</span>
</p>
Do you know why flexwrap: nowrap; isn't working? My icons are below the span instead of being placed to the right.
It's not working because flex-wrap: nowrap applies to flex items, not the text inside the item. You need to target the text with white-space: nowrap.
.copyright {
display:flex;
flex-wrap: nowrap; /* will prevent flex items on the same line from wrapping */
white-space: nowrap; /* will prevent text from wrapping */
}
jsFiddle demo
Just give your copyright class display: inline-block;
Just need a common wrapper such a div and display flex
div {
display: flex;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<p>Sample</p>
<span>
<li class="fa-stack">
<i class="fa fa-square fa-stack-2x" style="color:#3b5998"></i>
<i class="fa fa-facebook fa-stack-1x fa-inverse"></i>
</li>
<li class="fa-stack">
<i class="fa fa-square fa-stack-2x" style="color:#00aced"></i>
<i class="fa fa-twitter fa-stack-1x fa-inverse"></i>
</li>
</span>
<br><br>
<p class="copyright">
<div>
<span>I want this left from icons</span>
<span>
<li class="fa-stack">
<i class="fa fa-square fa-stack-2x" style="color:#3b5998"></i>
<i class="fa fa-facebook fa-stack-1x fa-inverse"></i>
</li>
<li class="fa-stack">
<i class="fa fa-square fa-stack-2x" style="color:#00aced"></i>
<i class="fa fa-twitter fa-stack-1x fa-inverse"></i>
</li>
</span>
</div>
</p>
I just needed to update <p class="copyright"> with <div class="copyright">
Or I could use display:block for the p.copyright
which ever elements or icons you want to see in a line and in order, then place those in a div element which is having flex.
and you dont need flex-wrap property as with proper html order ,just a display:flex property will take care of most of the things
See here https://jsfiddle.net/b6vw9t2y/38/
<div style='display: flex'>
<i>icon1></i>
<i>icon2</i>
<i>icon3</i>
</div>
output: icon1 icon2 icon3
go through below link for flexbox basics , its understandable and it will surely makes ur life much easier when u get the grip of flexbox
https://www.w3schools.com/css/css3_flexbox.asp

Center Icon Separately From Corresponding Text

just a quick one. I have 3 Font Awesome icons that i'm using for contact buttons on my page. These are aligned vertically and centered within a container div. I also have text next to each icon, which results in both icon and text being centered on the page. What i'm after is to center the icons vertically and have the text follow separately. I believe I could wrap the icons in a container then all the corresponding text in another container, but I realise this would look messy in my CSS. There must be a simple answer out there that i'm not realising. If you don't understand what i'm going on about please view the code snippet below. Thanks for any feedback.
<section class="contact-main">
<div class="container">
<div class="email">
<i class="fas fa-envelope fa-3x"><p> Email</p></i>
</div>
<div class="phone">
<i class="fas fa-phone-square fa-3x"><p> Phone</p></i>
</div>
<div class="facebook">
<i class="fab fa-facebook-square fa-3x"><p> Facebook</p></i>
</div>
</div>
</section>
You can use fixed-width icons with class fa-fw . Here is the link.
HTML
<div class="list-group">
<a class="list-group-item" href="#"><i class="fa fa-home fa-fw" aria-hidden="true"></i> Home</a>
<a class="list-group-item" href="#"><i class="fa fa-book fa-fw" aria-hidden="true"></i> Library</a>
<a class="list-group-item" href="#"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i> Applications</a>
<a class="list-group-item" href="#"><i class="fa fa-cog fa-fw" aria-hidden="true"></i> Settings</a>
</div>
I hope it helps.
Something like this? Fiddle
<body>
<section class="contact-main">
<div class="container">
<div class="list-group">
<div class="email">
<i class="fa fa-envelope fa-3x fa-fw"></i><h3 style="display:inline-block;">Email</h3>
</div>
<div class="phone">
<i class="fa fa-phone-square fa-3x fa-fw"></i><h3 style="display:inline-block;">Phone</h3>
</div>
<div class="facebook">
<i class="fab fa-facebook-square fa-3x fa-fw"></i><h3 style="display:inline-block;">Facebook</h3>
</div>
</div>
</div>
</section>
</body>
Was overthinking the whole thing. I just moved them into alignment using position: relative. Lightbulb finally lit up!

How can I put my bootstrap buttons in a vertical line going down in the centre of my webpage?

I was wondering how can I put my bootstrap buttons in a vertical line going down in the middle of my web page? I tried using vertical-align: top;
but it didn't work.
My site code.
Here is the HTML to the buttons I want to go down one after the other in a vertical line in the middle of the web page.
<ul class="list-inline intro-social-buttons">
<li>
<i class="fa fa-linkedin fa-fw"></i> <span class="network-name">Web Development Portfolio</span>
</li>
<li>
<i class="fa fa-linkedin fa-fw"></i> <span class="network-name">GFX Design Portfolio</span>
</li>
<li>
<i class="fa fa-linkedin fa-fw"></i> <span class="network-name">About Me</span>
</li>
<li>
<i class="fa fa-linkedin fa-fw"></i> <span class="network-name">Contact Me</span>
</li>
</ul>
As a side note if anyone could also help me with this it would be much appreciated.
How can I adjust the width of how long the <hr class="content-divider"> is but I need it to be responsive. I don't want the line to go past from where the buttons on each side end.
ul.intro-social-buttons li {
padding-bottom: 10px;
float: left;
display: block;
width: 100%;
}

Creating a 2x2 grid of Font Awesome icons and text beneath using Flexbox

I am trying to create a responsive 2x2 grid of Font Awesome icons with text beneath, both centered within their containing li element. I'm currently trying to use a method that I used when I was doing something similar with images within a list using Flexbox but it doesn't seem to work the same.
Here is my current HTML:
<section id="services">
<h2>What we do best:</h2>
<ul class="fa-ul">
<li>
<span class="fa-stack fa-2x">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-wrench fa-stack-1x fa-inverse"></i>
</span>
<p>Application Support</p>
</li>
<li>
<span class="fa-stack fa-2x">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-users fa-stack-1x fa-inverse"></i>
</span>
<p>User Training</p>
</li>
<li>
<span class="fa-stack fa-2x">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-headphones fa-stack-1x fa-inverse"></i>
</span>
<p>SharePoint Consulting</p>
</li>
<li>
<span class="fa-stack fa-2x">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-magic fa-stack-1x fa-inverse"></i>
</span>
<p>Custom Development</p>
</li>
</ul>
</section>
And CSS:
#services{
margin: 0 auto;
}
#services h2{
margin-left: 1rem;
margin-top: 0;
padding-top: 2rem;
}
#services ul{
display: flex;
flex-flow: row wrap;
}
#services li{
margin: .55rem;
font-size: .85rem;
flex-basis: calc(50% - 20px);
}
.fa-circle{
color: #30C0D8;
}
That code has gotten me here:
Will this method work for this situation or is there a better way? For some reason, as a side note, when I expand the window my 2nd column of icons moves whereas the 1st column of icons stay put. Any ideas why that would be? Here's a screenshot:
Thank you!
I think text-align: center; will help you for #services li

border radius not work for fa-stack in font awesome

I add fontawesome icon with square this worked for me:
HTML:
<ul class="list-inline">
<li><a href="#">
<span class="fa-stack fa-lg icon-facebook">
<i class="fa fa-square fa-stack-2x"></i>
<i class="fa fa-facebook fa-stack-1x"></i>
</span>
</a></li>
<li><a href="#">
<span class="fa-stack fa-lg icon-twitter">
<i class="fa fa-square fa-stack-2x"></i>
<i class="fa fa-twitter fa-stack-1x"></i>
</span>
</a></li>
<li><a href="#">
<span class="fa-stack fa-lg icon-gplus">
<i class="fa fa-square fa-stack-2x"></i>
<i class="fa fa-plus fa-stack-1x"></i>
</span>
</a></li>
</ul>
CSS:
.fa-stack-1x {
color:white;
border-radius:0;
}
.fa-square{
border-radius:0;
}
.icon-facebook {
color:#3b5998;
}
.icon-twitter {
color:#00aced;
}
.icon-gplus{
color:#dd4b39;
}
body {
background-color: black;
}
I need to show square without border radius and I add border-radius:0; for class .fa-square But font awesome not work without border radius.
how do can i fix this ?
DEMO JSFIDDLE
As others mentioned the "square" behind the icon is actually a font icon applied to .fa-square:before in the css.
Unfortunately the Font Awesome set at this time does not contain a true square.
However they do have an icon in their set with much harder corners called the "stop" icon (in the video player icon group). You can substitute this for the "square" in your css to get a much better square stack by doing this. It does make a very slight radius corner, but at small sizes it's hardly noticable:
.fa-square:before {
content: "\f04d";
}
"\f04d" is the CSS content value for the stop icon in Font Awesome.
List of CSS content values for Fontawesome Icons
http://astronautweb.co/snippet/font-awesome/
Results
Image of results
Cheers!
fa-square:before{content:"\f0c8"} is going to cause an issue. You can fix it by removing that class. Then overriding the border-radius for each of the fa-stack-1x icons.
<ul class="list-inline">
<li><a href="#">
<span class="fa-stack fa-lg icon-facebook">
<i class="fa fa-facebook fa-stack-1x"></i>
</span>
</a>
</li>
<li><a href="#">
<span class="fa-stack fa-lg icon-twitter">
<i class="fa fa-twitter fa-stack-1x"></i>
</span>
</a>
</li>
<li><a href="#">
<span class="fa-stack fa-lg icon-gplus">
<i class="fa fa-plus fa-stack-1x"></i>
</span>
</a>
</li>
</ul>
CSS:
body {
background-color: black;
}
.fa-stack-1x {
-webkit-border-radius: 18px;
-moz-border-radius: 18px;
border-radius: 18px;
color:white;
}
.icon-facebook>.fa-stack-1x {
background-color:#3b5998;
}
.icon-twitter>.fa-stack-1x {
background-color:#00aced;
}
.icon-gplus>.fa-stack-1x {
background-color:#dd4b39;
}
For squares just change the border-radius's to 0px; in the above CSS
I looked into font-awesome.min.css and found this line: fa-square:before{content:"\f0c8"} I believe that means you are using \f0c8 to draw the square. That means it is a character from awesome font and you can't change it by border-radius.
You can read about this icon at
http://www.utf8icons.com/character/61640/UTF-8-character