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

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

Related

Bootstrap container-build not filling the screen even with p-0

For screens, I put padding at 0 for container-fluid but the screen still does not fill the screen that is less than or equal to width 1024.
.container-fluid {
background-color: #e2e5f4;
height: 600px;
margin-bottom: 200px;
padding: 0;
}
What works:
at 1024- width: 101%;
at 768- width: 112%;
at 320- width: 112%;
HTML code:
<div class="container-fluid p-0">
<div class="row border bg-danger p-0">
<div class="col-md-7 p-0">
<div class="MededX">
MEDedX
</div>
<div class="capture_tittle">
liunhliunh
<br> lunliu luinu liuni
<br> nllniun Nilo ahh
</div>
<div class="subCapture_tittle">
LOerm Swaminarayan swmainarayan swaminarayan swaminarayan
</div>
</div>
<div class="col-md-5 p-0 ">
<div>
<img class= "hex" src="hex.png">
</div>
<div>
<img class= "medIpad" src="medipad.png">
</div>
<div>
<img class= "plantsLeft" src="plantsLeft.png">
</div>
</div>
</div>
</div>
What's the problem? How do I fix it?
Use a custom wrapper and set its width to 100%.
.container-full {
margin: 0 auto;
width: 100%;
}
or a fast solution
style="width:100%"

Bootstrap - aligning figures with col-sm-4 command

I am trying to align horizontaly three elements using the col-sm-4 function but for whatever reason I am missing it is not working. No matter what I do, the items are still displayed aligned to left and vertically. The images are all the same size.
Here's the code snippet:
<section class="container">
<div class="row">
<figure class="col-sm-4">
<p text-align: center>PLAY</p>
<img src="img/m1.jpg"/>
</figure>
<figure class="col-sm-4">
<p text-align: center>LEARN</p>
<img src="img/m2.jpg"/>
</figure>
<figure class="col-sm-4">
<p text-align: center>HELP</p>
<img src="img/m3.jpg"/>
</figure>
</div>
</section>
and the css:
section .row img {
margin: 0 0 30px;
width: 100%;
border: 4px dotted #000;
clear: none;
}
It puzzles me because I have looked over other websites using the same technique and I cannot spot the error. Thanks.
you want like this ?
section .row img {
border: 4px dotted #000;
clear: none;
display:inline-block;
}
.col-sm-4
{
display:inline-block;
}
DEMO HERE
After making a few adjustments, I managed to get your code working (see comments in snippet for details)
/* made the boxes use flexible boxes to lay themselves out in a row */
.flexgrid {
display: flex;
flex-direction: row;
align-items: center;
}
/* fixed css because there were no 'row' elemeents */
/* added the > operand */
section > .col > img {
margin: 30px 0 30px;
width: 50%;
border: 4px dotted #000;
clear: none;
align: center;
}
.col > div, .col > img {
content-align: center
}
<section class="container">
<div class="flexgrid">
<figure class="col">
<!-- change <p> to <div> to avoid newline -->
<div>PLAY</div>
<center>
<img src="img/m1.jpg" />
</center>
</figure>
<figure class="col">
<div>LEARN</div>
<center>
<img src="img/m2.jpg" />
</center>
</figure>
<figure class="col">
<div>HELP</div>
<center>
<img src="img/m3.jpg" />
</center>
</figure>
</div>
</section>
Seems to be an issue with the screen size your using not being specified in the col-- format. I've added col-lg-4 col-md-4 col-sm-4 col-xs-4 as the class to support all screen sizes and it is working perfectly now.
section .row img {
margin: 0 0 30px;
width: 100%;
border: 4px dotted #000;
clear: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<section class="container">
<div class="row">
<figure class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
<p text-align: center>PLAY</p>
<img src="img/m1.jpg"/>
</figure>
<figure class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
<p text-align: center>LEARN</p>
<img src="img/m2.jpg"/>
</figure>
<figure class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
<p text-align: center>HELP</p>
<img src="img/m3.jpg"/>
</figure>
</div>
</section>
You just need to use predefined bootstrap class text-center for <div class=row...:
section .row img {
margin: 0 0 30px;
width: 100%;
border: 4px dotted #000;
clear: none;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<section class="container">
<div class="row text-center">
<figure class="col-xs-4">
<p text-align: center>PLAY</p>
<img src="img/m1.jpg"/>
</figure>
<figure class="col-xs-4">
<p text-align: center>LEARN</p>
<img src="img/m2.jpg"/>
</figure>
<figure class="col-xs-4">
<p text-align: center>HELP</p>
<img src="img/m3.jpg"/>
</figure>
</div>
</section>

Flexbox in Firefox

I have been building a site and have been experimenting with display:flexand had some success in implementing what I feel is a nice enough thumb-nail block element.
However, in Firefox it does this:
I have tested it and it seems to be an issue with the use of display:flex and position:absolute.
I have read that Firefox treats absolute positioning differently than others browsers I have tested in.
Chrome
Edge
Opera
I have experienced a similar issue in:
Internet Explorer 11
Safari 5.1.7
Firefox 50.1.0
HTML
<section id="services" class="text-center center-block">
<div class="container">
<div class="row">
<!-- Block -->
<div class="col-xs-12 col-sm-6 col-lg-4">
<div class="thumbnail grey mb-30">
<img src="img/picto/originals/png/Pound/Newable_Pictogram_CoolGrey_POUND.png" width="156" height="200" alt="" />
<div class="caption">
<p class="bold">Attractive commissions for business introductions, paid promptly.</p>
</div>
</div>
</div>
<!-- Block -->
<!-- Block -->
<div class="col-xs-12 col-sm-6 col-lg-4">
<div class="thumbnail grey mb-30">
<img src="img/picto/originals/png/Arrows/Newable_Pictogram_Navy_ARROWS.png" width="200" height="199" alt="" />
<div class="caption">
<p class="bold">We’re committed to delivering fast, and treating you and your clients fairly.</p>
</div>
</div>
</div>
<!-- Block -->
<!-- Block -->
<div class="col-xs-12 col-sm-6 col-lg-4">
<div class="thumbnail grey mb-30">
<img src="img/picto/new/Newable_Pictogram_Navy_GROWTH.png" width="271" height="200" alt="" />
<div class="caption">
<p class="bold">We are a trusted, long established and large-scale Responsible Finance Provider.</p>
</div>
</div>
</div>
<!-- Block -->
<!-- Block -->
<div class="col-xs-12 col-sm-6 col-lg-4">
<div class="thumbnail grey mb-30">
<img src="img/picto/new/Newable_Pictogram_cool_grey_PARTNER.png" width="200" height="200" alt="" />
<div class="caption">
<p class="bold">Incentive-led schemes to promote long term business development partnership.</p>
</div>
</div>
</div>
<!-- Block -->
<!-- Block -->
<div class="col-xs-12 col-sm-6 col-lg-4">
<div class="thumbnail grey">
<img src="img/picto/originals/png/Speech Bubbles/Newable_Pictogram_CoolGrey_SPEECHBUBBLES.png" width="263" height="200" alt="" />
<div class="caption">
<p class="bold">Best in class broker support package including dedicated account manager.</p>
</div>
</div>
</div>
<!-- Block -->
<!-- Block -->
<div class="col-xs-12 col-sm-6 col-lg-4">
<div class="thumbnail grey">
<img src="img/picto/originals/png/Infinity/Newable_Pictogram_Navy_INFINITY.png" width="215" height="100" alt="" />
<div class="caption">
<p class="bold">We partner with finance brokers, financial advisors, High Street banks, solicitors and accountants.</p>
</div>
</div>
</div>
<!-- Block -->
</div>
</div>
</section>
CSS
.thumbnail {
border: none;
min-height: 500px;
position: relative;
display: -webkit-flex;
display: flex;
justify-content: center;
align-items: center;
}
.thumbnail img {
padding-top: 0;
max-height: 50%;
max-width: 50%;
padding-bottom: 25%;
}
.caption {
position: absolute;
bottom: 0;
}
Am I just using display:flex incorrectly?
Check this basic example of your scenario (commented .caption padding just to make it clearer):
Added flex-flow: column wrap; to .thumbnail.
div.thumbnail {
border: none;
min-height: 500px;
position: relative;
display: -webkit-flex;
display: flex;
flex-flow: column wrap;
justify-content: center;
align-items: center;
}
.thumbnail img {
padding-top: 0;
max-height: 50%;
max-width: 50%;
/* padding-bottom: 25%; */
}
.caption {
/* position: absolute; */
/* bottom: 0; */
max-width: 50%;
margin: 0 auto;
}
<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/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<section id="services" class="text-center center-block">
<div class="container">
<div class="row">
<!-- Block -->
<div class="col-xs-12 col-sm-6 col-lg-4">
<div class="thumbnail grey mb-30">
<img src="http://placehold.it/300x300" width="156" height="200" alt="" />
<div class="caption">
<p class="bold">Attractive commissions for business introductions, paid promptly.</p>
</div>
</div>
</div>
</div>
</div>
</section>

How do I align images to the bottom of a nested div (in bootstrap)?

I want to align different size images to the bottom of a div but the images are also in their own divs so the other answers don't work.
I have the following HTML:
<div class="row footer-links">
<section>
<div class="col-md-4">
<p>
Proudly presented and sponsored by
</p>
</div>
<div class="col-md-8 col-xs-12 logo-links">
<div class="row logo-bottom">
<div class="col-md-2 col-xs-12 logo-border col-md-offset-1">
<img id="rasv" class="center-block" src="img/rasv.png" alt="RASV logo">
</div>
<div class="col-md-2 col-xs-12 logo-border">
<img class="center-block" src="img/victoria-farmers.png" alt="Victoria Farmers logo">
</div>
<div class="col-md-2 col-xs-12 logo-border">
<img class="center-block" src="img/anz.png" alt="ANZ logo">
</div>
<div class="col-md-2 col-xs-12 logo-border">
<img class="center-block" src="img/pwc.png" alt="PWC logo">
</div>
<div class="col-md-2 col-xs-12 logo-border">
<img class="center-block" src="img/vac.png" alt="VAC logo">
</div>
</div>
</div>
</section>
</div>
I used the following CSS:
.logo-border {
border-right: 1px solid #d1d3d4;
height: 54px;
vertical-align: bottom;
display: table-cell;
}
Here is a Code Pen for more information.
You were really close.
The reason it wasn't working was because the columns are floated. Due to this, the elements weren't behaving like a table-cell, therefore rendering vertical-align: bottom useless.
You could simply add float: none and it will work as desired.
Updated Example
.logo-bottom .logo-border {
border-right: 1px solid #d1d3d4;
height: 54px;
vertical-align: bottom;
display: table-cell;
float: none;
}
As a side note, I increased the specificity of the selector .logo-border to .logo-bottom .logo-border so that float: left was overridden.

bootstrap how to make two div in one line

I am trying to write css code according to this image:
However, I don't know how to make two divs in one line, and hard to write code to make them exactly the same, tried many times. Could someone help me on that?
Here is my code:
<div class="media-card">
<div class="row">
<div class="col-sm-4 col-md-4">
<img class="img-responsive" src="{{ asset('images/twitter-icon-lg.png') }}">
</div>
<div class="col-sm-8 col-md-8">
<div class="media">
<a class="pull-left" href="#">
<img class="media-photo" src="{{ asset('images/header.png') }}" alt="...">
</a>
<div class="media-body">
<h4 class="media-heading">Matrix User</h4>
<p><span class="">#MatrixUser</span></p>
</div>
</div>
<div><span class="">2k followers</span></div>
</div>
</div>
<div>
<p>Approval required to publish</p>
<button>Select</button>
</div>
</div>
Here is the css part:
.block-inline {
display: inline-block;
}
.media-size {
height: 120px;
width: 90px;
border: 1px solid #CCCCCC;
}
.media-photo {
width: 45px;
}
Please try below code and keep in mind media class is already in bootstrap so always use other class:
HTML
<div class="media-card">
<div class="row2">
<div class="col-sm-4 col-md-4">
<img class="img-responsive" src="{{ asset('images/twitter-icon-lg.png') }}">
</div>
<div class="col-sm-8 col-md-8 media-right">
<a class="pull-left" href="#">
<img class="media-photo" src="{{ asset('images/header.png') }}" alt="...">
</a>
<div class="media-body">
<h4 class="media-heading">Matrix User</h4>
<p><span class="">#MatrixUser</span></p>
</div>
<span class="">2k followers</span>
</div>
</div>
<p>Approval required to publish</p>
<button>Select</button>
</div>
CSS
.row2{
overflow:hidden;
}
.media-card{
width:630px;
background:#F7F7F7;
}
.media-card div{
border:1px solid #ccc;
}
.media-right{
padding-left:0px;
padding-right:0px;
}
.block-inline {
display: inline-block;
}
.media-size {
height: 120px;
width: 90px;
border: 1px solid #CCCCCC;
}
.media-photo {
width: 45px;
}