Calculating the height of elements in Bootstrap for vertical alignment - html

I am newbie in Bootstrap & HTML.
In my HTML I have a container and a row with 3 columns inside. In my situation, the title of the last section is way longer than others and needs to be displayed in 2 lines.
Because of this, the text of this section is in lower position than it is in other sections.
My question: Is it possible to make all of these texts after headers to be vertically in the same position?
HTML Code example:
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading">MAIN_TITLE</h2>
</div>
</div>
<div class="row text-center">
<div class="col-md-3">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-search fa-stack-1x fa-inverse"></i>
</span>
<h4 class="service-heading">TITLE_1</h4>
<div class="text-muted eqHeight"> TEXT_1</div>
</div>
<div class="col-md-3">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-search fa-stack-1x fa-inverse"></i>
</span>
<h4 class="service-heading">TITLE_2</h4>
<div class="text-muted eqHeight"> TEXT_2</div>
</div>
<div class="col-md-3">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-search fa-stack-1x fa-inverse"></i>
</span>
<h4 class="service-heading">TITLE_3</h4>
<div class="text-muted eqHeight"> TEXT_3</div>
</div>
<div class="col-md-3">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-search fa-stack-1x fa-inverse"></i>
</span>
<h4 class="service-heading">TITLE_TITLE_TITLE_TITLE_TITLE_TITLE_TITLE_TITLE_TITLE_TITLE_TITLE_TITLE_TITLE_TITLE_TITLE_TITLE_TITLE_4</h4>
<div class="text-muted eqHeight"> TEXT_4</div>
</div>
</div>
</div>
This is how it looks like:

include jQuery and just write javascript for finding and setting the height of bigger one.
function max-height(){
var height=0;
var mHeight=0;
$('.service-heading').each(function(){
height = $(this).height();
if(height>mHeight)
mHeight = height;
});
$('.service-heading').height(mHeight);
height=0;
mHeight=0;
}
then call this function on ready() and resize()
$( document ).ready(function() {max-height();});
$( window ).resize(function() {max-height();});

in your code, text is aligned to center. i have removed it. check comment. then in the long text of title_title_title..so on, i have provided a space which encodes as newline character.
In the column setup, you have provided 'col-md-3' for three time, which makes it three-fourth of the width. so changed it to " col-md-3 , col-md-3 , col-md-6".
check out this.
<div class="container">
<div class="row">
<div class="col-md-12 text-center">
<h2 class="section-heading">MAIN_TITLE</h2>
</div>
</div>
<div class="row "> // removed text-center
<div class="col-md-3">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-search fa-stack-1x fa-inverse"></i>
</span>
<h4 class="service-heading">TITLE_1</h4>
<div class="text-muted"> TEXT_1</div>
</div>
<div class="col-md-3">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-search fa-stack-1x fa-inverse"></i>
</span>
<h4 class="service-heading">TITLE_2</h4>
<div class="text-muted"> TEXT_2</div>
</div>
<div class="col-md-6"> // here col-md-3 changed to col-md-6
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-search fa-stack-1x fa-inverse"></i>
</span>
<h4 class="service-heading">TITLE_TITLE_TITLE_TITLE_TITLE_TITLE_TITLE _TITLE_TITLE_TITLE_TITLE_ TITLE_TITLE_TITLE_TITLE_TITLE_TITLE_3</h4> // here provided with a space.
<div class="text-muted"> TEXT_3</div>
</div>
</div>
</div>

Changed answer: Now that I get what you're asking here, I would recommend using eqHeight library (jQuery). It works like a charm with Bootstrap and what it does is that it automatically calculates the height of the tallest element and adjusts the height of others to same.
In this case you could do the following:
<div class="row">
<div class="col-md-4">
<i class="service-heading eqHeight">Content here</i>
<i>More content here!</i>
</div>
<div class="col-md-4">
<i class="service-heading eqHeight">Content here</i>
<i>More content here!</i>
</div>
<div class="col-md-4">
<i class="service-heading eqHeight">Content here</i>
<i>More content here!</i>
</div>
</div>
The point is to make the eqHeight library point to the .eqHeight class and make it calculate the upper elements (in this case .service-heading classes) to be the same height.
This might require an additional CSS, but shouldn't be more than just height and max-height properties.
Vertical positioning is a slight problem with responsive design. Another solution for this would be of making an additional row below the existing one and setting the same cols in there, but that of course doesn't work when the site breaks up for mobile.

Related

Columns in bootstrap don't fit even though of columns is 12 [duplicate]

This question already has an answer here:
Wrapping bootstrap columns in extra div
(1 answer)
Closed 3 years ago.
I am building a small dashboard, with bootstrap 4. The structure is two columns (5 - 7), inside of which we have different rows and columns.
I have two rows that won't fit the columns inside of them even though the sum is 12.
I tried to wrap all columns inside a row div but it didn't change anything. I tried removing every padding through the developper console and I still get the same issue.
<div class="col-12 leg_planches">
<div class="col-2">
<h5 data-toggle="tooltip" data-placement="top" title="Référence" > <i class="fa fa-tint" aria-hidden="true"></i> <span>A1</span></h5>
<h5 title="Zone géographique"> <i class="fa fa-bolt" aria-hidden="true" ></i> <span></span></h5>
</div>
<div class="col-2">
<h5 data-toggle="tooltip" data-placement="top" title="Irrigation" > <i class="fa fa-tint" aria-hidden="true"></i> <span></span></h5>
<h5 title="Amendements"> <i class="fa fa-bolt" aria-hidden="true" ></i> <span></span></h5>
</div>
<div class="col-2">
<h5 title="Entretient"> <i class="fa fa-broom" aria-hidden="true" ></i> <span></span></h5>
<h5 title="Amendements"> <i class="fa fa-gem" aria-hidden="true" ></i> <span></span></h5>
</div>
<div class="col-2">
<h5 title="Estimation poids sur planche"> <i class="fa fa-hand-holding-usd" aria-hidden="true" ></i> <span></span></h5>
<h5 title="Exporté"> <i class="fa fa-fighter-jet" aria-hidden="true" ></i> <span></span></h5>
</div>
<div class="col-2">
<h5 title="Dépenses"> <i class="fa fa-credit-card" aria-hidden="true" ></i> <span></span></h5>
<h5 title="Temps de travail"> <i class="fa fa-clock" aria-hidden="true" ></i> <span></span></h5>
</div>
<div class="col-2">
<h5 title="Semé le"> <i class="fa fa-baby" aria-hidden="true" ></i> <span></span></h5>
<h5 title="Planté le"> <i class="fa fa-baby-carriage" aria-hidden="true" ></i> <span></span></h5>
</div>
</div>
I'd like for all the columns to fit on a single row as they are supposed to.
Instead of col-12, try with row. Like this
<div class="row leg_planches">
Just replace col-12 with row will resolve your issue. Thanks
<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">
<div class="row leg_planches">
<div class="col-2">
<h5 data-toggle="tooltip" data-placement="top" title="Référence" > <i class="fa fa-tint" aria-hidden="true"></i> <span>A1</span></h5>
<h5 title="Zone géographique"> <i class="fa fa-bolt" aria-hidden="true" ></i> <span>B1</span></h5>
</div>
<div class="col-2">
<h5 data-toggle="tooltip" data-placement="top" title="Irrigation" > <i class="fa fa-tint" aria-hidden="true"></i> <span>A2</span></h5>
<h5 title="Amendements"> <i class="fa fa-bolt" aria-hidden="true" ></i> <span>B2</span></h5>
</div>
<div class="col-2">
<h5 title="Entretient"> <i class="fa fa-broom" aria-hidden="true" ></i> <span>A3</span></h5>
<h5 title="Amendements"> <i class="fa fa-gem" aria-hidden="true" ></i> <span>B3</span></h5>
</div>
<div class="col-2">
<h5 title="Estimation poids sur planche"> <i class="fa fa-hand-holding-usd" aria-hidden="true" ></i> <span>A4</span></h5>
<h5 title="Exporté"> <i class="fa fa-fighter-jet" aria-hidden="true" ></i> <span>B4</span></h5>
</div>
<div class="col-2">
<h5 title="Dépenses"> <i class="fa fa-credit-card" aria-hidden="true" ></i> <span>A5</span></h5>
<h5 title="Temps de travail"> <i class="fa fa-clock" aria-hidden="true" ></i> <span>B5</span></h5>
</div>
<div class="col-2">
<h5 title="Semé le"> <i class="fa fa-baby" aria-hidden="true" ></i> <span>A6</span></h5>
<h5 title="Planté le"> <i class="fa fa-baby-carriage" aria-hidden="true" ></i> <span>B6</span></h5>
</div>
</div>

Align Font awesome and text to left

I'm trying to align my icons and text to the left but it seems a little messy
my code is really simple:
<p class="text-muted mb-2 text-left">22/8 <i class="fa fa-calendar-alt fa-1x"></i>
<br>21:00 <i class="fa fa-clock fa-1x"></i>
<br>Herzeliya <i class="fa fa-map-marker-alt fa-1x"></i>
<br>Texy <i class="fa fa-home fa-1x"></i>
<br>
Can someone help me to align them straight left?
It is necessary to set container widths for icons in accordance with the width of the widest.
<div class="container mt-3">
<div class="row">
<div class="col-12">
<p class="text-muted mb-2 text-left">
<i class="fa fa-calendar-alt fa-1x fa-custom-width mr-2"></i>22/8
<br>
<i class="fa fa-clock fa-1x fa-custom-width mr-2"></i>21:00
<br>
<i class="fa fa-map-marker-alt fa-1x fa-custom-width mr-2"></i>Herzeliya
<br>
<i class="fa fa-home fa-1x fa-custom-width mr-2"></i>Texy
<br>
</p>
</div>
</div>
</div>
.fa-custom-width{
width: 18px;
text-align: center;
}
https://www.codeply.com/go/GQAdPupsFU
Just use the fa-fw class (included in Font Awesome)...
<p class="text-muted mb-2 text-left">
<i class="fa fa-fw fa-calendar-alt fa-1x"></i> 22/8
<br><i class="fa fa-fw fa-clock fa-1x"></i> 21:00
<br><i class="fa fa-fw fa-map-marker-alt fa-1x"></i> Herzeliya
<br><i class="fa fa-fw fa-home fa-1x"></i> Texy
<br>
</p>
https://www.codeply.com/go/ouYds9p7kc

Bootstrap 4 Card image overlay float issue

I'm using Bootstrap 4 and am trying to use a card based layout to display my stores.
I have a location marker that's supposed to come over the store and on the same line, floating to the right, I want a 5 star rating. (Icons from font-awesome)
However, whenever I use float:right on the ratings they vanish. (I assume underneath the image)
Anyone have a clue as to how to fix this?
<div class="card">
<img class="card-img-top" src="https://upload.wikimedia.org/wikipedia/commons/a/a2/Mon_Ami_Boulangerie_(8119944759).jpg" alt="Card image cap">
<div class="card-block">
<div class="stores-card-img-overlay-text">
<p>
<i class="fa fa-map-marker" aria-hidden="true"></i> Hasselt
<span class="rating">
<i class="fa fa-star" aria-hidden="true" style="color: yellow;"></i>
<i class="fa fa-star" aria-hidden="true" style="color: yellow;"></i>
<i class="fa fa-star" aria-hidden="true" style="color: yellow;"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
</span>
</p>
</div>
<div class="test-shizzle">
<i class="fa fa-chevron-right" aria-hidden="true"></i>
</div>
<h4 class="card-title">De bakkerij testshop</h4>
<p class="card-text">Vlees / vis / Gevogelte / Charcuterie / Salades / Soep / Kaas</p>
<p class="card-search-text">14 appels in gamma!</p>
</div>
</div>
And the css to raise the .stores-card-img-overlay-text over the image and float the .rating span:
.stores-list .stores-card-img-overlay-text {
color: #fff;
margin-top: -50px;
}
.stores-list .stores-card-img-overlay-text .rating {
float: right;
}
Thanks in advance!
Update 2018 for Bootstrap 4.0
You can use the Bootstrap float-right class to pull the span right..
<div class="card">
<img class="card-img-top img-fluid" src="https://upload.wikimedia.org/wikipedia/commons/a/a2/Mon_Ami_Boulangerie_(8119944759).jpg" alt="Card image cap">
<div class="card-block">
<div class="stores-card-img-overlay-text">
<p>
<i class="fa fa-map-marker" aria-hidden="true"></i> Hasselt
<span class="rating float-right">
<i class="fa fa-star" aria-hidden="true" style="color: yellow;"></i>
<i class="fa fa-star" aria-hidden="true" style="color: yellow;"></i>
<i class="fa fa-star" aria-hidden="true" style="color: yellow;"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
<i class="fa fa-star-o" aria-hidden="true"></i>
</span>
</p>
</div>
<div class="test-shizzle">
<i class="fa fa-chevron-right" aria-hidden="true"></i>
</div>
<h4 class="card-title">De bakkerij testshop</h4>
<p class="card-text">Vlees / vis / Gevogelte / Charcuterie / Salades / Soep / Kaas</p>
<p class="card-search-text">14 appels in gamma!</p>
</div>
</div>
http://codeply.com/go/60n8Prld36
Idiot that I am I did not realise I could just the the .card-img-overlay class provided by Bootstrap. >_>

Float Left Spacing

I've got a collection of points that I'm displaying, I'm floating them all left, but if the text is too much in the one above it forces there to be a space appear. Can't figure out what's causing this, does anyone have any ideas?
HTML:
<div class="all-the-screen checkmark-move">
<div class="contain-inner">
<div class="checkmark-outer">
<div class="checkmark-33"><div class="fa-stack fa-1x checkmark-icon"><i class="fa fa-circle fa-stack-2x icon-background"></i><i class="fa fa-check fa-stack-1x icon-text"></i></div><div class="checkmark-inner">Water Included</div></div>
<div class="checkmark-33"><div class="fa-stack fa-1x checkmark-icon"><i class="fa fa-circle fa-stack-2x icon-background"></i><i class="fa fa-check fa-stack-1x icon-text"></i></div><div class="checkmark-inner">Gas Included</div></div>
<div class="checkmark-33"><div class="fa-stack fa-1x checkmark-icon"><i class="fa fa-circle fa-stack-2x icon-background"></i><i class="fa fa-check fa-stack-1x icon-text"></i></div><div class="checkmark-inner">Electric Included</div></div>
<div class="clearfix"></div>
<div class="read-more-show noselect">Show More</div>
</div>
</div>
</div>
CSS:
.checkmark-outer {
width:92%;
margin-left:4%;
margin-right:4%;
}
.checkmark-move {
margin-top:18px;
}
.checkmark-inner {
overflow: hidden;
font-family: 'Source Sans Pro Regular';
line-height:24px;
vertical-align: middle;
padding-left:4px;
padding-right:20px;
padding-top:4px;
}
.checkmark-33 {
width:33.33%;
float:left;
margin-bottom:6px;
}
.checkmark-icon {
float:left;
}
.icon-background {
color: #8d1e22;
}
.icon-text {
color: #ffffff;
}
Problem getting
Okay, since you are already familiar with the clearfix concept, you are using it wrong. Change your code this way, to include the floated elements inside the .clearfix:
<div class="clearfix">
<div class="checkmark-33"><div class="fa-stack fa-1x checkmark-icon"><i class="fa fa-circle fa-stack-2x icon-background"></i><i class="fa fa-check fa-stack-1x icon-text"></i></div><div class="checkmark-inner">Water Included</div></div>
<div class="checkmark-33"><div class="fa-stack fa-1x checkmark-icon"><i class="fa fa-circle fa-stack-2x icon-background"></i><i class="fa fa-check fa-stack-1x icon-text"></i></div><div class="checkmark-inner">Gas Included</div></div>
<div class="checkmark-33"><div class="fa-stack fa-1x checkmark-icon"><i class="fa fa-circle fa-stack-2x icon-background"></i><i class="fa fa-check fa-stack-1x icon-text"></i></div><div class="checkmark-inner">Electric Included</div></div>
</div>
Adding height is a hacky way. Use the clearfix properly to nest the floated items.
And also on a side note, use <i> tag to display icons and not <div> tags. It works, but it is not semantically correct. A <div> should be used only for a division or a section.
Give min-height to each checkmark wrap i.e in your case .checkmark-33
Example-
.checkmark-33{min-height:50px /*This should be the max-height of your longest checkmark*/}

How to call pages dynamically play scala using Intellij idea

I have uploaded a simple web template in play Scala using intellij idea. how to call each section from different file,
I am calling each function from index.scala.html
this is my main.scala.html
<html>
<body id="page-top" class="index">
#navigation
#header
#services
#portfolio
#about
#team
#client
#contact
#footer
</body>
</html>
As the above code how to have each function that is #services in separate file, #portfolio in separate file .
this is my index.scala.html
#(message: String)
#navigation = { navigation html code}
#header = {<header> html code</header>}
#services = {
<section id="services"><!--html code for reference-->
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h2 class="section-heading">Services</h2>
</div>
</div>
<div class="row text-center">
<div class="col-md-4">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-shopping-cart fa-stack-1x fa-inverse"></i>
</span>
<h4 class="service-heading">E-Commerce</h4>
</div>
<div class="col-md-4">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-laptop fa-stack-1x fa-inverse"></i>
</span>
<h4 class="service-heading">Responsive Design</h4>
</div>
<div class="col-md-4">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-lock fa-stack-1x fa-inverse"></i>
</span>
<h4 class="service-heading">Web Security</h4>
</div>
</div>
</div>
</section>
}
#main("hello test")(navigation)(header)(services){ }
my application package controllers
import play.api._
import play.api.mvc._
object Application extends Controller {
def index = Action {
Ok(views.html.index("Ok"))
}
}
my routes
GET / controllers.Application.index
I wanted header to be in same file ., make #services #portfolio into different different files and call them as one page web page dynamically.
I know one solution. You have to create one file per function.
navigation.scala.html
#()
navigation html code
header.scala.html
#()
<header> html code</header>
And other.
You can create it in separate package/folder (mainscala) and import all files:
#import views.html.mainscala._
And add brackets:
<html>
<body id="page-top" class="index">
#navigation()
#header()
....
</body>
</html>