Best Practice for Positioning elements in html/css

Coreysan 1,736 Reputation points
2022-07-07T16:52:23.323+00:00

Sometimes I get so immersed in complex nested <div>s, that I forget the simple basics!

Suppose I have a web page where I want to position a blog post title about 45% down from the top of the page.
Nothing above the title, no images, no nothing, just empty space.

What's the best practice for creating that space?

My first though was:

<h1 style="margin-top: 12em;">Title here</h1>

(Not trying to use exact measurement. I just wanted to emphasize a large amount of room)

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,573 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 65,576 Reputation points
    2022-07-07T19:25:21.277+00:00

    use vh for percent of window height:

    <h1 style="margin-top: 45vh;">Title here</h1>

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.