Center images in a <section> - html

I have a <section> tag in which there are 3 images. How can I center them for fullscreens?
The size of my screen is 22.9 ".
here is the code:
<section class="gallery">
<div class="container-fluid">
<div class="row">
<div class="fw mix-container home-gallery">
<div class="mix landscape portrait">
<div class="item-img">
<img src="images/parfum-aux-agrumes-002.jpg""/>
</div>
</div>
<div class="mix landscape portrait">
<div class="item-img">
<img src="images/parfum-aux-agrumes-003.jpg""/>
</div>
</div>
<div class="mix landscape portrait">
<div class="item-img">
<img src="images/parfum-aux-agrumes-004.jpg""/>
</div>
</div>
</div>
</div>
</div>
Thank you for your answers
Best regards.

I have included a code snippet below that will run.
Essentially you make the images inline-block so they sit next to each other.
Then you can set the images parent container to be left 50%, and offset it with transform:translate();
You can change the width of the images as needed but the same logic should still apply.
.mix {
width: 200px;
height: 100px;
border: black solid 1px;
display: inline-block;
}
.mix-container {
position: relative;
display: inline-block;
left: 50%;
transform: translate(-50%, 0);
}
<section class="gallery">
<div class="container-fluid">
<div class="row">
<div class="fw mix-container home-gallery">
<div class="mix landscape portrait">
<div class="item-img">
<img src="images/parfum-aux-agrumes-002.jpg"/>
</div>
</div>
<div class="mix landscape portrait">
<div class="item-img">
<img src="images/parfum-aux-agrumes-003.jpg"/>
</div>
</div>
<div class="mix landscape portrait">
<div class="item-img">
<img src="images/parfum-aux-agrumes-004.jpg"/>
</div>
</div>
</div>
</div>
</div>
</section>

Related

Center Text on multiple images

I need to add centre text on multiple images of different sizes within their own tags in a container div.
This is how my HTML and CSS is setup
<section>
<div class="row ">
<div class="col ">
<div class="container gallery">
<img class="sports" src="img/block1Sports.jpg">
<h3 class="text1" >Sports</h3>
<img id="wellness" src="img/block2Wellness.jpg">
<h3 class="text1" >wellness</h3>
<img id="expeditions" src="img/block3Expeditions.jpg">
<h3 class="text1" >expeditions</h3>
<img id="games" src="img/block4Games.jpg">
<h3 class="text1" >games</h3>
<img id="culture" src="img/block5Culture.jpg">
<h3 class="text1" >culture</h3>
<img id="beauty" src="img/block6Beauty.jpg">
<h3 class="text1" >beauty</h3>
<img id="travelling" src="img/block7Travelling.jpg">
<h3 class="text1" >travelling</h3>
</div>
</div>
</div>
</section>
All these images have a single text messages which should all be centred, appreciate your help.
Here is a snap example of desired output
Instead of <img>, put your image in a div container using css background-image:url('');. Then use display:flex; (https://css-tricks.com/snippets/css/a-guide-to-flexbox/) on this div to position your text vertically and horizontally centered.
HTML
<section>
<div class="row ">
<div class="col ">
<div class="container gallery">
<div class="imageWithCenteredText sports">
<h3 class="text1" >Sports</h3>
</div>
</div>
</div>
...
</div>
</section>
CSS
.imageWithCenteredText {
display:flex;
justify-content: center;
align-items: center;
}
.sports {
background-image: url('img/block1Sports.jpg');
width: 500px; /* PICTURE WIDTH */
height: 500px; /* PICTURE HEIGHT */
}
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<style>
.gallery-item {
position: relative;
}
.gallery-item img {
width: 100%;
}
.gallery-item h3 {
position: absolute;
top: 50%;
left: 50%;
}
</style>
</head>
<body>
<section>
<div class="row ">
<div class="col ">
<div class="container gallery">
<div class="gallery-item">
<img class="sports" src="img/block1Sports.jpg">
<h3 class="text1" >Sports</h3>
</div>
<div class="gallery-item">
<img id="wellness" src="img/block2Wellness.jpg">
<h3 class="text1" >wellness</h3>
</div>
<div class="gallery-item">
<img id="expeditions" src="img/block3Expeditions.jpg">
<h3 class="text1" >expeditions</h3>
</div>
<div class="gallery-item">
<img id="games" src="img/block4Games.jpg">
<h3 class="text1" >games</h3>
</div>
<div class="gallery-item">
<img id="culture" src="img/block5Culture.jpg">
<h3 class="text1" >culture</h3>
</div>
<div class="gallery-item">
<img id="beauty" src="img/block6Beauty.jpg">
<h3 class="text1" >beauty</h3>
</div>
<div class="gallery-item">
<img id="travelling" src="img/block7Travelling.jpg">
<h3 class="text1" >travelling</h3>
</div>
</div>
</div>
</div>
</section>
</body>
</html>

Leading images in flexbox containers

I've been building flexbox containers - actually rows of them - and in some there were leading images. To my surprise something unexpected happens every time I put in one row flexbox containers with leading images and containers of other type (where image doesn't come first).
HTML:
<div class="container">
<img class="image" src="https://res.cloudinary.com/gurugumawaru/image/upload/v1522765892/FCC_Game_Of_Life_resized_ddofex.png"/>
<span>Bam</span>
</div>
<div class="container">
<span>Bom</span>
<span>Bom</span>
</div>
<div class="container">
<span>Bim</span>
<span>Bim</span>
</div>
CSS:
.container {
display: inline-flex;
background-color: tomato;
}
.image {
height: 28px;
}
Please see the following example: https://codepen.io/GuRuGu/pen/KeYGwv
I'd really like to know why it happens as I'm at a loss right now.
Alex's answer is probably the best one, as it's more flexible, but this is a quick alternative: if your images are always a fixed height (in the demo they are 28px) you can make the container elements the same height, and align them with vertical-align (because they are inline elements):
.container {
height: 28px;
vertical-align: bottom;
}
I don't know if it's a solution for you, maybe I misunderstood the issue. But in my opinion, if you want to align all containers, you can wrap all containers with a wrapper and add it a display : flex;. With that configuration, maybe you don't need a display: inline-flex on containers anymore. I let them on the code below, because I don't know what are your limitations.
Here is your code with that modification. I add a .supracontainer class on a div wrapper around your containers. You can control the vertical alignment by using align-items flexbox property on supracontainer class.
.container {
display: inline-flex;
background-color: tomato;
align-items: stretch;
}
.supracontainer{
display: flex;
}
.image {
height: 28px;
}
<h2>Leading images</h2>
<div class="supracontainer">
<div class="container">
<img class="image" src="https://res.cloudinary.com/gurugumawaru/image/upload/v1522765892/FCC_Game_Of_Life_resized_ddofex.png"/>
<span>Bam</span>
</div>
<div class="container">
<img class="image" src="https://res.cloudinary.com/gurugumawaru/image/upload/v1522765892/FCC_Game_Of_Life_resized_ddofex.png"/>
<span>Bom</span>
</div>
<div class="container">
<img class="image" src="https://res.cloudinary.com/gurugumawaru/image/upload/v1522765892/FCC_Game_Of_Life_resized_ddofex.png"/>
<span>Bim</span>
</div>
</div>
<h2>Leading image & empty containers</h2>
<div class="supracontainer">
<div class="container">
<img class="image" src="https://res.cloudinary.com/gurugumawaru/image/upload/v1522765892/FCC_Game_Of_Life_resized_ddofex.png"/>
<span>Bam</span>
</div>
<div class="container">
<span>Bom</span>
<span>Bom</span>
</div>
<div class="container">
<span>Bim</span>
<span>Bim</span>
</div>
</div>
<h2>Trailing image & empty containers</h2>
<div class="supracontainer">
<div class="container">
<span>Bam</span>
</div>
<div class="container">
<span>Bom</span>
</div>
<div class="container">
<span>Bim</span>
<img class="image" src="https://res.cloudinary.com/gurugumawaru/image/upload/v1522765892/FCC_Game_Of_Life_resized_ddofex.png"/>
</div>
</div>
<h2>Leading images & trailing images</h2>
<div class="supracontainer">
<div class="container">
<img class="image" src="https://res.cloudinary.com/gurugumawaru/image/upload/v1522765892/FCC_Game_Of_Life_resized_ddofex.png"/>
<span>Bam</span>
</div>
<div class="container">
<img class="image" src="https://res.cloudinary.com/gurugumawaru/image/upload/v1522765892/FCC_Game_Of_Life_resized_ddofex.png"/>
<span>Bom</span>
</div>
<div class="container">
<span>Bim</span>
<img class="image" src="https://res.cloudinary.com/gurugumawaru/image/upload/v1522765892/FCC_Game_Of_Life_resized_ddofex.png"/>
</div>
<div class="container">
<span>Bim</span>
<img class="image" src="https://res.cloudinary.com/gurugumawaru/image/upload/v1522765892/FCC_Game_Of_Life_resized_ddofex.png"/>
</div>
</div>
You can change item order within a flex element using the order property:
.container {
display: inline-flex;
background-color: tomato;
align-items: stretch;
}
.supracontainer{
display: flex;
}
.image {
height: 28px;
order:0;
}
span{
order:1;
}
<h2>Leading images</h2>
<div class="supracontainer">
<div class="container">
<img class="image" src="https://res.cloudinary.com/gurugumawaru/image/upload/v1522765892/FCC_Game_Of_Life_resized_ddofex.png"/>
<span>Bam</span>
</div>
<div class="container">
<img class="image" src="https://res.cloudinary.com/gurugumawaru/image/upload/v1522765892/FCC_Game_Of_Life_resized_ddofex.png"/>
<span>Bom</span>
</div>
<div class="container">
<img class="image" src="https://res.cloudinary.com/gurugumawaru/image/upload/v1522765892/FCC_Game_Of_Life_resized_ddofex.png"/>
<span>Bim</span>
</div>
</div>
<h2>Leading image & empty containers</h2>
<div class="supracontainer">
<div class="container">
<img class="image" src="https://res.cloudinary.com/gurugumawaru/image/upload/v1522765892/FCC_Game_Of_Life_resized_ddofex.png"/>
<span>Bam</span>
</div>
<div class="container">
<span>Bom</span>
<span>Bom</span>
</div>
<div class="container">
<span>Bim</span>
<span>Bim</span>
</div>
</div>
<h2>Trailing image & empty containers</h2>
<div class="supracontainer">
<div class="container">
<span>Bam</span>
</div>
<div class="container">
<span>Bom</span>
</div>
<div class="container">
<span>Bim</span>
<img class="image" src="https://res.cloudinary.com/gurugumawaru/image/upload/v1522765892/FCC_Game_Of_Life_resized_ddofex.png"/>
</div>
</div>
<h2>Leading images & trailing images</h2>
<div class="supracontainer">
<div class="container">
<img class="image" src="https://res.cloudinary.com/gurugumawaru/image/upload/v1522765892/FCC_Game_Of_Life_resized_ddofex.png"/>
<span>Bam</span>
</div>
<div class="container">
<img class="image" src="https://res.cloudinary.com/gurugumawaru/image/upload/v1522765892/FCC_Game_Of_Life_resized_ddofex.png"/>
<span>Bom</span>
</div>
<div class="container">
<span>Bim</span>
<img class="image" src="https://res.cloudinary.com/gurugumawaru/image/upload/v1522765892/FCC_Game_Of_Life_resized_ddofex.png"/>
</div>
<div class="container">
<span>Bim</span>
<img class="image" src="https://res.cloudinary.com/gurugumawaru/image/upload/v1522765892/FCC_Game_Of_Life_resized_ddofex.png"/>
</div>
</div>

Horizontally aligning elements in a div

I am trying to align three elements in a div in such a way that the image is inline with h1 while the p tag is beneath the h1 tag.
.valign{
position:relative;
top: 50%;
transform: translateY(-50%);
vertical-align: middle;
}
.banner{
position: relative;
height: 100vh;
width:100vw;
background: #eee;
}
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="banner" style="display:flex">
<div class="container">
<div class="valign">
<img src="img/logo.png" style="height: 150px;width: 150px">
<h1>Anirudh Sharma</h1>
<p>This is my portfolio</p>
</div>
</div>
</div>
</div>
</div>
Here is an image for reference:
This is how the elements must be arranged
This is how the elements are looking right now:
This is a screenshot of the webpage
Any help would be appreciated.
Try this
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="banner" style="display:flex">
<div class="container">
<div class="valign">
<div class="float-xs-left float-sm-left float-md-left">
<img src="img/logo.png"></div>
<div class="float-xs-left float-sm-left float-md-left">
<h1>Anirudh Sharma</h1>
<p>This is my portfolio</p></div>
</div>
</div>
</div>
</div>
</div>
the class value for float is based on bootstrap 4
Try this html
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="banner" style="display:flex">
<div class="container">
<div class="valign">
<div style="float:left">
<img src="img/logo.png" style="height: 150px;width: 150px"></div>
<div style="float:left">
<h1>Anirudh Sharma</h1>
<p>This is my portfolio</p></div>
</div>
</div>
</div>
</div>
</div>
Use floats, Bootstrap provides pull-left and pull-right helper classes, so use it on the two parts of your layout to have them side-by-by.
You need to add some margins here and there to make it look good.
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="banner" style="display:flex">
<div class="container">
<div class="valign">
<div class="row">
<div class="pull-left">
<img src="img/logo.png" style="height: 150px;width: 150px">
</div>
<div class="pull-left">
<h1>Anirudh Sharma</h1>
<p>This is my portfolio</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
https://jsfiddle.net/n8o1w3cq/

How to set child div 100% height of the parent (Foundation 6)?

There are three 33% divs next to eachother. The 1st is an empty div, the 2nd a div containing four images, and the 3rd empty div.
How do I responsively keep these 3 blocks the same height? I'm using Foundation 6.
.block {
background: grey;
}
.block, .imgBlock {
height: 200px;
}
.imgBlock .row .column{
padding: 0;
}
<link href="https://cdn.jsdelivr.net/foundation/6.2.0/foundation.min.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.2.3/foundation.min.js"></script>
<div class="row small-up-3">
<div class="column block">
</div>
<div class="column imgBlock">
<div class="row small-up-2">
<div class="column">
<img src="http://placekitten.com/200/150"/>
</div>
<div class="column">
<img src="http://placekitten.com/200/150"/>
</div>
<div class="column">
<img src="http://placekitten.com/200/150"/>
</div>
<div class="column">
<img src="http://placekitten.com/200/150"/>
</div>
</div>
</div>
<div class="column block">
</div>
</div>
Use foundation equalizer js. Here is your code using foundation equalizer:
Code:
$(document).foundation();
.block {
background: grey;
}
.block,
.imgBlock {
height: 200px;
}
.imgBlock .row .column {
padding: 0;
}
<link href="https://cdn.jsdelivr.net/foundation/6.2.0/foundation.min.css" rel="stylesheet" />
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.2.3/foundation.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.2.3/plugins/foundation.equalizer.js"></script>
<div class="row small-up-3" data-equalizer>
<div class="column block" data-equalizer-watch>
</div>
<div class="column imgBlock" data-equalizer-watch>
<div class="row small-up-2">
<div class="column">
<img src="http://placekitten.com/200/150" />
</div>
<div class="column">
<img src="http://placekitten.com/200/150" />
</div>
<div class="column">
<img src="http://placekitten.com/200/150" />
</div>
<div class="column">
<img src="http://placekitten.com/200/150" />
</div>
</div>
</div>
<div class="column block" data-equalizer-watch>
</div>
</div>

how to align right hand side image on top of text on mobile screen

I have two rows on a webpage: on the first row, the image is on left side and text on right side. For the second row, it's vice versa. When I see the page on a mobile device, the image which is on the left goes on top of the text and the image on the right side goes to the bottom of the text.
I want all images to be at the top of the text, whether it is on the right or the left side of the screen.
How should I do that?
HTML code
<section class="pagecontent first_row" id="pagecontent">
<div class="container">
<div class="row">
<div class="col-md-5 text-center animated wow fadeInLeft">
<div class="iphone1">
<img src="images/image1.png" alt="" titl="">
</div>
</div>
<div class="col-md-7 animated wow fadeInRight">
<div class="features_list1">
<h1 class="text-uppercase">Text on Right</h1>
<p>Some text</p>
</div>
</div>
</div>
<hr class="style3">
</div>
</section>
<section class="pagecontent second_row" id="pagecontent">
<div class="container">
<div class="row">
<div class="col-md-7 animated wow fadeInLeft">
<div class="features_list1">
<h1 class="text-uppercase">Text on Left</h1>
<p>Some text</p>
</div>
</div>
<div class="col-md-5 text-center animated wow fadeInRight">
<div class="iphone1">
<img src="images/image2.png" alt="" titl="">
</div>
</div>
</div>
<hr class="style3">
</div>
</section>
Some CSS code
.pagecontent .iphone1{
max-width: 359px;
position: relative;
display: inline-block;
text-align: center;
}
.pagecontent .iphone1 img{
width: 100%;
height: auto;
padding-bottom: 15px;
}
.pagecontent .features_list1 p{
color: #767272;
font-family: "open_regular", Helvetica, Arial, sans-serif;
font-size: 14px;
margin-bottom: 19px;
text-align: justify;
}
Any help would be useful.
col-push-* and col-pull-* can help you
<div class="container">
<div class="row">
<div class="col-md-5 text-center animated wow fadeInRight col-md-push-7">
<div class="iphone1">
<img src="http://placehold.it/150x150" alt="" titl="">
</div>
</div>
<div class="col-md-7 animated wow fadeInLeft col-md-pull-5">
<div class="features_list1">
<h1 class="text-uppercase">Text on Left</h1>
<p>Some text</p>
</div>
</div>
</div>
</div>
You can see that in JSFiddle