Issues regarding aligning content vertically in flexbox

I can't seem to figure out this error, even though it seems simple.

.box {
  display: flex;
  align-items: center;
  justify-content: center;
}
<div class="box">
  <div><img src="https://via.placeholder.com/150x150" alt=""></div>
</div>

Despite following the code from MDN, my image still refuses to be centered.

I found a helpful link on CSS Flexible Box Layout: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Aligning_Items_in_a_Flex_Container

View my page here:

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

Answer №1

Looks like you've missed out on including the CSS:

.box div {
  width: 100px;
  height: 100px;
}

Additionally, consider setting a maximum vertical height as recommended by other users.

height: 100vh;

Answer №2

To address your problem, I suggest increasing the height.

.container {
display: flex;
align-items: center;
justify-content: center;
height:100vh;
}

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

Error loading .OBJ files in Three.js on Azure, but works fine locally

I've been using three.js for webGL to load .obj files, but I'm facing an issue when trying to load .obj files on Windows Azure with Windows Server 2008. I'm using Google Chrome browser and it's showing the error below: GET 404 (Not Fo ...

Unable to apply 100% height to flex child element

When it comes to creating a layout for my website, I have a simple idea in mind. I want the body content to take up at least 100% of the height of the page. This setup works perfectly on desktop screens, but when I switch to a mobile view (which changes th ...

An error occurs in the console stating 'Maximum call stack size exceeded' when trying to add data to the database using JavaScript

I've been struggling with a JavaScript error for the past few days and despite scouring through numerous answers on StackOverFlow, none seem to address my specific issue. My goal is to simply submit a record to the database using a combination of Jav ...

Guide to extracting JSON information in JavaScript that includes a URL as the key

I am having trouble parsing the json file from this URL. My goal is to retrieve the populationTotal, areaTotal, and populationDensity fields from the json data obtained through the URL mentioned above. Below is an excerpt of the json data retrieved from ...

Content extends beyond the navigation bar despite attempts to use word-wrap or word-break

Currently, I am in the process of making my website responsive. This involves ensuring that the navigation bar moves along with the screen when resized. I am working on getting the CSS to wrap to the next line when the browser is resized. * { padding ...

Change the styling of a DIV depending on the character count of a text within another DIV using JQuery

My website contains a series of div elements that display an image, title, and excerpt. Some of the content divs have titles that span two lines, while others have shorter one-line titles. I would like to add a different class to the excerpt div if the tit ...

Using jQuery to resize a div element when it is clicked on

I'm currently working on a project where I have a div that displays the user's status, with its width being based on a percentage ranging from 0 to 100. I'd like to add an animation feature where, upon clicking a button, the div's width ...

What steps can be taken to ensure this CSS is compatible with all web browsers?

On my Google App Engine application, there is a page that shows search results. While the design and font size look good on my laptop (using Chrome), they appear differently on a larger desktop display with IE. The title seems too large and the text benea ...

What is the method for modifying the chosen color using a select option tag instead of a list?

element, I have a Vue component that features images which change color upon clicking a list item associated with that color. <div class="product__machine-info__colors"> <ul> <li v-for="(color, index) in machine.content[0] ...

Is it truly unsemantic to use transparent <hr> elements for responsive vertical spacing?

I've recently adopted a unique technique for managing vertical spacing in front-end design by using transparent <hr> elements as spacers. I understand that this method is not favored among most of the web community, but I believe it has its meri ...

Pressing the enter key to input password

I have searched through various resources for an answer to my problem, but none of them seem to address it in a way that helps. As a beginner in coding, I may need some extra guidance. Currently, I am only able to submit a password by clicking with the mo ...

Unable to resolve Uncaught TypeError: Null property reading not possible

Although I am hesitant to seek help here, solving this seemingly simple error has proved to be quite challenging. No matter what solution I attempt, the error persists. I am currently developing an application on Google Sheets that allows users to track t ...

Here's a solution to prevent the "jump" effect when hiding elements in a navbar

Currently, I am facing an issue with my h5 elements within the navbar when scrolling. I am using Bootstrap 4 and jQuery for this project. The problem arises in my navbar where there are four sets containing an icon, followed by an "h5" and then a "p" elem ...

XSL For Each Loop Failing to Retrieve Values

I have successfully set up this XML document using XSL and CSS to enhance its appearance. However, I am facing issues with the foreach function as it is not working properly. Can anyone provide any insights or suggestions on what might be going wrong? XML ...

swapclass and initial padding

Firstly, I am not fluent in English. Secondly, my issue pertains to "toggleClass". I am a newbie to jQuery and JavaScript, and here is my code snippet: <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.mi ...

Basic single-page application on the web using API and MONGOOSE (problem with identification tags)

Currently, I am in the process of developing a basic AngularJS SPA that connects to Mongoose through an API. The main functionality of this app is to add a new member, display the list of members, and allow for editing of individual members by clicking on ...

Using CSS to create a silhouette of a PNG image

Does anyone have any tips on how to use CSS to turn a PNG image with transparency into a black silhouette? For example, from this: To this: I have multiple images to do this for which is why I prefer not to use Photoshop. ...

Tips on how to transform an <input type="text"> element into a <tr> element using jquery

I am currently working on updating a row using jQuery Ajax. Whenever the Edit button is clicked, it switches the <tr> element to <input type='text'>. I have utilized the .Change method which triggers successfully, but my goal is to r ...

Make SVG Path (Vector Graphic) Simplification easier

Provided Input: <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="800pt" height="600pt" viewBox="0 0 800 600"> <g enable-backgrou ...

What is the best way to connect a React application with a mailerlite.com signup form?

Looking to seamlessly incorporate an email signup form from Mailerlite.com into your website? Wondering how you can integrate this functionality with React? In particular, are you curious about the process of integrating the JavaScript code required for t ...