Tips for centering text in a react flexbox layout

Utilizing react-flexbox-grid in my project has led to the following layout:

const SpicyMenu = (props) => (

    <List>
        {props.foodItems.map(foodItem => <SpicyMenuItem key={foodItem.name} {...foodItem}/>)}
    </List>
);

const SpicyMenuItem = (props) => (
    <Grid fluid>
        <Row center="lg">
            <Col xs={3} sm={3} lg={2}><Avatar src={props.image}/></Col>
            <Col xs={6} sm={6} lg={4}>
                <Row around="lg">
                    <Col>{props.name}</Col>
                </Row>

            </Col>
            <Col xs={3} sm={3} lg={2}>
                <div>{props.price}</div>
            </Col>
        </Row>
    </Grid>
);

export default SpicyMenu;

Upon viewing this setup in a web browser, it's apparent that the text is not properly aligned within the box. Here are some snapshots for reference: https://i.sstatic.net/DsfEG.png https://i.sstatic.net/e9qQn.png

You can access my code on the menu branch by visiting https://github.com/hhimanshu/spicyveggie/tree/menu

What steps should I take to ensure that the text aligns perfectly at the center of the Col element? Your assistance would be greatly appreciated.

Answer №1

If you want to vertically center items, the parent div can utilize the CSS property align-items: center;.

For a visual example, check out this CodePen demo: https://codepen.io/amboy00/pen/GmpoLy

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 reason behind SWR constantly refreshing, even if the key is already stored in the cache?

How can I stop useSWR from always refreshing, even though the key is stored in the cache? https://i.stack.imgur.com/dOvtK.png After printing all cache using ``const { cache } = useSWRConfig();``, I noticed that when a specific call is requested again on t ...

Are tabs best displayed as an overlay?

I've been searching high and low for a tutorial on how to create an overlay with tabs similar to the Google Chrome webstore. If anyone knows of a tutorial or a combination of tutorials that can help me achieve this, please let me know! Link Any guida ...

Ways to align three divs next to each other in an HTML structure?

I am currently working on a website layout that consists of three sections positioned horizontally. I am aiming for the left division to take up 25% of the width, the middle one to occupy 50% of the width, and the right division to fill 25% of the width so ...

How can I modify the border color within a div element?

My journey into web development is just beginning, and I've grasped the basics of Java, JSP, HTML, JS, CSS, and JQ. However, I've hit a roadblock while attempting to change the border color of a div upon mouse hover. Despite my efforts, I haven&a ...

The Axios and TypeScript promise rejection error is displaying an unknown type- cannot identify

Currently, I am encountering an issue where I am unable to utilize a returned error from a promise rejection due to its lack of typability with Typescript. For instance, in the scenario where a signup request fails because the username is already taken, I ...

Design the appearance of page buttons distinct from select buttons

I am currently working on styling my paging buttons differently from the select buttons. However, the selector I am using for the select buttons is also being applied to the paging buttons: .gridView tr td a{} /* The gridView class has been assigned to th ...

I am looking to superimpose one rectangle over another rectangle

I am looking to create something similar using CSS and TypeScript/JavaScript: Could someone please guide me on how to achieve this? My attempt with a flex container looks like this: I am new to front-end development. Can anyone point out what I might be ...

Add to the current values of the REACT Form template property

I am new to working with REACT and I have been exploring whether it is possible to append a REACT Form control property value in order to enhance its functionality. To streamline the validation process, I have created a validation template that leverages ...

Updating the entire value of a Uint8Array using the useState hook in React - a step-by-step guide

const [data, setData] = useState([]) //Assume pdfData is of type Uint8Array with a length of 403970 setData(prevState => [...prevState, pdfData]) I have attempted to update the array using this method, but it is not yielding the desired outcome. Is t ...

An interesting approach to utilizing toggle functionality in JQuery is by incorporating a feature that automatically closes the div when

Currently, I am utilizing JQuery's toggle function to slide a ul li element. However, my desired functionality is for the div to close if someone clicks outside of it (anywhere on the page) while it is in the toggle Down condition. Below, you'll ...

Create and release a React component library with identical folder structure distribution

I have set out to develop a personalized UI library component for my smaller applications. My journey began with learning how to create a react app efficiently, followed by constructing reusable React UI components, and then mastering the process of build ...

I am having trouble retrieving the information stored in an Array of Objects. Specifically, I am having difficulty accessing and iterating through each object using a for

Is there a way to extract data from an API individually and retrieve data from an Array? let {Array}=jsonData fetch("https://apis.ccbp.in/city-bikes?bike_name" + search, options) .then(function(response){ return response.json(); }) .then(funct ...

Ensuring CSS tables fill their parent container or overflow as necessary

How can I create a dynamic table with variable-sized columns that always fills the parent area, regardless of the number of cells? The goal is to allow scrolling if needed, but ensure the table spans the entire parent space even with few cells. I've ...

Tips for Creating Sand Text Effects in CSS (Using Text-Shadow)

I am attempting to create a CSS effect that resembles text written in the sand. Here is an example of what I am trying to achieve: As a newcomer to CSS, I would appreciate any guidance on how to make this effect possible. I have tried using the following ...

Eliminating characteristics and rejuvenating the component

I have divs on my webpage that I want to keep hidden until a specific element is clicked. When trying to hide them, I encountered three options: visibilty: hidden - I didn't like this because the hidden div still took up space in the layout. displa ...

Each modification in props causes the app to increasingly lag

Using Matter js for physics and canvas for rendering 100 items, I am experiencing a slowdown in the app after each change in props. Interestingly though, subsequent downloads with the same props happen instantly as past images and elements are retained, ca ...

Tips for Building a Dual-Column Form Using React Material-UI

Currently, I am in the process of creating a react form using material-ui. The main goal is to design the form with a fixed 2 column layout that does not adjust based on the browser size. The desired structure should always appear like this: |First Name ...

svg contained within a resizable div

I am trying to insert an svg into the .container div that I created using this code snippet. The goal is to make the svg fit perfectly within the dimensions of the .container div, while also scaling proportionally with the page as it is resized: <html& ...

Setting the value of Material UI AutoComplete to zero

I've been banging my head against this bug for a while now and I just can't figure out what's going on. Any help would be greatly appreciated. Thank you. Problem: I'm attempting to use the autocomplete component with Material UI and r ...

Expanding Gridview Width within a Container in ASP.Net: A Step-by-Step Guide

https://i.stack.imgur.com/ZaJE7.jpg After viewing the image above, I am facing a challenge with stretching and fixing a gridview to contain the entire div where it is placed. The issue arises when the gridview adjusts automatically based on the content&ap ...