Determine the placement of the body with CSS styling

Here is the code snippet from my website:

body {
  background-image: url('background.jpg');
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
}

.centered {
  /* Center entire body */
  display: flex;
  justify-content: center;
  align-items: center;
  position: static;
}
<!DOCTYPE html>
<html>

<head>
  <title>Training File Upload</title>
  <link rel="stylesheet" href="index.css">
</head>

<body>
  <div class="centered">
    <div class="child">
      <br><br><br><br>
      <img src="logopng.png" style="width:450px;height:550px;">
      <form method="POST" action="http://68.227.63.30:100/upload.php" enctype="multipart/form-data">
        <span>Choose midi files:</span> <br>
        <input type="file" name="file[]" multiple required/>
        <br><br>
        <input type="submit" name="submit" value="Upload for training" />

      </form>

    </div>
  </div>
</body>

</html>

https://i.stack.imgur.com/PWrv9.jpg

I had initially centered the content on my website, but adding the logo caused a layout issue. I may need to specify coordinates to fix this. Any suggestions would be appreciated!

Thank you in advance for any assistance!

Answer №1

To easily center your <body> or any child element wrapper, you can utilize CSS Flexbox as you have attempted. One adjustment I suggest is applying the flexbox centering to the .child element directly beneath

<div class="centered">
.

By adding flex-direction: column to switch from a row layout to a column layout, you can effectively center the <form> content with the logo. If the alignment isn't quite right due to lack of the logo source, consider adjusting padding or margin within the <form> element for the desired centering.

body {
  background-image: url('background.jpg');
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
}

.centered .child {
  /* Center entire body */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
<!DOCTYPE html>
<html>

<head>
  <title>Training File Upload</title>
  <link rel="stylesheet" href="index.css">
</head>

<body>
  <div class="centered">
    <div class="child">
      <br><br><br><br>
      <img src="logopng.png" style="width:450px;height:550px;">
      <form method="POST" action="http://68.227.63.30:100/upload.php" enctype="multipart/form-data">
        <span>Choose midi files:</span> <br>
        <input type="file" name="file[]" multiple required/>
        <br><br>
        <input type="submit" name="submit" value="Upload for training" />

      </form>

    </div>
  </div>
</body>

</html>

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

Switch between various components using multiple buttons in Next.js

I am in the process of creating a component that will display different components depending on which button the user selects. Here are the available “pages”: ` const navigation = [ { name: "EOQ", return: "<EOQgraph />" }, { nam ...

Steps for retrieving the currently selected text inside a scrolled DIV

An imperfect DIV with text that requires a scroll bar For example: <div id="text" style='overflow:scroll;width:200px;height:200px'> <div style='font-size:64px;'>BIG TEXT</div> Lorem Ipsum is simply dummy text of th ...

Troubleshooting Angular 4's ng-selected functionality

I'm currently facing an issue with getting ng-selected to function properly. Initially, I attempted to simply add selected in the option tag, but later discovered that I should be using ng-select. Despite trying variations such as ng-selected="true" a ...

Creating a variable in JavaScript

In my HTML body, I have set up a global variable named index with the value <%var index = 0;%>. This allows me to access it throughout the code. I'm trying to assign the value of $(this).val() to <% index %>, but I can't seem to get ...

The problematic max-width with srcset attribute

Here's the HTML markup I'm working with: <picture> <source srcset="img/home-page/placeholders/placeholder_2560.jpg" media="(max-width: 2560px)"> <source srcset="img/home-page/placeholders/placeh ...

Utilizing Bootstrap to arrange table cells in a shifted manner

I'm new to utilizing bootstrap in web development. I've been exploring various examples of bootstrap templates that include tables, and I noticed that when I resize my browser window, the table adjusts accordingly. Now, I'm curious to know ...

Exploring elementary functionalities within PHP

I'm just starting out, so please excuse any confusion in how I phrase this. Currently, I'm diving into my online computer science course which is focused on functions. The task at hand is to create sentences that output three different variables ...

Is there a regular expression that can be used to extract sentences from HTML

As I delve into the world of HTML parsing, I'm starting to understand that using regular expressions for this task is not always the best approach. However, in my Perl class, I am currently experimenting with utilizing regular expressions to extract a ...

Achieving a frosted glass effect for your background without relying on a background image

I am currently working on creating a modal window in React with a blurred backdrop. My goal is to blur the backdrop content while keeping the background image clear, as there is no image behind the modal window, just content. I have explored various soluti ...

How can I arrange a table in Angular by the value of a specific cell?

Here's the current layout of my table: Status Draft Pending Complete I'm looking for a way to sort these rows based on their values. The code snippet I've been using only allows sorting by clicking on the status header: onCh ...

Leveraging tailwind for achieving dynamic height responsiveness

My Tailwind-built page currently has a table in the bottom left corner that is overflowing, and I would like it to adjust its size to fit the available space and scroll from there. I want it to fit snugly in the bottom left corner of the browser viewport ...

How can I load a function from the HTML file that is being loaded using .load() in jQuery?

Within my main window main.html, there is a div button that, when clicked, loads another html file into a large div. This is achieved using the .load() function: $('#mainpanel').load("search.htm"); The "search.htm" file contains a function cal ...

Display the text above overlapping div elements

I need a design where one div overlaps another, but the text inside the overlapping div must still be visible. <div class='box1'> <div class='sendAbove'> This message should remain visible in this div </div> ...

What are some tips for getting media queries to function properly?

I need help with my homepage banner image as I am trying to make it responsive by adding media queries. The goal is for the image to adapt to 3 different sizes based on the screen being used, but currently only the medium-sized version appears. Could someo ...

Ways to prompt a specific text value to generate varied responses

Whenever I try to input the letter "h", I expect a specific value in return but for some reason, it's not working as intended. Despite my best efforts to troubleshoot the issue, I have been unsuccessful in finding a solution. It's frustrating bec ...

Adaptable Website Design (Without Header)

Check out my current website layout on codepen. I'm looking for a more responsive way to code this with CSS, so that the text doesn't get pushed over when the window is resized. Also, I want to improve the efficiency of coding the CSS for this l ...

Unable to scroll after the webpage redirects

I am currently working on developing a website for uploading images with a comment feature. The comments section is displayed below the image in the 'imagedisplay.php' file. If a user is not logged in, they are redirected to the sign-up page and ...

Tips for making a sidebar sticky when scrolling

In order to keep the right-side bar fixed, I have implemented this javaScript function: <script type="text/javascript> $(document).ready(function () { var top = $('#rightsidebar-wrapper').offset().top - parseFloat($('#rightsideb ...

Combining Flask with npm: A Comprehensive Guide

I have a unique flask application that initiates with python3 app.py running on localhost:5000 Moreover, there is another distinct nodejs program that kicks off with npm run start which operates on localhost:3000 The challenge that lies ahead for m ...

The text should be wrapped to overlap with an image positioned above it

Currently, I am in the process of enhancing a webpage that contains a significant amount of old legacy code. One issue I have encountered pertains to text wrapping within a fixed-height and width container, as illustrated in the image below: The first ima ...