vertically align fontawesome icon to the middle of a textarea - css

I am using skeleton css framework, I want to vertically align my fontawesome icon to the right of a textarea, but it seems the common "vertical-align:middle; display: table-cell;" doesn't work. I also want when the textarea resizes, the icon still aligns in the middle, without hard code a height inside the style, is it possible?
<link href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.css" rel="stylesheet"/>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<style type="text/css">
.icon {
margin-left: 1em;
vertical-align: middle;
display: table-cell;
}
</style>
<div class="row">
<div class="six columns">
<label for="inputA">labelA</label>
<textarea class="u-full-width" id="inputA" type="text"></textarea>
</div>
<div class="one colum">
<span class="icon"> <i class="fa fa-check-circle"></i> </span>
</div>
</div>

You may need to fake it, due to the way skeleton styles its columns.
As such, you can use absolute positioning to offset the icon as necessary:
.six.columns {
position: relative; /* <-- ensure the icon positions relative to the parent column */
}
#inputA {
margin-bottom: 0; /* <-- remove the textarea margin, making the icon look like its not centered */
}
.icon {
position: absolute; /* <-- position the icon */
/* transform:translateY(-50%); OPTIONAL, use for true vertical alignment */
top: 50%;
right: -20px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.css" rel="stylesheet" />
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<div class="row">
<div class="six columns">
<label for="inputA">labelA</label>
<textarea class="u-full-width" id="inputA" type="text"></textarea>
<span class="icon"> <i class="fa fa-check-circle"></i> </span>
</div>
<div class="one column">
</div>
</div>

You can try creating a javascript function wich reubicates the icon. Anyways, it could be a little bit of trouble if you're handling with many dinamic icons/textareas.
css:
.icon {
margin-left: 1em;
vertical-align: middle;
display: table-cell;
position:absolute; <--- additions
padding-top:52px; <--- additions
padding-left:269px; <--- additions
}
HTML (Notice the onClick="resiz()" instruction)
<textarea onClick="resiz()" class="u-full-width" id="inputA" type="text"></textarea>
<span id="ico" class="icon"> <i class="fa fa-check-circle"></i> </span>
JavaScript
document.resiz=function(){
var he = document.getElementById("inputA").offsetHeight;
var wi = document.getElementById("inputA").offsetWidth;
document.getElementById("ico").style.paddingTop=(he/2+20)+'px';
document.getElementById("ico").style.paddingLeft=wi+'px';
}
Here's the code: https://jsfiddle.net/ko2dzcfc/
You can also make the resiz() instruction to execute when the page loads, so it will automatically place the icon correctly at start, and avoid editing the css.
Update: I tested it in Firefox, and it worked well. In chromium it does not work so well. Maybe you'll have to edit the code for differents browsers

Related

Is it possible to make a div visible inside a wrapper display: none div without changing the wrapper div

I have a wrapper div with the following classes d-none d-lg-block. This is to ensure it only visible in large screens.
Within this wrapper div I have another div which I need to make visible when the user clicks on a button. I have tried overriding display, z-index, position properties, but it seems like the wrapper d-none is not overridable. I need a solution without changing the wrapper div (removing the d-none class) as it contains other items which must stay invisible to the user.
Example
$("#btn").on('click', function() {
document.getElementById("text-to-display").classList.toggle("display-me");
});
.display-me {
position: absolute;
top: 30px;
width: 100%;
z-index: 9999;
display: block !important;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
<div class="row">
<div class="col d-none">
<h2 id="text-to-display">Should be visible</h2>
</div>
</div>
<div class="row">
<div class="col" id="btn">
<button>Click me</button>
</div>
</div>
</div>
Codeply Examnple
You hided the entire div using d-none, so the elements present inside div always pretend to be hidden because the parent itself is not visible.
So Just change your JavaScript code, change toggling .display-me on <h2> to <div>.
Since you are using bootstrap, d-none also contains display: none !important. So better mention your class in <style> or else add your <link href='style.css'> after bootstrap's link. Check This
$("#btn").click(function() {
$(".col.d-none").toggleClass("display-me");
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<style>
.display-me {
position: absolute;
top: 30px;
width: 100%;
z-index: 9999;
display: block !important;
}
</style>
<div class="container">
<div class="row">
<div class="col d-none">
<h2 id="text-to-display">Should be visible</h2>
</div>
</div>
<div class="row">
<div class="col" id="btn">
<button>Click me</button>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
And In your JS code, Half the part is jQuery and half the part is vanilla JS and it won't work.
Vanilla JS code
document.getElementById('btn').onclick = function(){
document.querySelector(".col.d-none").classList.toggle("d-block");
}
Additional : Since you are using bootstrap simply you can use d-block instead of display-me as shown above. .display-me contains all unnecessary properties to display except display property.
If you don't want to apply toggle on .col.d-none then move id from h2 to div and apply onclick to id.

When I add a space between <span> and <input>, the <input> will come to a next line in chrome

Everything is in this codesandbox
https://codesandbox.io/s/static-31poq
Different browsers behave differently too.
Here is the screenshots
chrome
firefox
I know how to fix this. What I concern is what causes this.
.wrapper {
display: flex;
width: 80px;
}
.number {
width: 70px;
margin-right: 10px;
}
<div class="wrapper">
<div class="container">
<!-- There is no space. Thus the input is in the same line. -->
<span class="plus">+</span><input class="number" value="1"></input>
</div>
</div>
<div class="wrapper">
<div class="container">
<!-- There is a space. Thus the input comes to the next line.-->
<span class="plus">+</span> <input class="number" value="1"></input>
</div>
</div>
There is space between and . Remove the space and it will display in one line. thanks
Your .wapper width causes the problem try to increase the .wapper width. This problem happens due to different browser css presets. Different browsers have different default css presets therefore default rendering will be vary. To address this problem you can use css normalize style sheet or rest style sheet. However normalize style sheet and reset style sheet has different behaviors.
Normalize style sheet: https://necolas.github.io/normalize.css/
Reset style sheet: https://meyerweb.com/eric/tools/css/reset/
.wrapper {
width: 110px;
display: flex;
}
.number {
width: 70px;
margin-right: 10px;
}
<div class="wrapper">
<div class="container">
<!-- There is no space. Thus the input is in the same line. -->
<span class="plus">+</span><input class="number" value="1"></input>
</div>
</div>
<hr/>
<div class="wrapper">
<div class="container">
<!-- There is a space. Thus the input comes to the next line.-->
<span class="plus">+</span> <input class="number" value="1"></input>
</div>
Chrome:
Firefox:

Font awsome icon not coming on top of Materialize css progress/determinate

I'm trying to show a fontawsome icon to come on top of a materialize css progress/determinate div. But with no luck. the icon shows but not completely part of it is clipped/hidden. I have tried a lot of solution but no help.
.progress .determinate {
overflow: visible;
z-index: 1;
}
.progress .determinate .fa {
position: absolute;
top: -5px;
font-size: 12px;
right: 0px;
visibility: visible;
z-index: 9;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/js/materialize.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css"></script>
<div class="col l9 m9 s9 ">
<div class="col l12 m12 s12">
<div class="progress">
<div class="determinate" style="width:70%">
<i class="fa fa-circle"></i>
</div>
</div>
</div>
</div>
Below is the image showing what it should look like. But i m not able to figure out how to achieve this even after hours of struggling. In the image the circle is the fa-circle icon
Below are some of the posts i have tried
First
Second
Third
Tried several other things but could make it work. Any help will be appreciated. Thanks in advance.
Your .progress overflow is hidden, so make it visible
.progress {
overflow: visible;
}
Here is the solution
http://codepen.io/Bhupinderkumar/pen/dOLOPJ check here i created with codepen and got the solution or you just need to add this
.progress{ overflow:inherit!important }
Your .progress overflow is hidden, so make it visible by adding code as below,
.progress{
overflow:visible !important;
}
!important - by adding !important to your CSS overflow property, you are telling to unseen other important rules and apply this first.
.progress{
overflow:visible !important;
}
.progress .determinate {
width:70%;
}
.progress .determinate .fa {
position:absolute;
top:-5px;
right:0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/js/materialize.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css">
<div class="col l9 m9 s9 ">
<div class="col l12 m12 s12">
<div class="progress">
<div class="determinate">
<i class="fa fa-circle"></i>
</div>
</div>
</div>
</div>

Fixed Header Under Navbar Menu

How to create a header menu under navbar menu which is fixed, like VTiger Dashboard :
Here is mine :
$(document).ready(function(){
$('.ui.dropdown').dropdown();
});
*{
margin: 0;
padding: 0;
}
body{
font-family: 'Open Sans', sans-serif;
margin-bottom: 60px;
}
.ui.grid.main{
margin-top: 70px;
}
.padding-reset{
padding: 0px !important;
}
.ui.message{
padding: 40px !important;
}
#media (max-width: 767px) {
.ui.grid.main{
margin-top: 70px;
}
.ui.vertical.menu.navbar{
margin-top: 0px !important;
}
}
.ui.vertical.menu{
margin-top: -15px !important;
width: 100%;
display: none;
}
.ui.page.grid{
padding-left: 2%;
padding-right: 2%;
}
<head>
<link href="http://cdnjs.cloudflare.com/ajax/libs/semantic-ui/0.13.0/css/semantic.min.css" rel="stylesheet"/>
</head>
<body>
<div class="ui grid">
<div class="ui blue inverted fixed menu navbar page grid">
<i class="home icon"></i>
Calendar
Leads
Account Members
Contacts
Opportunities
Quotes
Documents
Services
<div class="right menu">
<i class="trash brush icon"></i>
<i class="paint brush icon"></i>
<i class="settings icon"></i>
<a class="ui dropdown item">Owner
<i class="dropdown icon"></i>
<div class="menu">
<div class="item">My Preferences</div>
<div class="item">Log Out</div>
</div>
</a>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/semantic-ui/0.13.0/javascript/semantic.min.js"></script>
</body>
Fixed navbar works correctly, but I dont know how to add another segment, which is fixed too, below navbar. I use semantic ui as css framework
You can use semantic UI sticky to add a segment to the top of your page. In that segment your can put multiple menu bars, images, nested segments, texts, etc
<div class="ui sticky stickyTop">
<div class="ui inverted segment">
<div class="ui blue inverted menu navbar">
<i class="home icon"></i>
Calendar
Leads
</div>
<h3 class="ui header">Stuck Content</h3>
<p>Add menu bar, images, whatever here!</p>
<p>You will need to override some semantic UI css, such as margins however. For that, remember to use "<strong>!important"</strong></p>
</div>
</div>
<div class="content">
//... Your body content
</div>
Here's a semi-working code example:
http://jsfiddle.net/sL4fnrz0/3/
I say "semi-working" example, since semantic UI sticky only works to a limited extent in code playgrounds...
Try copy the code to a html file instead.

Can't get alignment right

This bootstrap accordion is built using AngularJS: http://jsfiddle.net/Mrbaseball34/c6Lw2/
<div class="accordion-group ng-scope" ng-repeat="program in programs">
<div class="accordion-inner">
<div class="acc_label ng-binding">The Certified Insurance Counselors Program (CIC)</div>
<div class="pull-right select_links">
<a ng-click="reselect($index)" class="ng-binding">Select All</a> |
<a ng-disabled="!select_action($index)" ng-click="program.expand=!program.expand" class="ng-binding">Expand</a>
</div>
</div>
<div ng-repeat="topic in program.topics" collapse="!program.expand && !topic.checked" class="ng-scope collapse" style="height: 0px;">
<div class="accordion-inner">
<label class="checkbox"><input type="checkbox" value="CIC Agency Management" ng-checked="topic.checked" ng-model="topic.checked" class="ng-pristine ng-valid"><span class="ng-binding">CIC Agency Management</span></label>
</div>
</div>
<div ng-repeat="topic in program.topics" collapse="!program.expand && !topic.checked" class="ng-scope collapse" style="height: 0px;">
<div class="accordion-inner">
<label class="checkbox"><input type="checkbox" value="CIC Commercial Casualty" ng-checked="topic.checked" ng-model="topic.checked" class="ng-pristine ng-valid"><span class="ng-binding">CIC Commercial Casualty</span></label>
</div>
</div>
</div>
But I cannot get the "Select All | Expand" links aligned in the middle of the container.
Can any CSS gurus help out?
Don't worry about the "Select All | Expand" functionality. I just need the alignment corrected.
Also, I'm sorry that the CSS files have to be online vs. embedded in the fiddle.
I don't think it was made clear, I wanted the "Select All | Expand" links centered vertically like this:
After changes recommended by #Mohsen:
When expanded, it should stay near the group title.
horizontal align:
remove pull-right class and set text-align:center to .select_links:
DEMO
HTML
<div class="select_links"> <!-- pull-right remove -->
<a ng-click="reselect($index)" class="ng-binding">Select All</a>
|
<a ng-disabled="!select_action($index)" ng-click="program.expand=!program.expand" class="ng-binding">Expand</a>
</div>
CSS
.select_links {
position: relative;
line-height: 100%;
vertical-align: middle;
text-align: center; /* added */
}
update - vertical align
need to set position:relative on your accordion-group, for doing that you can add this class to that tag like this:
<div class="accordion-group ng-scope relative" <!-- relative added -->
ng-repeat="program in programs">
...
</div>
bring back pull-right and add vertical (or something else) class to your links container like this:
<div class="pull-right select_links vertical"> <!-- vertical added -->
...
</div>
then add these styles to your CSS:
.relative{
position:relative;
}
.vertical{
position: absolute;
right: 5px;
top: 50%;
margin-top: -3px; /* you can change it if is not enough */
}
jsFiddle is HERE
note: you can add this styles to your bootstrap classes but I think this is not a good way.
edit: set relative class to the title container: DEMO
<div class="accordion-inner relative">...</div>
try this
.select_links {
position: relative;
line-height: 100%;
vertical-align: middle;
margin: 0 auto;
width: 70%;
}

Resources