Place text directly below the images for proper alignment

In my current rails app, I am working on the contributors page. Each member's name should be displayed centered beneath their respective images. Any assistance with this would be greatly appreciated.

Below is a snippet from my member.html.erb file

<h1>CONTRIBUTORS</h1>

 <div id="contributors_image">
  <%= image_tag "one.jpg" %>
  <%= image_tag "two.jpg" %>
  <%= image_tag "three.jpg" %>
  <%= image_tag "four.jpg" %> 
  <%= image_tag "five.jpg" %> 
  <%= image_tag "six.jpg" %> 
  <%= image_tag "seven.jpg" %> 
 </div>

Here is a portion of my application.css.scss file:

#contributors_image {
        float: centre;
        margin-left: 3em;
        img {
            width: 200px;
            height: 200px;
            border-radius: 8.35em;
        }
    }

Answer №1

There is no float: center; in the code provided. Instead, consider the following approach:

  • Set the images to have display: inline-block;.
  • Add text-align: center; to the container.
  • For consistent style, use Sentence case and apply text-transform: uppercase;.

The updated code should appear as follows:

h1 {
  text-transform: uppercase;
}
#contributors_image {
  margin-left: 3em;
  text-align: center;
}
#contributors_image img {
  width: 200px;
  height: 200px;
  border-radius: 100%;
  display: inline-block;
}
<h1>Contributors</h1>

<div id="contributors_image">
  <img src="//placehold.it/100?text=Image+1" alt="Image 1" />
  <img src="//placehold.it/100?text=Image+2" alt="Image 2" />
  <img src="//placehold.it/100?text=Image+3" alt="Image 3" />
  <img src="//placehold.it/100?text=Image+4" alt="Image 4" />
  <img src="//placehold.it/100?text=Image+5" alt="Image 5" />
  <img src="//placehold.it/100?text=Image+6" alt="Image 6" />
  <img src="//placehold.it/100?text=Image+7" alt="Image 7" />
</div>

Preview

https://i.sstatic.net/ppzg1.png

The code now displays as expected with the specified styling.


If you wish to include names in your code, encapsulate it within a <figure> and <figcaption> like so:

h1 {
  text-transform: uppercase;
}
#contributors_image {
  margin-left: 3em;
  text-align: center;
}
#contributors_image figure {
  width: 200px;
  height: 200px;
  display: inline-block;
}
#contributors_image img {
  display: block;
  border-radius: 100%;
  max-width: 100%;
}
<h1>Contributors</h1>

<div id="contributors_image">
  <figure>
    <img src="//placehold.it/200?text=Image+1" alt="Image 1" />
    <figcaption>Contributor 1</figcaption>
  </figure>
  <!-- Include additional contributor figures here -->
</div>

Preview

https://i.sstatic.net/MlBnU.png

The updated code now appropriately showcases the images along with their respective contributors' names.

Answer №2

The property float:centre is not a valid CSS property. To center the image and label containing the name, you need to encapsulate them in their own div or container and give that container a text-align: center;

.img-container{
    display: inline-block;
    text-align:center;
}

img{
    border-radius:100%;
    width:200px;
    float:left;
    margin: 0 20px;
}

After compiling, your HTML would look like this:

<h1>CONTRIBUTORS</h1>

<div id="contributors_image">
    <div class="img-container">
        <img src="http://fineartamerica.com/images/artworkgallerylogos/yosemite-national-park-science-source-images-1404150568.jpg" />
        <h4>John Doe</h4>
    </div>  
    <div class="img-container">
        <img src="http://fineartamerica.com/images/artworkgallerylogos/yosemite-national-park-science-source-images-1404150568.jpg" />
        <h4>John Doe</h4>
    </div>  
    <div class="img-container">
        <img src="http://fineartamerica.com/images/artworkgallerylogos/yosemite-national-park-science-source-images-1404150568.jpg" />
        <h4>John Doe</h4>
    </div>  
    <div class="img-container">
        <img src="http://fineartamerica.com/images/artworkgallerylogos/yosemite-national-park-science-source-images-1404150568.jpg" />
        <h4>John Doe</h4>
    </div>  
    <div class="img-container">
        <img src="http://fineartamerica.com/images/artworkgallerylogos/yosemite-national-park-science-source-images-1404150568.jpg" />
        <h4>John Doe</h4>
    </div>  
    <div class="img-container">
        <img src="http://fineartamerica.com/images/artworkgallerylogos/yosemite-national-park-science-source-images-1404150568.jpg" />
        <h4>John Doe</h4>
    </div>  
</div>

For guidance, refer to the demo, but make sure to modify it according to your specific markup for compilation from your code.

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

What is the best way to display a div based on a keyword match?

If the keyword search results in a match, I can display the corresponding input text and its related category div. Now, I am attempting to also search through category names. If the searched keyword matches a category name, that specific div should be visi ...

Utilize JavaScript to apply the CSS -moz-transition

Creating a web application and using CSS3 to transform a div, but encountering a challenge with Firefox. Able to make Chrome, Opera, and IE work properly, except for Firefox. Here's how I'm setting up the working browsers: obj.style.WebkitTrans ...

Tips for avoiding a 500 GET error due to an empty request during page loading

I recently encountered an issue with a form containing a dependent drop-down menu that reloads after form submission to preselect the main choice that was made before submission. The problem arises when the page initially loads without any parameters being ...

Activate the jQuery function multiple times

I am currently working on the menu structure for my website <div class="header"> <ul> <li id="menu__lnk_one"><a href="#">Home</a></li> <li><a href="#">Our Story</a></ ...

using jquery to fill in fields in a table form

I am currently working with a basic html table that initially has two rows, each containing 2 form fields. Users have the ability to add more rows to the table by following this process: $('a#addRow').click(function() { $('#jTable tr:la ...

Creating consistent row spacing between Bootstrap 5 rows that matches the spacing in Bootstrap 4

Is it possible to adjust the site.css file in order to achieve a similar row spacing effect as Bootstrap 5 when working with existing HTML code? ...

Creating a full-screen background with an rgba overlay using CSS

I recently encountered an issue with a fixed, fullscreen background image on my website. I initially applied the background image to the HTML's CSS instead of the body's CSS. To add a black overlay with lowered opacity, I included the following c ...

Moving through divisions that share a common class name using jquery

I am experimenting with a plugin that allows me to attach popups to images. My goal is to enable navigation between all popups using previous and next buttons upon clicking on a popup. Below is the element when it's displayed: <div class="imp-too ...

What is the process to enable mandatory validation after a change in input in Angular 4?

Currently, I am working on a project using Angular 4. One of the tasks I need to achieve is validation. <input [(ngModel)]="someModel" required placeholder="some placeholder"/> The validation triggers immediately, but I want it to only trigger aft ...

Modify the background color of checkboxes without including any text labels

I am looking to customize my checkbox. The common method I usually see for customization is as follows: input[type=checkbox] { display: none; } .my_label { display: inline-block; cursor: pointer; font-size: 13px; margin-right: 15px; ...

How to reference color variables from code behind in ASP and use them in CSS files

I have a total of 3 files dedicated to my Login-Screen: Login.aspx, Login.aspx.cs, and LoginStyle.css Upon the execution of the Page_Load method, I retrieve various data from the current system, including the theme-color represented as a string (e.g., #00 ...

When scrolling, a new page loads seamlessly

Recently, I came across a website that has an interesting feature where new content is loaded automatically while scrolling, seamlessly appending to the existing page. What's more fascinating is that not only does the content change, but the URL also ...

What is the significance of an empty href attribute in the HTML <base> tag?

If my website URL is: http://example.com/path/to/dir/index.html And I decide to proxy this page through: http://proxyserver.com/path/to/dir/index.html. I would like all relative URLs on the page to be resolved by proxyserver.com instead of example.com. Wh ...

Exploring elements in Javascript

I am attempting to retrieve values from various elements when a 'a' element is clicked. Consider the following code: <tr data-id="20"> <div class="row"> <td> <div class="btn-group"> <a data-checked= ...

Fatal error in CodeIgniter occurring while invoking CSS less functions

Whenever I try to execute this function, I encounter the following error message: "Fatal error: Uncaught exception 'Exception' with message 'load error: failed to find test.less' in C:\xampp\htdocs\project\applic ...

Taking out the z-index from the transition code

Is there a way to restructure the code without needing to use z-index for the transition? Without z-index: https://jsfiddle.net/Legcb42d/ .container1 { position: relative; width: 100%; height: 100%; } .container1.slide { height: auto; min-heigh ...

The addition and deletion of classes can sometimes lead to disruptions in the DOM

I've been struggling to phrase this question for a while now. I'm working on a single-page e-commerce site that operates by modifying the HTML in divs and using CSS along with JQuery to show and hide those divs. My problem arises when, occasional ...

Is there a way to retrieve the Location header of a 302 redirection URL using PHP?

Seeking a solution to expand shortened URLs universally. I am aware that popular services like bit.ly, TinyURL, and goo.gl use 302 redirection for forwarding users to new destinations. How can a HEAD request be made in PHP to retrieve the "Location" sectio ...

Determine the variable height of a div containing dynamic content in order to execute a transform

Looking to create a dynamic container that expands when a button/link is clicked? The challenge lies in achieving this expansion effect with a smooth transition. By using the height: auto property, the container can expand to fit its content, but incorpora ...

Angular: The Ultimate Guide to Reloading a Specific Section of HTML (Form/Div/Table)

On my create operation page, I have a form with two fields. When I reload the page using window.reload in code, I can see updates in the form. However, I want to trigger a refresh on the form by clicking a button. I need help writing a function that can r ...