Vertical Align Header with Alert and Button - html

I'm trying to vertically align a title header, an alert and two buttons.
My goal is to make the width of the alert bigger even if its content is short. My problem is that since I uses span for the alert, I need to put display: inline-block in its style but by doing that, the alignment with the header gets misaligned. BTW, I'm using Bootstrap.
Here's the image of what I want to happen:
Here's my HTML:
<h1>
<span>This will be a very long title</span>
<span class="alert custom">
This is notification!
</span>
<span class="pull-right">
<button class="btn button-round">O</button>
<button class="btn button-round">X</button>
</span>
</h1>
Here's my CSS:
.button-round {
border-radius: 50%;
color: white;
background: green;
}
.custom{
font-size: 12px;
vertical-align: middle;
background: green;
color: white;
}
Here's a jsfiddle of my current code:
JSFiddle of my current code

To make this easy, you should use flex :
.button-round {
border-radius: 50%;
color: white;
background: green;
margin: auto
}
.custom {
font-size: 12px;
vertical-align: middle;
background: green;
color: white;
/* added */
flex: 1;
margin: 0 0.25em;
}
h1 {
display: flex;
}
/* end added */
<!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>-->
<h1>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<span>This will be a very long title</span>
<span class="alert custom">
This is notification!
</span>
<span class="pull-right">
<button class="btn button-round">O</button>
<button class="btn button-round">X</button>
</span>
</h1>
https://jsfiddle.net/fczbe58L/1/

Related

Is it possible to have button text in two lines with different fonts using HTML and CSS?

Using the attribute value in HTML, I can't make button text work in two lines as well as different font sizes
I have already tried whitespace in css but it's more like word wrap and that does not solve my problem. I also tried using ampersand-hash13; and ampersand-hash10; but it doesn't work as well.
#media (min-height: 280px) {
.divNumKeypad {
position: fixed;
bottom: 0;
width: 100%;
}
.numberBtn{
font-size: 30px;
height: 68px;
}
<div class="col-xs-4 ">
<input id="btnEight" type="button" tabindex="-1" value="HI HELLO" class="btn btn-primary btn-block numberBtn" onclick="buttonClick(8)" />
</div>
I expect to have a button with two lines of text. "HI" should be on the first line with bigger font and the bottom text "HELLO" should be smaller than the text on the top.
Try this below
#media (min-height: 280px) {
.line-1, {
display:block;
font-size: 20px
}
.line-2 {
display: block;
font-size: 10px;
}
}
<div class="col-xs-4 ">
<button>
<span class="line-1">HI</span>
<span class="line-2">HELLO</span>
</button>
</div>
Consider using button instead of input:
button {
font-size: 30px;
}
<button>HI<br><small>HELLO</small></button>
Try this.
label{
max-width: 150px;
font-size: 18px;
display: block;
padding:10px 20px;
border:1px solid black;
cursor: pointer;
}
label span{
display: block;
font-size: 14px;
}
label input{
background:none;
border:none;
}
input[value]{
font-size: 0;
display: none;
}
<div class="col-xs-4 ">
<label> <input id="btnEight" type="button" tabindex="-1" value="HI HELLO" class="btn btn-primary btn-block numberBtn" onclick="buttonClick(8)" />HI<span> HELLO</span></label>
</div>

Put text and form next to photo using bootstrap

This is my HTML:
<div class="row trolibelanja">
<div class="col-md-3">
<img src="http://2.bp.blogspot.com/-WGiyrP7xGOk/VQlHwjgporI/AAAAAAAABHI/zLGXTH0-H2w/s1600/Mie%2BAyam%2B(4).jpg" class="detailfoto">
</div>
<div class="col-md-4">
<p class="detailnama">Mie Ayam Bakso</p>
<p class="detailtoko">Toko Bu Lastri</p>
</div>
<div class="col-md-2">
<p class="detailharga">Rp. 30.000</p>
</div>
<div class="col-md-2">
<div class="input-group">
<span class="input-group-btn">
<button class="btnjumlah" type="button">-</button>
</span>
<input type="text" class="form-control jumlah" value="1">
<span class="input-group-btn">
<button class="btnjumlah" type="button">+</button>
</span>
</div>
</div>
<div class="col-md-1">
</div>
</div>
This is my css:
body{
background-color: #661f61 !important;
font-family: 'Saira Extra Condensed', sans-serif !important;
}
.container-fluid.keranjang {
background-color: #e9e9e9;
flex: 1;
}
.container.keranjang {
}
.row.trolibelanja {
background-color: #e1e1e1;
position: relative;
padding-top: 10px;
padding-bottom: 23px;
}
.row.trolibelanja:after{
background-image: -webkit-linear-gradient(135deg, #6e1c64 25%, #e27f31 25%) !important;
position: absolute;
content: " ";
width: 100%;
height: 15px;
bottom: 0;
}
.detailfoto {
width: 100%;
height: 110px;
border: 6px solid white;
}
.detailnama{
font-size: 20px;
font-weight: bold;
}
.detailtoko{
line-height: 20px;
margin: -17px 0px;
}
.detailharga{
font-size: 20px;
font-weight: bold;
text-align: center;
}
.input-group .jumlah {
width: 50%;
text-align: center;
}
.input-group .btnjumlah {
background-color: #e27f31;
color: white;
border: 0;
font-size: 20px;
font-weight: bold;
padding: 0px 10px;
height: 100%;
}
I am trying to put text and form next to photo using bootstrap, as in photo below:
enter image description here
My code result:
enter image description here
Please let me know what am I missing? I tried each combination of display that i know, but they wouldn't work. Thank you
Arrange your columns properly. And you will be good. put image in one column (col-md-3 in this case) and rest of the content in another (col-md-9), then put all rest of the content in a new row. I would suggest that you have a better understanding of the rows and columns from bootstrap website.
https://www.w3schools.com/bootstrap/bootstrap_grid_system.asp
<div class="row trolibelanja">
<div class="col-md-3">
<img src="http://2.bp.blogspot.com/-WGiyrP7xGOk/VQlHwjgporI/AAAAAAAABHI/zLGXTH0-H2w/s1600/Mie%2BAyam%2B(4).jpg" class="detailfoto">
</div>
<div class="col-md-9">
<div class="row">
<div class="col-md-4">
<p class="detailnama">Mie Ayam Bakso</p>
<p class="detailtoko">Toko Bu Lastri</p>
</div>
<div class="col-md-2">
<p class="detailharga">Rp. 30.000</p>
</div>
<div class="col-md-2">
<div class="input-group">
<span class="input-group-btn">
<button class="btnjumlah" type="button">-</button>
</span>
<input type="text" class="form-control jumlah" value="1">
<span class="input-group-btn">
<button class="btnjumlah" type="button">+</button>
</span>
</div>
</div>
</div>
</div>
</div>
Add flex-wrap: nowrap; to your .row.trolibelanja like this:
.row.trolibelanja {
background-color: #e1e1e1;
position: relative;
padding-top: 10px;
padding-bottom: 23px;
flex-wrap: nowrap;
}
I made codepen example with your code: https://codepen.io/anon/pen/wPZoXX
i ran your code on bootsnipp and found everything is placed side by side to each other, except for the fact that you did not add img-responsive to the image class. and that the below code is distorting your design.
.row.trolibelanja:after{
background-image: -webkit-linear-gradient(135deg, #6e1c64 25%, #e27f31 25%) !important;
position: absolute;
content: " ";
width: 100%;
height: 15px;
bottom: 0;
}
dont you what you intent designing with that, but i think you need to run a check that css code .
when i added your css to it, it distort the whole code.
first review your CSS is well written , targeting the right class.
second add img-responsive to the img class and i think you are good
to go.

Does <br> tag take some horizontal space?

I can't understand why it renders different two lines vertically separated with a br tag from two lines separated vertically making the first line a block level tag.
Here's an example:
https://jsfiddle.net/qzgeassf/
span.block {
display: block;
}
div {
text-align: center;
}
.border {
border: 1px solid black;
display: inline-block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div>
<nav class="bottom-nav">
<span class="border">
<span>PORTFOLIO</span>
<br>
<span><i class="glyphicon glyphicon-circle-arrow-down"></i></span>
</span>
</nav>
</div>
<div>
<span class="border">
<span class="block">PORTFOLIO</span>
<span><i class="glyphicon glyphicon-circle-arrow-down"></i></span>
</span>
</div>
With Chrome dev tools I can't see what's taking that space at the end of the first line.
What you're seeing is white space in the non-block span. Remove the white space between the inline elements, and the widths are the same.
span.block {
display: block;
}
div {
text-align: center;
}
.border {
border: 1px solid black;
display: inline-block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div>
<nav class="bottom-nav"><span class="border"><span>PORTFOLIO</span><br><span><i class="glyphicon glyphicon-circle-arrow-down"></i></span></span></nav>
</div>
<div>
<span class="border">
<span class="block">PORTFOLIO</span>
<span><i class="glyphicon glyphicon-circle-arrow-down"></i></span>
</span>
</div>

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;
}

Vertically Center in Twitter Bootstrap

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