Is there a way to perfectly center my webpage using just HTML and CSS? I've tried various methods like margin: auto, margin: 0 auto, and even margin-left: auto & margin-right: auto but nothing seems to be working based on the information I found online. Below is the code I am currently using. I want everything to be centered, every div element, and also compatible with mobile applications.
body {
background-color: white;
font-family: Arial, Helvetica, sans-serif;
}
#header {
display: flex;
justify-content: center;
align-items: center;
color: black;
margin-top: 50px;
font-size: 40px;
font-weight: bold;
}
.social {
float: left;
text-align: center;
margin-bottom: 20px;
position: relative;
right: -220px;
bottom: -70px;
}
.social #spotifylogo {
position: relative;
bottom: -7px;
}
.social #fblogo {
position: relative;
bottom: 1px;
left: -1px;
}
.social #twitterlogo {
position: relative;
bottom: 1px;
left: 6px;
}
.nav {
text-align: center;
color: black;
font-size: 14px;
float: left;
position: relative;
right: -495px;
margin-top: 25px;
}
.nav a:link {
text-decoration: none;
color: black;
margin-right: 15px;
}
.nav a:hover {
color: greenyellow;
}
#headpic {
position: relative;
right: -225px;
bottom: -100px;
}
<h1 id="header">cyberpVnk</h1>
<div class="nav">
<a href="#headpic">Start</a>
<a href="#Musik">Musik-Player</a>
<a href="#Video">Video-Player</a>
<a href="#Bio">Biografie</a>
<a href="#Kontakt">Kontakt</a>
</div>
<div class="social">
<a href="http://www.instagram.com/cyberpvnk9x" target="_blank"><img src="https://image.flaticon.com/icons/svg/87/87390.svg" width="25" height="25"></a>
<a href="spotify"><img src="spotify.png" width="40" height="40" id="spotifylogo"></a>
<a href="facebook"><img src="fbbutton.png" width="26" height="26" id="fblogo"></a>
<a href="twitter"><img src="https://www.nicepng.com/png/full/84-842524_twitter-logo-in-circular-black-button-twitter-logo.png" width="27" height="27" id="twitterlogo"></a>
</div>
<div id="headpic">
<img src="headpic.jpg" width="900" height="500">
</div>