FontAwesome Icons disturbs pixel during transformation - css

I am using FontAwesome Icons in my application on a tree structure list. fa-caret-down and fa-caret-right disturbs my pixel like on right to dow it moves content right to 5 pixels during change fa-caret-right to fa-caret-down.
Here is my html code:
<i class="fa fa-caret-down"></i>
CSS:
.fa {
display: inline-block;
font: normal normal normal 14px/1 FontAwesome;
/*font-size: inherit;*/
text-rendering: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
transform: translate(0, 0);
}
.fa-caret-right:before {
content: "\f0da";
}
.fa-caret-down:before {
content: "\f0d7";
}

Font Awesome has a fix for this.
Fixed Width Icons
Use fa-fw to set icons at a fixed width. Great to use when different icon widths throw off alignment. Especially useful in things like nav lists & list groups.
Here you can find information on different Font Awesome Features.
ul {
list-style:none;
}
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/>
<ul>
<li>
<span class="fa fa-caret-down fa-fw"></span>
Fruit
<ul>
<li>Apple</li>
<li>Orange</li>
<li>Apple</li>
</ul>
</li>
<li>
<span class="fa fa-caret-right fa-fw"></span>
Animals
<ul>
<li>Monkey</li>
<li>Dog</li>
<li>Cat</li>
</ul>
</li>
</ul>

You have to remember that Font-Awesome icons are nothing more than simple characters - letters, if you like. The letter 'W' for example is wider than the letter 'I' - equally .fa-caret-down is wider than .fa-caret-right.
To overcome this problem, one solution to this is to define a specific width on your i element to stop different icons from influencing this value themselves:
i.fa {
text-align: center; /* If you want the icons to appear central. */
width: 20px; /* Adjust accordingly. */
}

Related

Add :before content to an elements child

I have the following, simplified:
<ul class="menu">
<li class="button-1">
Link
</li>
</ul>
The 'a' is dynamically loaded and I cannot add a class to it. I can only add a class to the 'li'. I want to add an icon before the 'a', so that it is included as part of the clickable link.
Currently I have:
.button-1:before {
font-family: "FontAwesome";
content: "\f007";
padding-left: 14px;
}
which sets the icon perfectly above the text link. But it's not clickable. Thus, I tried...
.button-1 a:before
But this doesn't work. Nor any other variation that I can think of or find. I think I am being incredibly stupid here and missing something obvious. Any advice. Thanks
It works (i.e. clickable etc.) when you use the :before on the child, i.e. .button-1 > a:before:
.button-1 > a:before {
content: "© ";
}
<ul class="menu">
<li class="button-1">
Link
</li>
</ul>
(As you can see, I used some other content to work around the non-available FontAwesome Icon)
ADDITION AFER COMMENTS:
You can also use :afer insteadof before. In this case you need some more settings, also for the parent, especially a relative/absolute position pairing as shown below:
.button-1 {
position: relative;
padding-left: 20px;
}
.button-1>a:after {
content: "©";
position: absolute;
left: 0px;
}
<ul class="menu">
<li class="button-1">
Link
</li>
</ul>

How to display icon and text below each other with icon in center

I have an i tag with background image and then follows <span>.
Basically its an icon followed by text. I am trying to align the icon in center and then below the icon the text.
How can I do this?
I tried with vertical align, but it did not work.
<li>
<i class="icons" ></i>
<span>Icon text</span>
<li />
CSS :
.icons ::before {
content: url(/Style/Image1.svg);
}
You can do this a few ways (once you fix the syntax errors):
1. Using flexbox
With flex you only need to style the container element using the right options to make the child elements act as we wish - see the comments:
li {
display: flex;
align-items: center; /* center align the elements in the container */
flex-direction: column; /* make the child elements appear one under another */
}
.icons:before { content: url(https://via.placeholder.com/200x100); }
<ul>
<li><i class="icons"></i><span>Icon text 1</span></li>
<li><i class="icons"></i><span>Icon text 2</span></li>
</ul>
2. Block elements with text-align: center
/* center-align the container element */
li { text-align: center; list-style: none; }
/* make i and span block elements so they appear one below the other */
li i, li.span { display: block; }
.icons:before { content: url(https://via.placeholder.com/200x100); }
<ul>
<li><i class="icons"></i><span>Icon text 1</span></li>
<li><i class="icons"></i><span>Icon text 2</span></li>
</ul>
Note - you also have a number of syntax errors:
You cannot have a space between the selector and :before (or ::before - both work)
Also <li /> is not correct - you close an li element using </li>
As you can see first error you write .icon instead of .icons and second just use double ::
.icons::before {
content: url("https://placeholder.pics/svg/300");
}
<i class="icons" ></i>
<span>Icon text</span>
Pack them into div styled like this:
<div style="text-align: center;">
<i class="icons" ></i>
<div>Icon text</div>
</div>
Vertical alignment works, when you want to center them putting in one line, but if I understood well you want to put text under the icon, so you should use text-align instead of vertical-align
Here's a simpler way of doing this
.icons {
display: flex;
align-items: center;
}
.icons::before {
content: url(https://static2.clutch.co/s3fs-public/logos/r7q9_xgp.png);
}
<li>
<span class="icons">Icon Text here</span>
</li>

List row columns with different icons in css

How can I do one list of elements (ul with text) in a row and that each element has an icon or an image to its left. Here's an example: list row columns with different icons in css
My main problem is to put the images or icons. I dont know how to make it with an image or an icon different for each element (text) too.
You can either include the icon/image in the list element:
<ul>
<li><img src="icon1.png" alt="icon" /> Text next to icon</li>
<li><img src="icon2.png" alt="icon" /> Text next to icon</li>
</ul>
...or if you're using an icon font like FontAwesome then you can just do:
<ul>
<li><i class="fa fa-desktop"></i> Text next to icon</li>
<li><i class="fa fa-apple"></i> Text next to icon</li>
</ul>
I can agree with Lauri. But this is how you can achive your goal without frameworks by pure css.
<style>
ul {
padding: 0;
}
li {
padding: 0.15em 0 0.5em 1.5em;
margin-bottom: 0.2em;
text-indent: 0.4em;
font-weight: bold;
list-style: none;
background-repeat: no-repeat;
background-size: 10px;
background-image: url("https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcR_DztL2nlERHrDWBFIyA5dp9sblqn6zt57uoRB4IbAbymgpFskfg");
}
</style>
<ul>
<li>Text</li>
<li>Text</li>
</ul>

How to render bootstrap dropdown above the object?

I have this HTML which renders a bootstrap dropdown under the object. It is possible to make it apear above the Title button?
<div class="btn-group">
<a class="btn dropdown-toggle" data-toggle="dropdown">
Title
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li class="dropdown-submenu"><a>Option 1</a></li>
<li class="dropdown-submenu"><a>Option 1</a></li>
(various number of <li>)
</ul>
</div>
I've tried with position:absolute; top:50px but doesn't work for any case.
Thanks!
This is by default part of what Bootstrap can do. It's in the docs under Button Dropdowns - Dropup menus
<div class="btn-group dropup">
As it's absolutely positioned, you will need to have some space above the button so you can see the drop up menu, so I wouldn't use it at the top of a page.
I've set up a fiddle here for you. If you remove the <br> at the top, you'll see that the menu options are hidden at the top of the output box.
you can rotate the container, and rotate the items inside to appear normal :)
its just a few lines of css.
css:
.dropdown {
left: 40px;
top: 150px;
transform: rotate(180deg);
}
.dropdown a, .dropdown button {
transform: rotate(180deg);
}
.dropdown a {
padding: 5px 35px 5px 5px;
}
.dropdown-menu {
margin-left: -18px !important;
}
fiddle
IMO its very simple and elegant solution, the only downside you will have to use transform or 'left' with important to override Bootstrap's direct styling on the element to adjust the opened menu

Gap between list-items with floated elements in IE7 (with isolated test case)

I'm having huge difficulties in removing the gap between list items in IE7.
The problem with gap between the list-items occurs when I am floating elements inside the li:s.
A simple test case is here (with 2 different possible solutions that didn't work):
http://jsfiddle.net/UJMr8/1/
...And here is the HTML from the test:
<ul>
<li class="even">
<span class="left">left</span>
<span class="right">right</span>
</li>
<li class="odd">
<span class="left">left</span>
<span class="right">right</span>
</li>
<li class="even">
<span class="left">left</span>
<span class="right">right</span>
</li>
<li class="odd">
<span class="left">left</span>
<span class="right">right</span>
</li>
</ul>
With the following css:
li { height: 30px; line-height: 30px; padding: 0 10px; }
.even { background: #ccc; }
.odd { background: #eee; }
.left { float: left; }
.right { float: right; }
Any suggestions or thoughts on this? Thanks!
Edit: Thanks for the comment, I hadn't test it in other browsers. So, you can use conditional comments, to target internet explorer only like this
<!--[if IE 7 ]>
li {height:0px;}
<![endif]-->
Or you can use an external css, to target internet explorer 7 for any other problem you may have and you can't find a cross browser solution:
<!--[if IE 7 ]>
<link type="text/css" rel="stylesheet" href="ie7.css"/>
<![endif]-->
Another option is to use an internet explorer hack, like asterisk *. An example is
*height:0px;
The hack must be below the height:30px to be able to override it.
I suggest you to use conditional comments, instead the hack.
Have you tried using Eric Meyers CSS Reset?
http://www.cssreset.com/downloads/css-resets/eric-meyer-reset-css/eric-meyer-reset.css
It sets all browser default margin and padding to 0
You will have a lot of problems with styling list items if you don't change their display to block and reset them properly.
Add this to the top of your css:
ul li, ul {
list-style:None;
margin:0;
padding: 0;
display:block;
}

Resources