Best approach to center items horizontally on Bulma - css

I want to have a section that's three fifths columns wide, and that it will be centered.
At first when I only had "section", the content was horizontally centered, but it took the entire width of the screen. So I added a parent div of columns with a column of is-three-fifths. Now I have a section that is three-fifths wide, but not centered, so what is the best approach to do that?
.section{
border: 1px solid;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.css" rel="stylesheet" />
<div class="columns">
<div class="column is-three-fifths">
<section class="section">
<div class="container">
<figure class="image is-128x128">
<img src="https://bulma.io/images/placeholders/256x256.png">
</figure>
</div>
</section>
</div>
</div>

Add margin: auto; on figure tag
.section{
border: 1px solid;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.css" rel="stylesheet" />
<div class="columns">
<div class="column is-three-fifths">
<section class="section">
<div class="container">
<figure class="image is-128x128" style=" margin: auto;">
<img src="https://bulma.io/images/placeholders/256x256.png">
</figure>
</div>
</section>
</div>
</div>

You can add is-centered class to div.columns. https://bulma.io/documentation/columns/options/#centering-columns
.section{
border: 1px solid;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.css" rel="stylesheet" />
<div class="columns is-centered">
<div class="column is-three-fifths">
<section class="section">
<div class="container">
<figure class="image is-128x128">
<img src="https://bulma.io/images/placeholders/256x256.png">
</figure>
</div>
</section>
</div>
</div>

Related

CSS how to align different size images with text inside row?

Need to align four different height (beetween 160-180px) svg images with text under them.
Images should be placed in line at sight and I don't know how to make strict align short text under them in one line like on screenshot.
Thanks!
UPD: Sorry for inconvinient information, thought that this question is quite typical for those who know css good.
Here is my html and css. Also I'm using bootstrap rows.
<div class="did-you-know">
<div class="row items">
<div class="col-lg-3 col-xs-6">
<div class="icon">
<img src="/img/mswa/inline-wa.svg"/>
</div>
<div class="title text-poppins">
<p>We’re from WA</p>
<p>{like you!}</p>
</div>
</div>
<div class="col-lg-3 col-xs-6">
<div class="icon">
<img src="/img/mswa/inline-packaging.svg"/>
</div>
<div class="title text-poppins">
<p>We use minimal packaging</p>
<p>{great for the planet}</p></div>
</div>
<div class="col-lg-3 col-xs-6">
<div class="icon">
<img src="/img/mswa/inline-quality.svg"/>
</div>
<div class="title text-poppins">
<p>We only choose quality</p>
<p>{better for your health}</p></div>
</div>
<div class="col-lg-3 col-xs-6">
<div class="icon">
<img src="/img/mswa/inline-community.svg"/>
</div>
<div class="title text-poppins">
<p>We love giving back</p>
<p>{great for our community}</p></div>
</div>
</div>
</div>
.did-you-know {
padding: 20px;
text-align: center;
}
.did-you-know .items .icon {
padding: 50px;
}
.did-you-know .items .title {
font-size: 20px;
}
here is a solution:
Replace images by your images.
<!DOCTYPE html>
<html>
<head>
<style>
* {
box-sizing: border-box;
}
.column {
float: left;
width: 25%;
padding: 5px;
}
/* Clearfix (clear floats) */
.row::after {
content: "";
clear: both;
display: table;
}
</style>
</head>
<body>
<div class="row">
<div class="column">
<img src="https://freesvg.org/img/cartoonsun.png" alt="Snow" style="width:100%">
<p style='text-align: center;'>test1</p>
</div>
<div class="column">
<img src="https://freesvg.org/img/cartoonsun.png" alt="Forest" style="width:100%">
<p style='text-align: center;'>test2</p>
</div>
<div class="column">
<img src="https://freesvg.org/img/cartoonsun.png" alt="Mountains" style="width:100%">
<p style='text-align: center;'>test3</p>
</div>
<div class="column">
<img src="https://freesvg.org/img/cartoonsun.png" alt="Mountains" style="width:100%">
<p style='text-align: center;'>test3</p>
</div>
</div>
</body>
</html>

moving last row to bottom of container in bootstrap 4

I have a simple footer with contact information that contains of three rows. The first two appear at the top, the last one should be placed on the very bottom of the container.
So what I did was using an absolute positioning:
footer .verybottom {
position: absolute;
bottom: 0px;
background-color: grey;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<footer id="kontakt">
<div class="container">
<div class="row">
<div class="col md-12">
<h2>Contact</h2>
</div>
</div>
<div class="row">
<div class="col-md-6">
Adress
</div>
<div class="col-md-6">
something else
</div>
</div>
<div class="row verybottom">
<div class="col-md-6">
some more Text
</div>
<div class="col-md-6">
some more Text
</div>
</div>
</div>
</footer>
The positioning works fine, but whatever I do - the last row is only a wide as the col above it. can someone help me align the content with the rows above?
You need to put a container inside to get it to work... and then introduce another .row since we want the col-md-XX classes to work
working snippet:
footer .verybottom {
position: absolute;
bottom: 0px;
background-color: grey;
padding-left: -15px;
}
.row {
border: 1px dotted red;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<footer id="kontakt">
<div class="container">
<div class="row">
<div class="col md-12">
<h2>Contact</h2>
</div>
</div>
<div class="row">
<div class="col-md-6">
Adress
</div>
<div class="col-md-6">
something else
</div>
</div>
<div class="row">
<div class="container verybottom">
<div class="row">
<div class="col-md-6">
some more Text
</div>
<div class="col-md-6">
some more Text
</div>
</div>
</div>
</div>
</div>
</footer>

Align text using CSS

How can I align the picture with the text?
Many thanks in advance
<div class="w3-container" style="padding:128px 16px" id="about">
<h1 class="w3-center w3-knallpink"><b>#about</b></h1>
<div class="w3-row">
<div class="w3-container w3-center w3-third">
<img src="/bilder/Spongebob.png" alt="Bikini Bottom" style="width:100%;max-width:360px; margin-left: auto;
margin-right: auto; border-radius: 3px;">
</div>
<div class="w3-container w3-twothird">
<p>TEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXT<p>
TEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXT<p>TEXTTEXTTEXTTEXTTEXTTEXTTEXT<p>
</p>
</div></div> </div>
To achieve expected result, add margin-top:15px , as the paragraph text has margin-top:15px
codepen for reference - https://codepen.io/nagasai/pen/dqLNNo
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<div class="w3-container" style="padding:128px 16px" id="about">
<h1 class="w3-center w3-knallpink"><b>#about</b></h1>
<div class="w3-row">
<div class="w3-container w3-center w3-third">
<img src="https://tse2.mm.bing.net/th?id=OIP.MhyD6cHgUgRSnYMrQ8TomQHaGI&pid=15.1&P=0&w=183&h=153" alt="Bikini Bottom" style="width:100%;max-width:360px; margin-left: auto;
margin-right: auto; border-radius: 3px;margin-top:15px">
</div>
<div class="w3-container w3-twothird">
<p>TEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXT<p>
TEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXTTEXT<p>TEXTTEXTTEXTTEXTTEXTTEXTTEXT<p>
</p>
</div></div> </div>

Thumbnail Class in bootstrap

Problem
So, I am trying to fit 3 images in a row. Every Image has a different dimension.
So, I tried adding the thumbnail class hoping that it would make all images the same size but it only added the border but never changed the image size.
What I want
I want all images the same size.
Code
(The code is for one image since all images have the same code)
<div class="col-lg-4">
<div class="thumbnail">
<img src="https://images.unsplash.com/photo1423034816855245e5820ff8cdpr=1&auto=format&fit=crop&w=1500&h=2000&q=80&cs=tinysrgb&crop="alt="Something in france!">
</div>
</div>
you could do it something like this, apply width: 100%; and height: auto; to img
see fiddle for working demo
img{
max-width: 100%;
border: 1px solid red;
width: 100%;
height: 200px; // adjust it based on your need
}
<div class="row">
<div class="col-md-4 col-sm-4">
<img src="http://placehold.it/500x150" />
</div>
<div class="col-md-4 col-sm-4">
<img src="http://placehold.it/100x50" />
</div>
<div class="col-md-4 col-sm-4">
<img src="http://placehold.it/200x150" />
</div>
</div>
Some images are affected differently with the thumbnail tag. That is because some images have a larger width than the height (ex: 480 x 670).
Example
<html lang="en">
<head>
<title>Image Gallery</title>
<link href="bootstrap.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="Image Gallery.css">
</head>
<body>
<div class="row">
<div class="col-lg-4">
<div class="thumbnail">
<img src="https://images.unsplash.com/photo-1423034816855-245e5820ff8c?dpr=1&auto=format&fit=crop&w=1500&h=2000&q=80&cs=tinysrgb&crop=" alt="Something in france!">
</div>
</div>
<div class="col-lg-4">
<div class="thumbnail">
<img src="https://images.unsplash.com/photo-1441790844170-ec5dc89c7eae?dpr=1&auto=format&fit=crop&w=1500&h=1000&q=80&cs=tinysrgb&crop=" alt="A sad monkey">
</div>
</div>
<div class="col-lg-4">
<div class="thumbnail">
<img src="https://images.unsplash.com/photo-1464039397811-476f652a343b?dpr=1&auto=format&fit=crop&w=1500&h=1003&q=80&cs=tinysrgb&crop=" alt="A forest!">
</div>
</div>
</div>
</div>
<script src="bootstrap.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
</body>

images to the center of the div in bootstrap

all the images should be center aligned irrespective to its size.
i have tried with below code, but it doesn't work for me.
any help would be appreciated
.border-class{
border:1px solid #ddd;
padding:5px;
min-height:160px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<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>
<div class="container">
<div class="col-xs-3">
<div class="border-class">
<img src="http://www.w3schools.com/bootstrap/cinqueterre.jpg" class="img-responsive" alt="Cinque Terre"/>
</div>
</div>
<div class="col-xs-3">
<div class="border-class">
<img src="https://cdn2.iconfinder.com/data/icons/hawcons-gesture-stroke/32/icon_27_one_finger_click-128.png" class="img-responsive" alt="Cinque Terre"/>
</div>
</div>
<div class="col-xs-3">
<div class="border-class">
<img src="http://www.w3schools.com/bootstrap/cinqueterre.jpg" class="img-responsive" alt="Cinque Terre"/>
</div>
</div>
<div class="col-xs-3">
<div class="border-class">
<img src="http://www.w3schools.com/images/colorpicker.png" class="img-responsive" alt="Cinque Terre"/>
</div>
</div>
</div>
You can use CSS Flexbox. Just add Flex properties to .border-class
.border-class {
display: flex;
justify-content: center;
align-items: center;
}
See the snippet below:
.border-class{
/* Add these 'flex' properties */
display: flex;
justify-content: center;
align-items: center;
border:1px solid #ddd;
padding:5px;
min-height:160px;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<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>
</head>
<body>
<div class="container">
<div class="col-xs-3">
<div class="border-class">
<img src="http://www.w3schools.com/bootstrap/cinqueterre.jpg" class="img-responsive" alt="Cinque Terre"/>
</div>
</div>
<div class="col-xs-3">
<div class="border-class">
<img src="https://cdn2.iconfinder.com/data/icons/hawcons-gesture-stroke/32/icon_27_one_finger_click-128.png" class="img-responsive" alt="Cinque Terre"/>
</div>
</div>
<div class="col-xs-3">
<div class="border-class">
<img src="http://www.w3schools.com/bootstrap/cinqueterre.jpg" class="img-responsive" alt="Cinque Terre"/>
</div>
</div>
<div class="col-xs-3">
<div class="border-class">
<img src="http://www.w3schools.com/images/colorpicker.png" class="img-responsive" alt="Cinque Terre"/>
</div>
</div>
</div>
</body>
</html>
Hope this helps!
Use the cover property of background-size :
background-image : ...
background-size : cover;
background-position : center;

Resources