<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Puggy Adventure Website</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body style="background-color: rgb(237, 227, 227);">
<header>
<section>
<h1 style="position:absolute; display: flex; top: 0%; left: 2%; color:rgb(182, 21, 185); font-style: italic;"><strong>Puggy Adventures</strong></h1>
</section>
</header>
<div class="navigationBar" style="background-color: rgb(123, 120, 123); height: 50px;">
<section>
<button class="homeButton" style="position: absolute; display: flex; left: 20%; top: 3.5%;"><strong>Home</strong></button>
</section>
<section>
<button class="newsButton" style="position: absolute; display: flex; left: 30%; top: 3.5%;"><strong>News</strong></button>
</section>
<section>
<button id="supportButton" style="position: absolute; display: flex; left: 40%; top: 3.5%;"><strong>Support</strong></button>
</section>
<section>
<button id="aboutButton" style="position: absolute; display: flex; left: 50%; top:3.5%;"><strong>About</strong></button>
</section>
</div>
<main>
<img src="" id="featuredImage" style=" position: absolute; display: flex; height: 200px; width: auto; left: 20%; top: 40%;">
<section>
<h2>Storyline</h2>
</section>
<section>
<p style="position: absolute; display: flex; top: 40%; left: 45%; text-align: center;"><strong>The Puggy Adventure offers a school-friendly experince which is designed to keep you entertained for hours! Our team of professionals with google slides know how to make you have the best experince possible while playing our game! This year the puggy adventure is mostly in 1st person POV! along with some 3D models being injected into the game.</strong></p>
</section>
<section>
<iframe width="220" height="200" src="https://www.youtube.com/embed/VJEVxYyTFRI" ?autoplay=1 frameborder="0" style="left:0%; top: 40%; position: absolute; display: flex;"></iframe>
</section>
</main>
<script src="index.js"></script>
</body>
</html>
I have tried on other projects to make the buttons closer together manually and testing out different percentages but it took so much time and was so boring, there has to be a better way to do this.
2
Answers
The problem is with you using too many absolute position elements that’s why nearly all your code need to be positioned from the start screen, you need to set the position to relative on the buttons and put margins on each one.
I’m not sure what your end-goal is with this you need to remove all the absolute positioning from your code and used flex-box or css grid instead. This way you can position items on your page using a flexible and responsive pattern. I would recommend this for further reading. Here is a very basic example of using flex-box with some code to get you started. Uncomment the
/*flex: 1;*/
if you want to space the links out within it’s parent element: