Struggling to align elements in the middle both vertically and horizontally with flex in CSS

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

Apologies for the basic question, but I've been struggling with this issue for quite some time. I'm attempting to use flexbox to horizontally center align the elements in div.Homepage, however, I can only manage to get the button aligned horizontally. Additionally, I'm having trouble getting the text TEST to be centered as well. Here is my CSS code:

body {
    font-family: 'Recoleta';
    color: #FFF;
    background: #111;

}

html, body {
    height: 100%;

}

.Homepage{
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
}

.logo-social-image{
    max-width: 20%;
}

Below is the React HTML code:

   return(
            <div className="Homepage">
                <div className="Name-social">
                    {view}
                </div>
                <div className="Pro-button">
                    <OutlinedButtons  isLoading={this.state.isLoading} isLoaded={this.isLoaded} />
                </div>
            </div>
        )

Answer №1

Since a code snippet was not provided, I have created an example demonstrating how to achieve the desired effect: https://jsfiddle.net/L29h8oxs/

Simply include the following CSS properties:

display: flex;
align-items: center;
justify-content: center;

Add these styles to the parent div (most likely .Homepage) and it will automatically center the child element.

Answer №2

To center your content, simply include justify-content: center in the Homepage class.

.Homepage {
  /*Retain your existing styles*/
  justify-content: center;
}

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

How about: "Is there a way to show items in a list without using

I have removed the bullet points from an unordered list, but I am having trouble displaying Log with every message. The code I have doesn't seem to be working as expected. I want users to be able to differentiate between messages easily, without seein ...

Queries surrounding the use of useState in React.js function components

I am having trouble accessing state data. Can someone guide me on how to transfer an array object into a data array? -code function TableList() { const [state, setState] = React.useState({ columns: [ { title: '로트번호', field ...

React.js not displaying image

Here's my App.js File I am trying to display an image from the MongoDB database. Click here to view the image stored in MongoDB The images are stored as Binary data in MongoDB How can I display the image on the React page? import React,{useState} fr ...

The words overlaid on the image spill out beyond its edges

I want to create a design where the text flows outside of the image and continues into another container. After some trial and error, I managed to achieve a layout where the text seamlessly extends beyond the image and into a separate section. Ideally, the ...

Preventing the generation of div tags with Thymeleaf's th:each functionality

<div class="question" th:each="question : ${questions}"> <h2 id="question" class="description" th:text="${question.description}">Question goes here</h2> <div id= ...

What could be causing the Navbar Collapse feature to malfunction in my Bootstrap setup?

Hey there, I'm facing an issue with the Bootstrap navbar collapse button not working. I've tried everything, followed all the steps in a tutorial, but still can't get it to function properly without altering the Signup and Login buttons. Ca ...

Whenever I trim down the images, the captions somehow get lost in the thumbnail

My issue arises when cropping photos, as the captions end up being hidden within the thumbnail images. How can I ensure that the captions are visible and also make all images the same height? I am striving to achieve a layout similar to this: ![][2] ...

Discover the power of catching Custom DOM Events in Angular

When working with an Angular library, I encountered a situation where a component within the library dispatches CustomEvents using code like the following: const domEvent = new CustomEvent('unselect', { bubbles: true }); this.elementRef.nati ...

Add a new string to a class within a Vue.js component

Hey there, currently working on a Vue component where I am iterating through a list of countries. Here's how it looks: <div v-for="i in countries" :key="i.id"> {{i.name}} <span class="flag-icon-gr"></span> I want to dynamically ...

Height that is determined in real-time

I am attempting to adjust the height of a div based on the size of the screen. Within this div, there is a calendar that contains multiple lines of content, which can be displayed or hidden based on user preference. The height of the calendar is not fixed, ...

What is the procedure for adjusting the padding in Material UI's datepicker?

Click here to access the codesandbox link function InlineDatePickerDemo(props) { const [selectedDate, handleDateChange] = useState(new Date()); return ( <Fragment> <MuiPickersUtilsProvider utils={DateFnsUtils}> <Keyboa ...

In IE11, the property of table.rows.length is not functioning as expected

In my HTML page, I have the following script: var table = document.getElementById(tableID); var rowCount = table.rows.length; While this script works fine in IE8, in IE11 it does not return the exact row count. Instead, it only returns "0" when the actua ...

Utilizing Vue's v-for directive to manipulate data through custom looping

When I loop through my data using v-for, I find myself unsure of how to display the data with a custom looping method, such as using modulus. I aim to display the data in groups of three items, assigning a different class to every 3 items. The desired st ...

Tips on concealing the divs following the second click and a page refresh

Bootstrap 4 js collapse is working fine, but I am facing an issue. When I click to show a hidden div and then reload the page, clicking again reveals the previously hidden div when it should be hidden. Any suggestions for addressing this problem? ...

Certain rows appear to be missing even though they are present in both the webpage and its corresponding source code

I am facing a CSS issue that I am unable to resolve. I have 20 results that should be displayed on my website, but only 14 of them are appearing. The other ones are visible in the source code when inspected. When I move the position of the menu up or down, ...

Is it considered acceptable to conduct an https redirect from an http connection?

My web application utilizes node.js, the socket.io library, and a postgresql database while being hosted on heroku. When accessing the site with "http://X", I encounter an error related to the socket.io library that is not present when using "https://X". T ...

Symfony 2 can be configured to add a "data-*" attribute to each radio input field in a form entity

Within my form, I have a field named "membership" that displays radio buttons. Here is the code snippet: ->add( 'membership', 'entity', array( 'class' => 'Comit ...

Forcing the display of invalid-feedback in Bootstrap 4 is crucial

Suppose I am working with HTML code that looks like this: ... <div class="form-group"> <div class="form-check"> <input class="form-check-input" type="checkbox" id="invalidCheck"> <label class="form-check-label" for ...

Using jQuery to change the `class` of the parent `div` based on the length of a `p`

I am attempting to adjust the height of a parent div based on the length of text in its child p.descr. This is achieved by adding a specific class that corresponds to different height values in CSS. Below is the jQuery code snippet: $(document).ready(fu ...

Getting the currently selected value from a dropdown in react-bootstrap-typeahead

I've been experimenting with using react-bootstrap-typeahead in my application. I found a helpful example on this website . This is the component code snippet: <Typeahead labelKey={(option) => `${option.firstName} ${option.lastName}`} options ...