Как правильно выровнять по центру страницы?
Кто знает как разместить див по центру страницы, я пробовал несколько способов но оставался в верхнем левом углу. Что я делаю не так?
html код:
h1{
font-family: Arial Black,Arial Bold,Gadget,sans-serif;
}
h4{
margin-top: -60px;
font-family: Arial Black,Arial Bold,Gadget,sans-serif;
}
pre{
margin-bottom: -40px;
}
#field{
width: 300px;
border-radius: 50px;
height: 30px;
}
.btns{
cursor: pointer;
margin-top: 5px;
}
#footer{
bottom: 0;
left: 0;
position: absolute;
width: 100%;
display: flex;
justify-content: center;
background-color: lightgrey;
text-align: center;
}
<div id="main">
<pre>
<h1>MSearch </h1>
<h4>Convenient search engine</h4>
</pre>
<input id="field" type="search" placeholder="To find what?"><br>
<img class="btns" src="img/google.png">
<img class="btns" src="img/yahoo.png">
<img class="btns" src="img/bing.png">
<img class="btns" src="img/yandex.png">
<img class="btns" src="img/youtube.png">
<img class="btns" src="img/wikipedia.png">
<img class="btns" src="img/msn.png">
</div>
<div id="footer">
<footer>
MultiSearch:copyright: - All rights reserved.<br>
2021 - 2021
</footer>
</div>
Спасибо.
Ответы (1 шт):
Автор решения: EkaterinaRatatui
div{
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
<div> text </div>
→ Ссылка
Кто знает как разместить див по центру страницы, я пробовал несколько способов но оставался в верхнем левом углу. Что я делаю не так? html код:
h1{
font-family: Arial Black,Arial Bold,Gadget,sans-serif;
}
h4{
margin-top: -60px;
font-family: Arial Black,Arial Bold,Gadget,sans-serif;
}
pre{
margin-bottom: -40px;
}
#field{
width: 300px;
border-radius: 50px;
height: 30px;
}
.btns{
cursor: pointer;
margin-top: 5px;
}
#footer{
bottom: 0;
left: 0;
position: absolute;
width: 100%;
display: flex;
justify-content: center;
background-color: lightgrey;
text-align: center;
}
<div id="main">
<pre>
<h1>MSearch </h1>
<h4>Convenient search engine</h4>
</pre>
<input id="field" type="search" placeholder="To find what?"><br>
<img class="btns" src="img/google.png">
<img class="btns" src="img/yahoo.png">
<img class="btns" src="img/bing.png">
<img class="btns" src="img/yandex.png">
<img class="btns" src="img/youtube.png">
<img class="btns" src="img/wikipedia.png">
<img class="btns" src="img/msn.png">
</div>
<div id="footer">
<footer>
MultiSearch:copyright: - All rights reserved.<br>
2021 - 2021
</footer>
</div>
Спасибо.
Ответы (1 шт):
Автор решения: EkaterinaRatatui
→ Ссылка
div{
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
<div> text </div>