Tips for positioning images in a Bootstrap div class to center them from the top and bottom sides

Having trouble centering the top padding for all aligned images inside

<div class="photos text-center">
? I've already set a background for the div, but it ends up looking like a border after centralizing the images from all sides. Check out the code at the link below:

http://codepen.io/devendrasingh/pen/dGroGM

<div class="container">
  <div class="heading text-center">
   <h1 class="heading">Amitabh Bachchan</h1>
      <h5 class="heading">Shahenshah of Bollywood</h5>
</div> 
   <div class="photos text-center">
      <img src="http://i2.wp.com/celebritykick.com/wordpress/wp-content/uploads/2015/01/Amitabh-Bachchan-Childhood-pictures-1a.jpg" class="profile-pic image-responsive">
      <img src="http://4.bp.blogspot.com/-M406xYLxmxQ/TiP6cAVINQI/AAAAAAAABI4/WR5cdWO1h0s/s1600/4.jpg" class="profile-pic image-responsive">
      <img src="http://4.bp.blogspot.com/-TPBdiYqY2N4/TiP7S-QyKEI/AAAAAAAABJc/_WWCsdLZfIM/s1600/d.jpg" class="profile-pic image-responsive">
      <img src="https://s-media-cache-ak0.pinimg.com/736x/d0/23/e1/d023e15529ee609aec540e354b0617ef.jpg" class="profile-pic image-responsive">
      <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/9/9e/Amitabh_Bachchan_December_2013.png/220px-Amitabh_Bachchan_December_2013.png" class="profile-pic image-responsive">
<p class="caption">Amitabh Bachchan photos from different ages.</p>
</div>

Note : Images should be responsive.

Answer №1

It's because there is a single p tag containing images.

This particular p tag reads as follows:

<p class="caption">Amitabh Bachchan photos from various stages of life.</p>

To adjust the height, set it to 0, like this:

.caption {
    height: 0;
}

Also, add padding to the image with the following code:

.profile-pic {
    height: 200px;
    padding: 10px 0; //insert here.
}

View the working fiddle example

Answer №2

Here is a method to achieve the desired outcome:

To view an example, visit: http://example.com/code-sample

Code Snippet (HTML):

<div class='wrapper'>
    <a href='#'>
    <img class='resize_fit_center'
      src='http://i.imgur.com/ABCD123.jpg' />
    </a>
</div>

CSS Styles:

.wrapper {
    margin: 10px;
    width: 115px;
    height: 115px;
    line-height: 115px;
    text-align: center;
    border: 1px solid blue;
}
.resize_fit_center {
    max-width:100%;
    max-height:100%;
    vertical-align: middle;
}

Answer №3

.container{
    position: relative;
}

.box{
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Steps to reset default behavior after using event.preventDefault()

I came across a similar question on this post, but the solution provided did not work for my specific needs. So, I decided to share some example code and provide a bit of explanation... $(document).keypress( function (event) { // Pressing Up o ...

Animating the background of a div element using jQuery

I am facing an issue with the code snippet below that I have written. It doesn't seem to be working as expected and I'm curious if anyone knows why. The problem is that I have set a background color on the DIV, but when hovering over it, I want ...

Touch interaction operates differently than mouse movement

Imagine three neighboring divs, div1, div2, and div3. When I click on div1 and then move my mouse to div2, the mousemove event is triggered with div2 as the target. However, on mobile devices, if I tap on div1 (touchstart) and slide my finger to div2, the ...

What are the signs of a syntax error in a jQuery event like the one shown below?

One of my forms has an ID attribute of id ='login-form' $('#login-form').submit(function(evt) { $('#login-button').addClass('disabled').val('Please wait...'); evt.preventDefault(); var postData = ...

What is the process for rendering the material element that has been inserted using innerHTML in TypeScript?

When incorporating material design elements using the innerHTML attribute, it yields a specific result. However, if we create an HTML page with the same material design content without utilizing the innerHTML attribute, the outcome is different. Here is a ...

Checking the validity of subdomain names using JavaScript/jQuery

For users signing up, my form allows them to choose a subdomain for their account. The valid characters allowed in the subdomain are letters, numbers, and dashes. Spaces and most special characters should be filtered out. http://_________.ourapp.com To r ...

Disabling hover effects for mobile devices

I've been searching for a solution to this problem, but nothing seems to work for me. In mobile viewports, I have a dropdown menu with styles applied on :hover, which shouldn't be active due to usability reasons. The structure of the dropdown i ...

HTML elements are positioned in alignment

I'm currently working on a website and I need some assistance in aligning my images properly. Here's what I have tried: https://i.sstatic.net/suIVu.png However, I haven't been able to achieve the desired result with the following code: &l ...

What is the best way to access and retrieve URL parameters within AngularJS?

I'm currently working on a blog project using AngularJS. The main page is connected to an external service that provides an array of all the articles I've written. Each post is displayed with a shortened version on the homepage, along with a "rea ...

Using PHPs nth-child in media queries

There are multiple images on MyPage, typically displayed in rows of 6. However, the number of images per row adjusts based on browser size using media queries. The issue arises with the margin set for the last image in each row, as the nth-child property r ...

Tips on serializing two arrays into JSON format and incorporating them in an AJAX request

I have a task where I need to retrieve all the names and details associated with a specific reference number. To accomplish this, I am using a while loop. However, I am unsure of how to encode these values in JSON format so that I can use them in AJAX for ...

How can you extract the text associated with the chosen value in a dropdown list implemented in JavaScript?

Hello, I've been having difficulty extracting the value from a dropdown list created using the FacetWP plugin. Despite extensive research and numerous attempts using various methods to retrieve the text value from the list, I have not been successful. ...

I am interested in incorporating a vertical scrollbar into a gridview in ASP.NET

I've successfully bound data to a grid view in my ASP.NET application. I've implemented pagination, but instead of that, I'd like to incorporate a scroll bar to prevent lengthy paging. Below is the code for my grid view: <div class="box ...

Setting the background using parameters in ReactJS is a powerful technique for customizing

Can someone assist me with setting a background for a div using react js, where I pass the background URL as a parameter? This is the main functionality. function Main (){ return ( <main className="Main"> <List BGimage={" ...

Navigate directly to a specific slide in jQuery Cycle without using a pager manually

Is there a way to programmatically advance to a specific slide in jQuery cycle instead of relying on pager clicks? Similar to how you can advance using this syntax: $('#slideshow').cycle('next'); I am interested in passing a specific ...

Scrolling issue observed on Safari browser for iPad

For my responsive website built with Bootstrap, I decided to include anchor HTML in my navigation bar. The navigation includes a logo that, when clicked, should scroll the site to the top. This functionality works perfectly on desktop computers, however, w ...

In a React application, adjusting the main container height to 100vh results in the window.scrollY position being set to

I was facing problems with flashing on the Safari/Firefox browsers. By setting the main container height to max-height: 100vh, I managed to resolve the flickering issue. However, I am also looking for a solution to keep track of the window.scrollY positi ...

Is capturing a screenshot through PHP with mp4-upload feasible?

I recently implemented an upload function for videos on my website. The files are uploaded using jQuery and then processed on the server with PHP. On another page, I have all the videos displayed in a small "thumbnail" format. However, these are not tradi ...

Delete class at waypoints

I am currently using waypoints.js to manage a single-page website that includes a highlighted navigation feature. When the viewport reaches the element with the class "content", the corresponding navigation point is given the class "active". The script i ...

What is the method for specifying the HTML file extension within Visual Studio?

I am having issues with my project recognizing the CSS and other files in the HTML files I have created, even though I have double-checked the extension paths. How can I resolve this problem? https://i.stack.imgur.com/85ooE.png https://i.stack.imgur.com/F ...