Share via

Best Practice for Positioning elements in html/css

Coreysan 1,866 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)

Developer technologies | ASP.NET | ASP.NET Core
0 comments No comments

Answer accepted by question author

  1. Bruce (SqlWork.com) 83,821 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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.