Bootstrap div as table td, middle text - html

problem with set vertical align to content inside div
Example:
<div class="row border">
<div class="col-lg-1 col-md-1 col-xs-1 col-sm-1">
<span class="align-middle">Short</span>
</div>
<div class="col-lg-1 col-md-1 col-xs-1 col-sm-1 ">
<span class="align-middle">Long col with long text</span>
</div>
https://jsfiddle.net/lymychm/cuv10dqo/
I want to vertically show text in div's.
So if i set line-height to span it works, but when text has many words with spaces between them...each word now starts from new line and this line(each) has same line-height
Example:
https://jsfiddle.net/lymychm/prc2rstd/
This is what i want, but on div https://jsfiddle.net/lymychm/zn48z0ex/

.border {
border: 1px solid red;
}
.line-height-class {
line-height: 120px;
}
.abc { display: table;
width: 100px; /* width of parent */
height:100px; /* height of parent */
overflow: hidden; }
.inner {
display: table-cell;
vertical-align: middle;
width: 100%;
margin: 0 auto;
text-align: center;
}
<div class="row border">
<div class="col-lg-1 col-md-1 col-xs-1 col-sm-1 abc">
<span class="align-middle inner">Short</span>
</div>
<div class="col-lg-1 col-md-1 col-xs-1 col-sm-1 ">
<span class="align-middle">Long col with long text</span>
</div>
</div>

Use flexbox, See the example: https://jsfiddle.net/prc2rstd/6/
HTML,
<div class="box">
<div class="row align-middle">
<div class="col-lg-1 col-md-1 col-xs-1 col-sm-1 column">
<span>Short</span>
</div>
<div class="col-lg-1 col-md-1 col-xs-1 col-sm-1 column">
<span>Long col with long text</span>
</div>
</div>
</div>
CSS,
.box {
border: 1px solid red;
width: auto;
padding: 20px;
display: inline-block;
}
.align-middle {
display: flex;
align-items: center;
}
.column {
width: 70px;
}

As when float :left is used then it is hard to make it vertically align middle. we need to define row as a table and its inner div as table cell and remove floats from it. But somehow we have another good approach for it i.e using flexbox, demo https://jsfiddle.net/anmolsandal/cuv10dqo/1/
Updated css
.border {
border: 1px solid red;
display: flex;
align-items: center;
}
.line-height-class {
line-height: 120px;
}
code
<div class="row border">
<div class="col-lg-1 col-md-1 col-xs-1 col-sm-1">
<span class="align-middle">Short</span>
</div>
<div class="col-lg-1 col-md-1 col-xs-1 col-sm-1 ">
<span class="align-middle">Long col with long text</span>
</div>
</div>

you can add this code in your css,
.col-lg-1 {
display: inline-block;
vertical-align: middle;
float: none;
}
change that class name...

Expand the width of your div like this fiddle.
.border {
border: 1px solid red;
}
.line-height-class {
line-height: 120px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="row border">
<div class="col-lg-1 col-md-1 col-xs-1 col-sm-1">
<span class="align-middle line-height-class">Short</span>
</div>
<div class="col-lg-9 col-md-9 col-xs-9 col-sm-9 ">
<span class="align-middle line-height-class">Long col with long text</span>
</div>
</div>

Related

creating three dots vertically with span and align them

I'm trying to create three vertical dots and align the bottom left of my container with css and bootstrap 5. exactly like the pic below:
my HTML and CSS:
.dot {
border-radius: 50%;
height: 12px;
width: 12px;
background: linear-gradient(90deg, #76b3fe, #8680e4);
}
.selected-dot {
height: 20px;
width: 20px;
background: #97cdfe;
}
<section class="slider-bg-1 d-flex align-items-end">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-5 d-flex flex-column justify-content-center pt-4 pt-lg-0 order-2 order-lg-1">
<h1 class="head-font-size">Choose a powerful design for your Start-up</h1>
<h6 claas="caption-text-color">Get your freebie template now</h6>
<div class="d-lg-flex">
<div class="mt-5"><button class="my-btn" type="submit">Discover</button></div>
</div>
</div>
<div class="col-lg-5 col-md-12 col-sm-12 order-1 order-lg-2 d-flex justify-content-center">
<img src="Assets/home-slider/slider-m-1.png" class="img-fluid img-slider" alt="">
</div>
</div>
</div>
<span class="dot selected-dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</section>
this is my output
how can i align the vertically and move them to bottom left of container? because when i use div for wrapping they disappear
1st: wrap the dots in a container. I used a section with the class: .dot-wrapper.
2nd: give the wrapper a width: min-content;. With that, it will only be as wide as the seclected dot.
3rd: to cenetr the dots, give them a margin left and right of auto;
.dot {
border-radius: 50%;
height: 12px;
width: 12px;
background: linear-gradient(90deg, #76b3fe, #8680e4);
margin: 5px auto;
}
.selected-dot {
height: 20px;
width: 20px;
background: #97cdfe;
}
.dot-wrapper {
width: min-content;
}
<section class="slider-bg-1 d-flex align-items-end">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-5 d-flex flex-column justify-content-center pt-4 pt-lg-0 order-2 order-lg-1">
<h1 class="head-font-size">Choose a powerful design for your Start-up</h1>
<h6 claas="caption-text-color">Get your freebie template now</h6>
<div class="d-lg-flex">
<div class="mt-5"><button class="my-btn" type="submit">Discover</button></div>
</div>
</div>
<div class="col-lg-5 col-md-12 col-sm-12 order-1 order-lg-2 d-flex justify-content-center">
<img src="Assets/home-slider/slider-m-1.png" class="img-fluid img-slider" alt="">
</div>
</div>
</div>
<section class="dot-wrapper">
<div class="dot selected-dot"></div>
<div class="dot"></div>
<div class="dot"></div>
</section>
</section>
it's quite easy, you can wrap the dots with a div container like this
<!--Column Dots -->
<div class="dot-container">
<span class="dot selected-dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</div>
and style the container as below
.dot-container{
width: 15px;
display: flex;
flex-direction:column;
align-items:center;
}
and for better styling. give dot class some amrgin like margin: 3px 0;
here is a codpen : https://codepen.io/shammlo/pen/QWKggNX?editors=1100

Column width on table is not following grid container width on bootstrap?

I have been trying to build a table with Bootstrap 4 grid container. Everything looks great (styling, alignment,...) except for one problem: the table doesn't follow the grid container as expected. It seems like only the first column expands/shrinks when I try to resize my browser.
I used the display property to build my table to solve alignment problems, but once I try putting col-# as class names for the columns, it doesn't seem to work.
.my-table {
border: 1px solid grey;
display: table;
padding: 0;
}
.my-table-row-header {
display: table-header-group;
height: 50px;
}
.first-header-column {
display: table-cell;
vertical-align: middle;
text-align: center;
}
.my-table-body {
display: table-row-group;
}
.my-table-row {
height: 50px;
border-left: 1px solid grey;
border-bottom: 1px solid grey;
display: table-row;
}
.row-cell {
display: table-cell;
vertical-align: middle;
border-right: 1px solid grey;
}
.c-column {
display: table-cell;
vertical-align: middle;
text-align: center;
padding-left: 11px;
padding-right: 11px;
}
<div class="container-fluid no-gutters">
<div class="my-table col-9 table">
<div class="my-table-row-header row">
<div class="first-header-column col-1 row-cell">
<span class="c-column">c</span>
</div>
<div class="second-column col-4 row-cell">
<span>text</span>
</div>
<div class="third-column col-4 row-cell">
<span>text</span>
</div>
</div>
<div class="my-table-body">
<div class="my-table-row row">
<div class="first-column col-1 row-cell">
<span class="c-column">c</span>
</div>
<div class="second-column col-4 row-cell">
<span>text</span>
</div>
<div class="third-column col-4 row-cell">
<span>text</span>
</div>
</div>
<div class="my-table-row row">
<div class="first-column col-1 row-cell">
<span class="c-column">c</span>
</div>
<div class="second-column col-4 row-cell">
<span>text</span>
</div>
<div class="third-column col-4 row-cell">
<span>text</span>
</div>
</div>
</div>
</div>
</div>
Jsfiddle: https://jsfiddle.net/4zn5oby6/2/
If you try resizing your browser, you'll see the first column resizes accordingly. I expect it to follow the grid container size strictly.
P.S. Since my table contains other components (not just text), I would like to keep the display properties to assure my styling is on point if possible. Thanks.
I am not clear on what the question is exactly, but I noticed the col-9 needed to be in its own div. Then to equal 12 columns add the col-3 div after.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<style>
.my-table {
border: 1px solid grey;
display: table;
padding: 0;
}
.my-table-row-header {
display: table-header-group;
height: 50px;
}
.first-header-column {
display: table-cell;
vertical-align: middle;
text-align: center;
}
.my-table-body {
display: table-row-group;
}
.my-table-row {
height: 50px;
border-left: 1px solid grey;
border-bottom: 1px solid grey;
display: table-row;
}
.row-cell {
display: table-cell;
vertical-align: middle;
border-right: 1px solid grey;
}
.c-column {
display: table-cell;
vertical-align: middle;
text-align: center;
padding-left: 11px;
padding-right: 11px;
}
</style>
</head>
<body>
<div class="container-fluid no-gutters">
<div class="col-9">
<div class="my-table table">
<div class="my-table-row-header row">
<div class="first-header-column col-1 row-cell">
<span class="c-column">c</span>
</div>
<div class="second-column col-4 row-cell">
<span>text</span>
</div>
<div class="third-column col-4 row-cell">
<span>text</span>
</div>
</div>
<div class="my-table-body">
<div class="my-table-row row">
<div class="first-column col-1 row-cell">
<span class="c-column">c</span>
</div>
<div class="second-column col-4 row-cell">
<span>text</span>
</div>
<div class="third-column col-4 row-cell">
<span>text</span>
</div>
</div>
<div class="my-table-row row">
<div class="first-column col-1 row-cell">
<span class="c-column">c</span>
</div>
<div class="second-column col-4 row-cell">
<span>text</span>
</div>
<div class="third-column col-4 row-cell">
<span>text</span>
</div>
</div>
</div>
</div></div>
<div class="col-3"></div>
</div>
</body>
</html>
So, I found a way around it. Instead of using display: table-cell and all that vertical-align and text-align crap, I used display: flex which respected the bootstrap grid column width (which I'm still not sure why?).

horizontally center multiple divs within a div in small devices (xs)

My page has 3 div(s) within a div. In tablet and desktop screens they look good (center-aligned), but on a very small device such as cellphone the inner div(s) are left aligned (I want them to be horizontally center aligned). I applied text-center, and center-block to the outer div but it does not work. Any suggestion? Here are the html, and css codes.
.img-responsive {
display: block;
max-width: 100%;
height: auto;
}
portfolio-caption {
max-width: 281px;
background-color: #994ACC;
text-align: center;
padding: 10px;
border-top: 3px solid #ffffff;
margin-bottom: 10px;
}
<div class="row">
<div class="col-md-4 col-sm-6 col-xs-12">
<div style="max-width: 281px">
<a href="#" ">
<img src="./x/pilotproject1.jpg " class="img-responsive " style="margin: 0 auto; " alt=" ">
</a>
<div class="portfolio-caption text-center ">
<strong><h4>Project Name</h4></strong>
</div>
</div>
</div>
<div class="col-md-4 col-sm-6 col-xs-12 ">
<div style="max-width: 281px ">
<a href="# ">
<img src="./x/pilotproject2.jpg " class="img-responsive "
style="margin: 0 auto; " alt=" ">
</a>
<div class="portfolio-caption text-center ">
<strong><h4>Project Name</h4></strong>
</div>
</div>
</div>
<div class="col-md-4 col-sm-6 col-xs-12 ">
<div style="max-width: 281px ">
<a href="# " class="pilot-link ">
<img src="./x/pilotproject3.jpg " class="img-responsive "
style="margin: 0 auto; " alt=" ">
</a>
<div class="portfolio-caption text-center ">
<strong><h4>Project Name</h4></strong>
</div>
</div>
</div>
</div>
The reason that I have is that the width of the pictures is 281 px, if I do not set the width, the width of the div that comes after the img will be bigger than 281 px which is not something that I want.
as you can see in this picture, the images are all left-aligned
I added a class centered as a container to center elements (please remove the border border: 1px solid red; it is used to show you the container block ):
.centered {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
border: 1px solid red;
}
.img-responsive {
display: block;
max-width: 281px !important;
height: auto;
margin: 0 auto;
}
wrap each element you want to be centered.
Also in your css portfolio-caption should be .portfolio-caption to select a class.
I moved your in-line style to css class img-responsive so you can update your style in one place.
.img-responsive {
display: block;
max-width: 281px !important;
height: auto;
margin: 0 auto;
}
.portfolio-caption {
width: 281px;
background-color: #994ACC;
text-align: center;
padding: 10px;
border-top: 3px solid #ffffff;
margin-bottom: 10px;
float: right;
}
.centered {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
/* border: 1px solid red; */
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<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>
<div class="row">
<div class="col-md-4 col-sm-6 col-xs-12">
<div class="centered">
<a href="#">
<img src="http://placehold.it/350x150" class="img-responsive" alt=" ">
</a>
</div>
<div class="centered">
<div class="portfolio-caption text-center ">
<strong><h4>Project Name</h4></strong>
</div>
</div>
</div>
<div class="col-md-4 col-sm-6 col-xs-12">
<div class="centered">
<a href="# ">
<img src="http://placehold.it/350x150" class="img-responsive" alt=" ">
</a>
</div>
<div class="centered">
<div class="portfolio-caption">
<strong><h4>Project Name</h4></strong>
</div>
</div>
</div>
<div class="col-md-4 col-sm-6 col-xs-12">
<div class="centered">
<a href="# " class="pilot-link ">
<img src="http://placehold.it/350x150" class="img-responsive" alt=" ">
</a>
</div>
<div class="centered">
<div class="portfolio-caption text-center ">
<strong><h4>Project Name</h4></strong>
</div>
</div>
</div>
</div>
You should not apply classes to outer divs, apply them exactly to what you want to be centered : class="img-responsive center-block", and
also check the bootstrap version center-block is new in Bootstrap version 3.0.1 i believe.
Use
Text align : center ;
text-align:center
<div style="max-width: 281px; text-align : center">
Plunker link :
https://plnkr.co/edit/UaW436KiylzfqOCU1cg1?p=preview

How to change the bg color on hover for entire row in bootstrap 3

Actuly i want to make a grid tiles like below image
My all columns comes in a parent div thats why i am unbale to change the bg color on hover for entire row.
If i use multiple rows as a parnet for cloumns than these columns wont comes correctly to each other.
HTML:
<div class="container grid-layout">
<div class="row">
<div class="col-xs-12 col-md-3 col-sm-3">
<div class="name">Supercity</div>
</div>
<div class="col-xs-12 col-md-3 col-sm-3">
<div class="name">Supercity</div>
</div>
<div class="col-xs-12 col-md-3 col-sm-3">
<div class="name">Supercity</div>
</div>
<div class="col-xs-12 col-md-3 col-sm-3">
<div class="name">Supercity</div>
</div>
<div class="col-xs-12 col-md-3 col-sm-3">
<div class="name">Supercity</div>
</div>
<div class="col-xs-12 col-md-3 col-sm-3">
<div class="name">Supercity</div>
</div>
<div class="col-xs-12 col-md-3 col-sm-3">
<div class="name">Supercity</div>
</div>
</div>
</div>
CSS:
.grid-layout .row .col-md-3{
text-align: center;
border-bottom:#eee solid 1px;
}
.grid-layout .row .col-md-3 > a{
padding:10px 0;
display: inline-block;
width:100%;
color:#999999;
outline: none;
}
.grid-layout .row .col-md-3 > a:hover{
color:#5fa9e3;
text-decoration: none;
}
.grid-layout .row .col-md-3:hover{
background: #f7f7f7;
cursor: pointer;
}
.name{
padding:15px 0;
}
Please let me know what would be the correct approach.
You can try this using CSS like this:
.row:hover div[class^="col-"]{
background-color: #dcdcdc;
}
Hope this is what you are looking for.
If you just want to change the .row background-color this will work.
$('body > div > div').on( "mouseover", function() {
$( this ).css( "background-color", "red" );
});

Vertical aligment elements in bootstrap

i'm create a little site like a app store page, and cant align all elements in the middle of div .game-dark
<div class="row">
<div class="game-dark col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="number col-lg-1 col-md-1 col-sm-1 col-xs-1">
<p>1</p>
</div>
<div class="col-lg-1 col-md-1 col-sm-2 col-xs-2">
<img src="img/kings-empire.png" alt="Kings Empire" title="Kings Empire" class="thumb img-responsive">
</div>
<div class="col-lg-8 col-md-8 col-sm-7 col-xs-5">
<h2 class="game-name">Kings Empire</h2>
</div>
<div class="col-lg-2 col-md-2 col-sm-2 col-xs-3">
<button type="button" class="btn btn-default">Скачать</button>
</div>
</div>
How i can vertical align all elements in the middle in my case?
Live example - here
there are multiple ways to realize this.
here a simple way:
add this to your css
.game-dark {
line-height: 100px;
}
no margin on <p>
.number p {
margin: 0;
}
set max-height to the img
.img-responsive {
min-height: 45px;
min-width: 45px;
max-height: 100px;
}
remove margin/padding of h2
h2.game-name {
margin:0;
padding: 0;
line-height: 100px
}
more ways are here http://www.vanseodesign.com/css/vertical-centering/
First set line-height to 98px on .game-dark.col-lg-12.col-md-12.col-sm-12.col-xs-12, and remove display: block style from image. That will align everything except second to last div. With h2 set top and bottom margin to 0, and also set line-height to 98px.