Create my website with a centered design (both horizontally and vertically)

I am looking to create a website similar to this one:

What I want for my website:

  • A dark general background
  • A bright main body in the center
  • The main logo placed just above and left of the main body
  • A top menu positioned above the main body

In simple terms, something similar to the design on the provided link.

If anyone can guide me in the right direction, it would be greatly appreciated.

Just so you know, I aim to follow HTML5 standards for my website.

Thank you.

Answer №1

If you want to center a div both vertically and horizontally, it can be achieved by setting a fixed width/height for the div as shown below:

div {
    width:300px;
    height:100px;
    position:absolute;
    top:50%;
    left:50%;
    margin-top:-50px;
    margin-left:-150px;
}

You can see how this code works in action by checking out this example http://jsfiddle.net/YxYCT/

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

Can you explain the contrast between "#msg" and "#msg div" when used in a style tag?

<html> <head> <style> #msg { visibility: hidden; position: absolute; left: 0px; top: 0px; width:100%; height:100%; text-align:center; ...

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 ...

Refreshing all parts of a webpage except for a single div

Currently, I am in the process of creating a simple web page that includes a small music player (niftyPlayer). The individuals I am developing this for request that the player be located in the footer and continue playing when users navigate to different s ...

What is the deal with CSS relative magnification?

I am currently utilizing a PHP styleswitcher along with alternate stylesheets in an attempt to replicate the functionality of browser zoom (done using keyboard shortcuts cmd-plus or ctrl-plus). At the moment, when clicking on the "zoom in" graphic, it is ...

Use Html.ActionLink to trigger events in various sections of the code

I'm attempting to create an ActionLink that will trigger an action in a different section of the code. Here is what I have so far: <div class="col-md-4"> @Html.ActionLink("Click to Perform Action", "Action", "SomeController") </div> ...

Seeking clarification on the distinction between using an input of type button versus an input of type submit when triggering a jQuery form submission

This particular code is designed to execute the following actions upon being clicked: Submit the form Disable the button in order to prevent double clicks Add a spinner to the button to indicate to the user that something is happening If the form is inva ...

What is the best way to store dynamic table data into an array?

After successfully implementing functionality for inputs, I am now facing some trivial errors that have slipped my attention. My script appears as follows: <script type="text/javascript"> $(document).ready(function () { $('#clicke ...

Duplicate numerous Td elements

I am trying to manipulate a table with 3 columns and 6 rows by copying the contents of certain cells into a newly created column, inserting them in the middle of the table. Here is the desired outcome: https://i.sstatic.net/RVTfV.png This is the approach ...

Enhanced Fancybox Version 2 adjusts iframe width to fit content

I have been attempting to adjust the width of the iframe in fancybox v2 to fit my content properly. However, every time I try, the content appears too large within the iframe and requires horizontal scrolling to view it all. My goal is to see the entire wi ...

What is the best way to incorporate JQuery into html content retrieved through an ajax request?

In my jsp file, there is a div structured like this : <div id="response" class="response"></div> After triggering an ajax call to a servlet, the content of this div gets updated with the following elements : <div id="response" class="res ...

Unexpected disappearance of form control in reactive form when using a filter pipe

Here is a reactive form with an array of checkboxes used as a filter. An error occurs on page render. Cannot find control with path: 'accountsArray -> 555' The filter works well, but the error appears when removing any character from the fi ...

What is the process for connecting CSS to an HTML page?

In my project, I have an index.html file and a style.css file. Currently, I am using inline CSS in my HTML file but now I want to utilize an external stylesheet. Inside my index.html file, just before the closing </head> tag, I have added the followi ...

Is there a way to instantly receive notifications when a website publishes new content?

Is there a way to preview a new website page before it goes live on the homepage, but after it has been posted online? I've tried using sitemaps, but the issue is that I need real-time monitoring, not historical data. For instance, let's consid ...

Issue with left-aligned navigation in Bootstrap

Having some trouble getting my logo to align correctly on the top navigation bar. It looks fine in a small view, but when I stretch it out, the logo shifts to the right. I want the logo to stay all the way to the left regardless of screen size. I've ...

Verifying the selectedIndex does not align when choosing multiple options in a select element

<div class="row"> <div class="col-xs-12 col-sm-6 col-md-6"> <div class="form-group"> <select id="s1" multiple="multiple" class="form-control" name="stype" onchange="showfield1(this.options[this.selectedIndex].valu ...

The reliability of jQuery posting varies

My current setup involves using jQuery to send data to an external source with the code snippet provided below. As part of the process, I'm also ensuring that all input fields are filled out correctly. However, there has been a strange issue where the ...

Retrieve a collection of nested dictionaries containing flask and angular data

In my app development journey with flask and ionic(angular), I'm working on returning a JSON list. Here's the python code snippet: def get-stocks(): # Select all stocks cursor.execute("""SELECT * FROM `tbl_symbol_index`"" ...

Attempting to display images in various formats using the Picture HTML element

Vue is being used to create a dynamic picture component, resulting in the following code: <picture style="display: contents;"> <source type="image/avif" sizes="700px" src ...

Expanding Your Django Template Abilities

Dealing with a fairly simple issue here. I've got a web page template that includes some common CSS styles at the top. <html> {% load static %} <link rel="stylesheet" type="text/css" href="{% static 'css/index.css' %}"> .... *n ...

Angular: sending the user input to the component

I'm trying to link the value of an HTML input field to a variable 'numToAdd' in my component, and then increment the 'numToAdd' variable by 1. However, I'm facing difficulties passing the input value to the component variable. ...