A guide to resizing images to fit the page in React using Bootstrap

Currently, I am utilizing a function to iterate over each item in the props array and generate an image tag. My goal is to have every set of 3 images enclosed within a row div using Bootstrap to ensure proper page layout. However, I am struggling to implement this feature. Any assistance or guidance on how to achieve this would be greatly appreciated. Below is the code snippet:


        import React, { Component } from 'react';
        import "./Skills.css";

        export default class Skills extends Component {
            static defaultProps = {
                images: [
                    "https://upload.wikimedia.org/wikipedia/commons/thumb/6/61/HTML5_logo_and_wordmark.svg/1200px-HTML5_logo_and_wordmark.svg.png",
                    "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d5/CSS3_logo_and_wordmark.svg/1200px-CSS3_logo_and_wordmark.svg.png",
                    "https://upload.wikimedia.org/wikipedia/commons/6/6a/JavaScript-logo.png",
                    "https://p7.hiclipart.com/preview/306/37/167/node-js-javascript-web-application-express-js-computer-software-others.jpg",
                    "https://bs-uploads.toptal.io/blackfish-uploads/skill_page/content/logo_file/logo/5982/express_js-161052138fa79136c0474521906b55e2.png",
                    "https://webassets.mongodb.com/_com_assets/cms/mongodb_logo1-76twgcu2dm.png",
                    "https://www.pngfind.com/pngs/m/430-4309307_react-js-transparent-logo-hd-png-download.png",
                    "https://botw-pd.s3.amazonaws.com/styles/logo-thumbnail/s3/012015/bootstrap.png?itok=GTbtFeUj",
                    "https://sass-lang.com/assets/img/styleguide/color-1c4aab2b.png"
                ]
            }
            
            photo() {
                return (
                    <div >
                        {this.props.images.map(image => (
                            <div className="col-md-4">
                                <img className="photo" src={image} />
                            </div>
                        ))}
                    </div>
                );
            }

            render() {
                return (
                    <div id="skills-background" className="mt-5">
                        <div id="skills-heading" className="text-center">Skills I've Learned:</div>
                        <div className="container">
                            <div className="row">
                                {this.photo()}
                            </div>
                        </div>
                    </div>
                )
            }
        }
    

CodeSandbox

Answer №1

After some investigation, it seems that I have identified the issue,

<div>  <-----Upon closer inspection, this div appears to be causing the problem
    {this.props.images.map(image => (
        <div className="col-md-4">
            <img className="photo" src={image} />
        </div>
    ))}
</div>

It looks like you have enclosed your col-md-4 within a div, and since div has a display: block style, each image is displayed on a separate row. To resolve this, simply replace div with Fragments,

<>  <-----Use Fragments instead
    {this.props.images.map(image => (
        <div className="col-md-4">
            <img className="photo" src={image} />
        </div>
    ))}
</>

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

I am looking to enhance my CSS menu by incorporating a sub menu feature

I am having trouble getting my submenu to slide to the right horizontally. I have tried various CSS menus, but they are causing issues with my webpage. Here is the HTML code for the menu: <li class="widget"> <h2>Categories</h2> & ...

Using Swig template to evaluate a condition

I'm trying to achieve something similar using swig-template. var remId = $(this).attr('remId'); if (remId) { var end = remId.search('_'); var underscore = remId.slice(end, end + 1); var Id = remId.slice(end + 1, remId ...

Stop MatDialog instance from destroying

In my application, I have a button that triggers the opening of a component in MatDialog. This component makes API calls and is destroyed when the MatDialog is closed. However, each time I open the MatDialog for the second time by clicking the button agai ...

Creating a fresh discord.js v11.3 channel

I've been working on a ticket bot, but I'm encountering issues with my !new command. Can someone please assist me with this problem? I've been referring to Discord's documentation for guidance. Below is the code snippet I'm using: ...

The $http service factory in Angular is causing a duplication of calls

After creating an angular factory that utilizes the $http service, I encountered a problem where the HTTP request is being made twice when checking the network tab in the browser. Factory: app.factory('myService', function ($http, $q) { var de ...

What is the best way to personalize the Window.Confirm() dialog in JavaScript?

var val= confirm("Are you sure to cancel?"); The code snippet above will display a popup with two choices - Ok and Cancel, with Ok being the default choice. Is there a way to make Cancel the default choice instead and switch the positions of the ...

Combining photos seamlessly and bringing them to life through animation upon window loading

My main goal is to seamlessly fit the images together, but I'm struggling to achieve this. I tried using masonry, but unfortunately it didn't work for me. All I want is to tightly pack the divs together. For instance, in my fiddle example, I woul ...

Please follow the format of "M d, yy" when entering the date

I need to change the format of newDate from Tue Dec 24 2013 00:00:00 GMT+0530 to Dec 24, 2013 var dateString = 'Dec 17, 2013'; // date string var actualDate = new Date(dateString); // convert to actual date var newDate = new Date(actualDate.getF ...

What could be causing cancelAnimationFrame to fail?

Take a look at this fiddle - http://jsfiddle.net/rnqLfz14/28/ [ The code provided isn't my own - ] //.... function stop() { running = false; started = false; cancelAnimationFrame(frameID); } //... function mainLoop(timestamp) { / ...

How can I position an element to the bottom right using CSS?

Is there a way to position this element to the bottom right corner? HTML <div class="info player"> <div id="job" style="display:none;"><span>Jobname</span></div> <div i ...

Integrating a real-time chat feature on a website

Considering adding a live chat support feature to my website specifically for new users seeking information about my services. I've been contemplating the most effective way to incorporate this solution without relying on third-party options. My idea ...

Div element obstructing the ability to view markers

Issue with a positioned DIV over Google Maps: The DIV is causing accessibility problems for the map, taking up the entire width when it should stop at the green square borders. Interaction with the map is limited to the very bottom after the green square. ...

What is the method for adjusting the background color of the Material-UI AppBar component?

I am in the process of developing an application utilizing Material-UI components and have customized the color scheme in the theme as shown below (in src/index.js): const theme = createMuiTheme({ palette: { pale: { main: '#FCF4D9', ...

Why is it possible for the EXPRESS+EJS template to access CONFIG without explicitly passing it when rendering?

Currently exploring my knowledge of node.js alongside express and the ejs template. As I delved into some code, I stumbled upon the fact that they were able to invoke config in the template without explicitly passing it as a variable during rendering. You ...

Reactjs button only responds on the second click instead of the first tap

Currently, I am working on a Reactjs/nextjs project and have a video with audio button on my page. There are two things that I want to achieve: 1) I would like the button to have the "bi bi-volume-mute" class by default instead of "bi bi-volume-down". 2) W ...

The CSS code for ::before is not functioning properly

Trying to enhance the style in Ionic2, I have a message box: https://i.sstatic.net/PCRtA.png I am attempting to integrate this image into it: https://i.sstatic.net/PSQID.png To create a seamless look with the message box. Facing an issue where the ima ...

Effectively monitoring coordinates on both the client and server sides

I'm currently in the process of developing a multiplayer game using websockets, node, and JavaScript. I need advice on the most effective approach to update client information and manage their coordinates on the server. The method I am using at the mo ...

Adding a fresh element to an object array in TypeScript

How can we add a specific value to an array of objects using TypeScript? I am looking to insert the value 1993 into each "annualRentCurrent" property in the sample object. Any suggestions on how to achieve this in TypeScript or Angular? Thank you! #Data ...

Defer the rendering of Vue.js pages until the data request is completed

I am currently working on a page that retrieves data from the server using axios. My goal is to wait for the axios request to complete before rendering the page content. The reason behind this approach is that I already have a prerendered version of the ...

Moogonse request for modification

json:{ data:{ id:"123"} , res:{ message:false, "resId":"afdsfd" } } I need to make changes to the res field in the JSON above, but I'm having trouble doing it using mongoose in my NodeJS app. Currently, I am attempting t ...