Vertically Center in Twitter Bootstrap - html

I'm using Bootstrap in order to create a notification-like drop down when the user mouseovers the bell icon (font-awesome). The menu is created alright, each element inside the menu is indicated by a red chevron sign. I'm not able to center the chevron vertically and align the text to the right of the chevron to start from the same place (there's some margin at the beginning of each line). I cant vertically center the chevron with a fixed value because the length of the string inside the container can be different and the position of the chevron should be determined dynamically.
Basically, I'm creating a jQuery element
$("<div class='notification-content'><i class='ion-chevron-right'></i><span class=''>"+randromString+"</span></div>");`,
and the chevron is inserted with the content.
JSfiddle here.
HTML
<div class="notifications_wrap text-center center b-l b-r hidden-sm hidden-xs">
<span class="vlign"> </span>
<a href="#" id="notification-center" aria-haspopup="true" data-toggle="dropdown">
<i class="glyphicon glyphicon-bell"></i>
<span class="bubble "></span>
</a>
<div class="dropdown-menu notification-toggle1" role="menu" aria-labelledby="notification-center" id="notif">
<!-- START Notification -->
<div class="notification-panel">
<div class="test"></div>
</div>
</div>
</div>
CSS
#notif{
background-color: white;
color: black;
}
.notification-content{
text-align: left;
padding: 10px;
padding-right: 25px;
border-bottom: 1px solid #ddd;
transition: 0.4s ease;
}
.notification-content:hover{
color: #48B0F7;
}
.notification-toggle1 {
top: 75px;
padding: 0;
z-index: 9999;
left: 100px;
width: 250px;
}
/* > sign of the notification*/
.notification-content >.ion-chevron-right:before {
color: red;
/* display:inline-block;*/
vertical-align: middle;
line-height: 50%;
width: 50px;
height: 20px;
}
.notification-content>span{
position: relative;
left: 15px;
}
JS
$(".notifications_wrap").find("a").mouseover(function(){
$(".notification-content").remove();
var random_i=randomNumOfNotifs();
for(var i=0;i<random_i;i++){
var randromString = stringGen(randomLength());
var notification = $("<div class='notification-content'><i class='ion-chevron-right'></i><span class=''>"+randromString+"</span></div>");
$("#notif").append(notification);
}
$("#notif").animate({height:"show"},500);
});

You can add the following css:
.notification-content >.ion-chevron-right {
display:table-cell;
vertical-align:middle;
}
.notification-content>span{
display:table-cell;
}
Here is a fiddle

Related

HTML items not getting positioned on the right using CSS

I am trying to align my items list to the right side of the web page. Also, I wanted to have a vertical thin separator between the left and center data structure (hierarchy) and my right list.
Right.component.html :
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<div class="header-divider">
<ul class="selection-list">
<li *ngFor="let item of getSelections()">
<button class="btn" (click)="deselect(item)" *ngIf="item.selected">
<i class="fa fa-close"> {{ item.displayName }} </i>
</button>
</li>
</ul>
</div>
Right.component.css :
.selection-list {
list-style: none;
margin-top: 5px;
margin-bottom: 10px;
line-height: 15px;
font-size: 16px;
color: #555;
padding-left: 23px;
text-transform: capitalize;
right: 0;
}
.btn {
border: none;
padding: 0;
background: none;
}
.header-divider {
border-left:1px solid #38546d;
height:30px;
position:relative;
right:20px;
top:10px;
}
Right now, it just appears below my hierarchy structure. What should I do to fix this?
I always favor the use of flexbox which is a great simple way to use all available space inside a container. This is how I would do it:
-----(Edited)-----
.flex-container {
display: flex;
height: 50px;
border: solid 1px peru;
}
.sendToRight {
margin-left: auto;
}
<div class="flex-container">
<div class="PLCheck">
fortuneSelect
</div>
<div class="sendToRight"> <!-- add class to div for manipulation -->
rightSideComp
</div>
</div>
In this example, the margin-left:auto makes your .sendToRight div move all the way to the right. You could also use justify-content: space-between; in your container element to achieve the same result.

CSS Top position needs manual refresh

I am making a webshop and have encountered a sort of weird bug.
I am trying to make a cart "badge" to easily view how many items that are in the cart. It's a responsive site and the badge is located on a a tag with two spans of display: block inside. On the desktop side the badges css looks like this:
.count::after{
content: "2";
display: inline-block;
background: #FF0000;
border-radius: 20%;
padding: 0 0.5em;
transform: scale(0.7);
color: #FFF;
float: right;
position: absolute;
top: 5px;
right: 1.5em;
}
.count::after:empty{
display: none;
padding: 0
}
Which works fine and the badge displays in the upper right corner. However on mobile, the a tags wrapper goes full-width and using the above css results in the badge flying off to the side of the screen.
Thus i wrote the following mobile code:
#media max-width: 990px{
...
.count::after{
position: relative;
top: -90%;
right: 0;
}
}
However. The top: -90% doesn't register properly.
If i enter the development tools and switch it off and on, it works perfectly. But if i refresh it goes right back down to the bottom of the icon.
JS-fiddle of the offending part: here
I agree with Shahil, you should set the position:relative to the element with the .count class and set position:absolute and top:-5px (let's say) to the .count::after
Like so:
.d-block{
display: block;
}
.d-inline_block{
display: inline-block;
}
.t-center{
text-align: center;
}
.menu{
width:100%;
text-align: center;
}
.count {
position:relative;
}
.count::after{
content: "2";
display: inline-block;
background: #FF0000;
border-radius: 20%;
padding: 0 0.5em;
transform: scale(0.7);
color: #FFF;
float: right;
position: absolute;
top: -5px;
right: 0;
}
<div class="col-xs-12 col-md-4 my-auto menu t-right">
<a href="/account/login" class="d-inline_block headerLink">
<i class="fa fa-lg fa-user d-block t-center py-8">icon</i>
<span class="d-block t-center">Min konto</span>
</a>
<i class="fa fa-lg fa-question d-block t-center py-8">icon</i><span class="d-block t-center">Kundeservice</span>
<i class="fa fa-lg fa-shopping-cart d-block t-center py-8">icon</i><span class="kurv d-block t-center">Min kurv</span>
</div>
This should work on both Desktop and mobile without using #media queries

Glyphicons not aligning properly in Firefox

I am trying to make a page that shows an Application, the Environments that app is served in (Dev, Test, Prod, etc), and finally the Host that application is running on.
In our back-end, we have it set up so that an application can be made active or passive, and a host can be made active or passive as well. I've added glyphicons that visualize the app and host states.
The glyphicons are supposed to be contained within the server name button, and if you run the jsfiddle in Chrome you'll see how it's supposed to look.
The problem is in Firefox, the glyphicons get pushed down to what looks like a new line. I don't want this to happen - I want it to look the same as in Chrome. I've done some googling and inspecting of properties and can't see to ascertain why this is happening and how it can be fixed.
<body>
<div id="container" class="container-fluid col-lg-10 col-md-10 col-sm-12" role="main">
<div class="app row" id="ATStatsProcessor">
<h4>Application Name</h4>
<div class="environment col-sm-4 col-lg-3">
<h5>Environment Name</h5>
<span class="glyphicon glyphicon-chevron-down pull-right"></span>
<span class="glyphicon glyphicon-chevron-up pull-right"></span>
<div class="host">
<div class="host btn btn-default btn-pressed">
<span class="button-text">Server Name</span>
<span class="state-enabled icon-size-small glyphicon glyphicon-off pull-right"></span>
<span class="state-enabled icon-size-small glyphicon glyphicon-hdd pull-right"></span>
</div>
</div>
</div>
</div>
</div>
</body>
CSS:
.app {
color: #818a98;
border-radius: 6px;
margin: 1em;
padding: 1em;
background-color: #e4e9ef;
}
div.environment h5 {
display: inline-block;
max-width: 80%;
}
.environment {
color: #818a98;
border-radius: 6px;
margin: .5em 2.25em;
padding-top: .25em;
padding-bottom: 1em;
background-color: white;
}
.app .environment .host {
display: inherit;
margin: .25em;
}
.host.btn.btn-default {
background-color: #c93135;
color: white;
}
.host.btn.btn-pressed {
background-color: #2f3b46;
color: white;
}
.confirm.btn-success {
background-color: #63a72c !important;
}
.confirm.btn-danger {
background-color: #c93135 !important;
}
body {
background-color: #f8f9fb !important;
}
.icon-size-small {
font-size: x-small;
}
.state-enabled {
color: green;
}
.button-text {
display: inline-block;
max-width: 85%;
overflow-x: hidden;
}
https://jsfiddle.net/zc419hwa/11/
It seems that floats clear all elements within a parent element that has the white-space: nowrap; property in Firefox. Not sure why this is, but it can be worked around easily enough. You can fix the issue a few different ways:
Modify your HTML code by moving the button-text span after the glyphicons like so:
<div class="host btn btn-default btn-pressed">
<span class="state-enabled icon-size-small glyphicon glyphicon-off pull-right"></span>
<span class="state-enabled icon-size-small glyphicon glyphicon-hdd pull-right"></span>
<span class="button-text">Server Name</span>
</div>
--OR--
Remove property white-space: nowrap; from your .btn class.
--OR--
Absolutely position your glyphicons by adding this code to your CSS:
.host {
position: relative;
}
.host .glyphicon {
position: absolute;
top: 0;
right: 0;
margin-top: 5px;
margin-right: 10px;
}
.host .glyphicon-hdd {
margin-right: 21px;
}

Floating Action Button Text to the Side

I have been trying to add labels to the left of my FAB. I am liking the Material Design, but I am having an issue on getting the labels to appear properly. Any tips would be appreciated. Everything is displaying correctly except adding labels.
Here is a working example:
http://codepen.io/petja/pen/OVRYMq
HTML
<div class="backdrop"></div>
<div class="fab child" data-subitem="1">
<img alt="" src="images/smile.jpg">
</div>
<div class="fab child" data-subitem="2">
<img alt="" src="about/smile.jpg">
</div>
<div class="fab visible-xs float-phone" id="masterfab">
<i class="fa icon-phone soft-white"></i>
</div>
CSS
.fab {
background: #1C9E00;
border-radius: 50%;
text-align: center;
color: #FFF;
position: fixed;
right: 70px;
font-size: 25px;
padding: 9px 2.5px 6px;
-webkit-filter: drop-shadow(0 1px 3px rgba(0, 0, 0, .42));
}
.fab span {
vertical-align: middle;
}
.fab.child {
width: 53.666667px;
height: 37.666667px;
display: none;
opacity: 0;
background: transparent;
border-radius: 0%;
right: 63px;
padding: 0;
}
.fab img {
border-radius: 50%;
}
.backdrop {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #FAFAFA;
opacity: 0.7;
display: none;
}
JS
$(function(){
$(".fab,.backdrop").click(function(){
if($(".backdrop").is(":visible")){
$(".backdrop").fadeOut(125);
$(".fab.child")
.stop()
.animate({
bottom : $("#masterfab").css("bottom"),
opacity : 0
},125,function(){
$(this).hide();
});
}else{
$(".backdrop").fadeIn(125);
$(".fab.child").each(function(){
$(this)
.stop()
.show()
.animate({
bottom : (parseInt($("#masterfab").css("bottom")) + parseInt($("#masterfab").outerHeight()) + 70 * $(this).data("subitem") - $(".fab.child").outerHeight()) + "px",
opacity : 1
},125);
});
}
});
});
You want something like this?
There is .backdrop class in your css So, when I try to add materialize tooltipped it has same class name .backdrop which responsible to change background color of tooltip.
You added background: #ECECEC; in .backdrop So, tooltips had also same background color. So, I changed your .backdrop to .backdrop_gray and Now everything is fine.
HTML
<div class="backdrop_gray"></div>
<div class="tooltipped fab child" data-position="left" data-delay="50" data-tooltip="I am C" data-subitem="1"><span>C</span></div>
<div class="tooltipped fab child" data-position="left" data-delay="50" data-tooltip="I am B" data-subitem="2"><span>B</span></div>
<div class="tooltipped fab child" data-position="left" data-delay="50" data-tooltip="I am A" data-subitem="3"><span>A</span></div>
<div class="fab" id="masterfab"><span>+</span></div>
<h1>Floating Action Button</h1>
<p>(Hint: Button interacts with you)</p>
JS
$('.tooltipped').tooltip({delay: 50});
... // Your other JS.
Working Codepen
Check out this github issue
Github user philipraets created a nice codepen to demonstrate his soluton.
Edit (For the Lazy):
philipraets created a simple css style:
.mobile-fab-tip {
position: fixed;
right: 85px;
padding:0px 0.5rem;
text-align: right;
background-color: #323232;
border-radius: 2px;
color: #FFF;
width:auto;
}
then wrapped the tooltip within another link element using that style:
<div class="fixed-action-btn click-to-toggle" style="bottom:24px; right:24px;">
<a class="btn-floating btn-large red"><i class="large material-icons">settings</i></a>
<ul>
<li>
<i class="material-icons">create</i>
Edit <!--tooltip-->
</li>
<li>
<i class="material-icons">event</i>
Save to calendar <!--tooltip-->
</li>
<li>
<i class="material-icons">supervisor_account</i>
Switch responsible <!--tooltip-->
</li>
</ul>
</div>

Using glyphicon as background image in CSS: rails 4 + bootstrap 3

I'm using bootstrap's collapse.js to expand and collapse some input groups in a rails app. I'm using JS to determine if the group is expanded or not and have created CSS classes to add a "+" or "-" to show whether it's open or closed:
Open:
Closed:
As you can see from the CSS, I'm using a background image that's a png within my images:
.expandable {
background: url('/assets/plus.png');
padding-top: 4px;
width: 400px;
height: 30px;
background-repeat: no-repeat;
padding-left: 55px;
display: block;
}
.expanded {
background: url('/assets/minus.png');
padding-top: 4px;
width: 400px;
height: 30px;
background-repeat: no-repeat;
padding-left: 55px;
display: block;
}
I would like to use the glyphicon-plus and glyphicon-minus instead of these .png files.
What's the best way to accomplish this?
Updated:
In order to get the proper styling, I changed the CSS to:
.expandable {
height:40px;
width:50%;
margin:6px;
}
.expandable:before{
content:"\2b";
font-family:"Glyphicons Halflings";
line-height:1;
margin:5px;
}
.expanded {
height:40px;
width:50%;
margin:6px;
}
.expanded:before{
content:"\2212";
font-family:"Glyphicons Halflings";
line-height:1;
margin:5px;
}
And for reference, my HTML is:
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<p1 class="panel-title" >
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" class="expandable">
Provider details
</a>
<p2>
</div>
<div id="collapseOne" class="panel-collapse collapse">
<div class="panel-body">
blah, blah....
And JS to detect the opening/closing of the sections:
$ ->
$(".expandable").click () ->
$this = $(this)
if $this.hasClass("expandable")
$this.removeClass("expandable").addClass "expanded"
else $this.removeClass("expanded").addClass "expandable" if $this.hasClass("expanded")
return
return
Here, try this Bootply. Would this suffice?
<div id="lol"></div>
#lol{
height:40px;
border:1px solid #555;
width:50%;
margin:30px;
}
#lol:before{
content:"\2b";
font-family:"Glyphicons Halflings";
line-height:1;
margin:10px;
display:inline-block;
}
I did something similar to get an arrow effect, using absolute positioning to move the glyph to where I wanted it:
li.arrow {
&:after {
content:"\e080";
font-family:"Glyphicons Halflings";
position: absolute;
right: 15px;
top: 10px;
}
padding-right: 25px;
}