How can I add 0-5 images to a column without causing any distortion in the row?

I'm having trouble adding a series of images to rows in my Bootstrap 4 project. The source assets are large by default and I'm struggling with scaling them properly without affecting other columns. Here's a visual representation of what I currently have and what I aim to achieve:

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

I'm attempting to loop through my object attributes and insert an image tag in a td element whenever a certain attribute matches a specific string. Below is a snippet of my code and how it currently reflects on the page:

#erb file
<tbody id="hits">
  <% @objects.each do |obj| %>
    <tr>
      <td><%= link_to obj.title, obj_path(obj) %></td>
      <% if obj.packages.any? %>
        <% obj.packages.each do |p| %>
          <td>
              <span><%= image_tag "img1.jpg", :class => "imgrow"  if p.someattribute === "attr1"%></span>
              <span><%= image_tag "img2jpg", :class => "imgrow"  if p.someattribute === "attr2"%></span>
              <span><%= image_tag "img3jpg", :class => "imgrow"  if p.someattribute === "attr3"%></span>
              <span><%= image_tag "img4jpg", :class => "imgrow"  if p.someattribute === "attr4"%></span>
              <span><%= image_tag "img5jpg", :class => "imgrow"  if p.someattribute === "attr5"%></span>
          </td>
        <% end %>
      <% end %>
      <td><%= obj.capacity %></td>
      <td><%= obj.started_at.strftime('%A, %B %e, %Y at %l:%M %p') if obj.started_at? %></td>
    </tr>
  <% end %>
  <tr><td colspan="3" align="center"><%= link_to "Load More", objects_path, class: "load-more" %></td></tr>
</tbody>

Below is a snippet from my CSS file that styles the images:

#CSS
.imgrow {
  display:block; width:100%; height:auto;
  border: 1px solid red;
}

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

When implementing this code, the images scale down but not consistently as seen by the border colors. I'm looking for guidance on how to improve the scaling and achieve my desired layout. Any advice on what I may be doing wrong would be greatly appreciated.

Answer №1

Perhaps the varying images are adjusting their size based on the width of the container. If the container has a 100% width, then the span inside will match the width of the image inside, whether it's a 100px x 100px glass or a 100px x 140px dollar.

Could this be the reason for their different appearances?

This could be due to the CSS you are using:

.imgrow {
  display:block; width:100%; height:auto;
  border: 1px solid red;
}

When uploading images with carrierwave, you can create different versions using the imagemagick gem to scale images properly based on your specified width and height settings.

https://github.com/carrierwaveuploader/carrierwave#adding-versions

https://github.com/rmagick/rmagick

Answer №2

I managed to achieve my desired outcome with some effort.

.image-container {
  display: inline-block;
  margin: 0;
  height: 20%;
  width: 20%;
}

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

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

When you click on an anchor tag, the divs do not automatically move to the top of the page

Encountering an issue with a rather straightforward website. It consists of a vertical scroll with a left side navigation. Whenever I click on a menu item, it fails to bring the corresponding section to the top of the page. I've experimented with a fe ...

Flexbox alignment issue: Text is not vertically centered

I'm facing an issue with centering my content vertically. Upon inspecting the divs, I noticed some empty space below them that seems to be causing the problem. When I tried adding <line-height: 3> in the dev tool styles, it seemed to center prop ...

Joomla CSS styling malfunctioning

I've been exploring the creation of an in line menu using Joomla 1.6 and CSS. The issue arises when Joomla removes <span class="dmenu"> from the document before saving, despite having all cleanup options turned off. This led me to try a couple ...

The transparency feature using rgba is not supported in the Chrome browser for Android

Have you noticed the transparency effect in certain divs using the rgba CSS property? Strangely, Chrome on my ASUS tablet and Samsung S3 mini Galaxy smartphone does not seem to support this feature. Surprisingly, Internet Explorer does! Any insights on w ...

Condense everything when displaying one at a time (various divs)

I found the solution at https://getbootstrap.com/docs/4.2/components/collapse/ My query is related to collapsing multiple elements and showing only one when divided into different divs. While it works within the same div, dividing content into separate di ...

Responsive design for Galaxy S7 devices is optimized through the use of media

I am encountering an issue with media queries on two different websites hosted on the same server, both being accessed using a Galaxy S7 device. @media only screen and (min-width:501px) and (max-width: 999px) { } @media only screen and (max-width: 500p ...

Is it important to position elements based solely on the parent container?

My frustration with element positioning persists: <div id="container"> <div id="div1"></div> <div id="div2"></div> <div id="div3"></div> </div> #div1 { right:0; // I want its right border to be 0px from th ...

Changing the properties of the admin bar when it is hovered over in

After successfully styling a button on the admin bar, I noticed a few imperfections in the implementation. The button in question is situated on the admin bar and is labeled "maintenance". Upon clicking the button, jQuery triggers the addition of the clas ...

An issue with jQuery and LESS causing stylesheets to update only once

Struggling with updating a custom CSS href - everything works perfectly the first time, but subsequent updates do not reflect any changes on the page. Even though I can see the href updating in Chrome debugger and there are no errors being thrown by LESS, ...

Adding -moz & -o prefixes to code that only has -webkit tags can be done by manually duplicating each line of

Imagine having a webpage located at this link: After saving the page and running the HTML file on my localhost, everything seems to work smoothly in Chrome due to the presence of -webkit prefixes in the CSS. Now the question arises - how can I ensure that ...

How to position an absolute element beneath a fixed element

My website is experiencing a problem where the fixed header is overlapping an absolute paragraph on this page. Does anyone know how to resolve this issue? ...

Manipulate only the elements inside the designated container

My CSS/bootstrap file is quite extensive and the styles are affecting more than just the elements I intended to target. While I want it to have a broad impact, the CSS changes are impacting the entire page. Renaming every element to [name].slider is not ...

Display the elements of a div at a reduced size of 25% from its original dimensions

I'm currently developing a JavaScript-based iOS simulator that allows users to view their created content on an iPhone and iPad. This involves using AJAX to load the content/page into the simulator, but one issue is that the simulator isn't life- ...

Increase the height and width of the inner divs to match the outer div while reducing the number of inner divs

Within my HTML structure, I have three vertical divs that each contain multiple inner div elements. I am looking to achieve a responsive layout where the inner divs wrap into either a 2-column or 1-column grid based on the browser's height and width. ...

Guide on adding space between rows in a table using HTML and Bootstrap 5

In the current table containing my content, it appears like this: https://i.sstatic.net/Mm7qT.png. I wish to add space between each row to create distinct separation and achieve a look similar to this: https://i.sstatic.net/ARgR1.png I experimented with ...

choose the <li> element with no <a> tag

Hello there, I am looking for a way to keep the padding consistent in <li> elements, but have it applied to the <a> tag instead when it's a link (to create a larger selection area). li a { padding: 1rem; } li:not(a) { padding: 1rem ...

tips for concealing the shadow of a draggable div during the dragging process

I am facing an issue with a draggable div. When I drag the div, the shadow also moves along with it. I want to find a way to hide this shadow while dragging. <div draggable="true" (dragstart)="mousedown($event)" (drag)="dra ...

What is the best method for creating a vertical line separator with a hover effect in CSS?

Facing an issue with creating a vertical line separator in the navigation menu. While trying to add a vertical line separator to my navigation, I noticed that it does not get covered by the hover effect when hovering over the menu items. Please refer to t ...

"Exploring the world of remote_form_tag in Rails with jrails

After transitioning to jQuery with jRails for my application, most of my previous RJS code is working perfectly. However, I am facing an issue with the :loading => callback when using the remote_form_tag. <% form_remote_tag :url => '/hostels ...