我只是無法將此文本垂直居中放置在我的 div(紅色背景)中,我已經嘗試了所有方法但沒有任何效果,請幫忙!出于某種原因,如果不使用邊距/填充,我什至無法在 div 中獲取我的文本。我試過對文本使用 div、span、p 和 h1,但沒有任何效果 =(

這是我的代碼:
<div class="headerdiv">
<div class="backtotop">
<a class="material-symbols-outlined" href="#" >arrow_upward</a>
<a class="backtotoptext" href="#">Voltar ao topo</a>
</div>
<div class="githubcontainer">
<a href="https://github.com/maruan-achkar/javascript_exercicios" target="_blank" class="githublink" >//GITHUB LINK</a>
</div>
<div class="dropdown">
<div class="dropdown-title-container">
<p class="dropdown-title">MENU</p>
</div>
<div class="dropdown-content">
<a class="dropdowna" href="#trocarvariaveis">// Trocar Variaveis<br></a>
<a class="dropdowna" href="#celsiusparafarenheit">// Celsius para Farenheit<br></a>
<a class="dropdowna" href="#farenheitparacelsius">// Farenheit para Celsius<br></a>
<a class="dropdowna" href="#areacirculo">// Area Circulo<br></a>
<a class="dropdowna" href="#parouimpar">// Par ou Impar<br></a>
<a class="dropdowna" href="#intervalo">// Intervalo entre numeros<br></a>
<a class="dropdowna" href="#intervalovetor">// Intervalo entre maior e menor de vetor<br></a>
<a class="dropdowna" href="#maiormenor">// Maior e menor numero<br></a>
<a class="dropdowna" href="#paisagemouretrato">// Paisagem ou retrato<br></a>
<a class="dropdowna" href="#fizzbuzz">// Fizz ou Buzz<br></a>
<a class="dropdowna" href="#stringobject">// String do objeto<br></a>
<a class="dropdowna" href="#parimparlimite">// Par ou impar ate limite<br></a>
</div>
</div>
</div>
</header>
--------------------------------------------CSS--------------------------------------------
.dropdown {
float: left;
background-color: #F6F7EB;
height: 100%;
width: 100px;
}
.dropdown-title-container{
background-color: #DC3318;
height: 100%;
display: flex;
justify-content: center;
}
.dropdown-title{
font-family: Arial;
font-weight: bolder;
font-size: 1.75em;
line-height: 100%;
}
.dropdown-content {
display: none;
position: absolute;
top: 48px;
background-color: #F6F7EB;
padding-right: 15px;
outline: solid black 3px;
box-shadow: 0px 10px 15px black;
border-radius: 0.1vw;
font-size: 0.8em;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdowna{
color: black;
font-size: 1.75em;
margin-left: 2vw;
text-decoration: none;
}```.sticky{
position: fixed;
top: 0;
width: 100%;
height: 45px;
background-color: #DC3318;
box-shadow: 0px 0px 5px rgb(0, 0, 0, 0.65);
}
.headerdiv{
background-color: greenyellow;
height: 100%;
width: 100%;
}
.backtotop{
font-weight: bolder;
font-size: 0.75em;
margin-right: 0;
height: 100%;
width: 160px;
float: right;
display: flex;
align-items: center;
}
.backtotoptext{
margin: auto;
text-decoration: none;
color: black;
font-size: 1.55em;
margin-right: 12px;
}
.material-symbols-outlined{
text-decoration: none;
margin-right: -30px;
margin-bottom: 3px;
color: black;
}
.backtotop:hover .backtotoptext{
color: rgb(0, 132, 255);
}
.backtotop:hover .material-symbols-outlined{
color: rgb(0, 132, 255);
}
.githubcontainer{
width: 200px;
height: 100%;
float: right;
margin-right: 40px;
display: flex;
align-items: center;
}
.githublink{
color: black;
margin: auto;
font-size: 1.35em;
text-decoration: none;
}
.githublink:hover{
text-decoration: underline;
}
uj5u.com熱心網友回復:
只需添加 align-items:center;到.dropdown-title-container,文本就會垂直對齊。
uj5u.com熱心網友回復:
我測驗了你的代碼。但是,它不會顯示與您發布的圖片相同的螢屏,
所以我不能確切地說。你試過'align-items: center;'
.dropdown-title-container{
background-color: #DC3318;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
uj5u.com熱心網友回復:
我相信你正在嘗試做一些簡單的事情,但比需要的要難得多。
在您的 CSS 檔案中嘗試align-items: center在.dropdown-title-container.
像這樣:
.dropdown {
float: left;
background-color: #F6F7EB;
height: 100%;
width: 100px;
}
.dropdown-title-container{
background-color: #DC3318;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.dropdown-title{
font-family: Arial;
font-weight: bolder;
font-size: 1.75em;
line-height: 100%;
}
.dropdown-content {
display: none;
position: absolute;
top: 48px;
background-color: #F6F7EB;
padding-right: 15px;
outline: solid black 3px;
box-shadow: 0px 10px 15px black;
border-radius: 0.1vw;
font-size: 0.8em;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdowna{
color: black;
font-size: 1.75em;
margin-left: 2vw;
text-decoration: none;
}
.sticky{
position: fixed;
top: 0;
width: 100%;
height: 45px;
background-color: #DC3318;
box-shadow: 0px 0px 5px rgb(0, 0, 0, 0.65);
}
.headerdiv{
background-color: greenyellow;
height: 100%;
width: 100%;
}
.backtotop{
font-weight: bolder;
font-size: 0.75em;
margin-right: 0;
height: 100%;
width: 160px;
float: right;
display: flex;
align-items: center;
}
.backtotoptext{
margin: auto;
text-decoration: none;
color: black;
font-size: 1.55em;
margin-right: 12px;
}
.material-symbols-outlined{
text-decoration: none;
margin-right: -30px;
margin-bottom: 3px;
color: black;
}
.backtotop:hover .backtotoptext{
color: rgb(0, 132, 255);
}
.backtotop:hover .material-symbols-outlined{
color: rgb(0, 132, 255);
}
.githubcontainer{
width: 200px;
height: 100%;
float: right;
margin-right: 40px;
display: flex;
align-items: center;
}
.githublink{
color: black;
margin: auto;
font-size: 1.35em;
text-decoration: none;
}
.githublink:hover{
text-decoration: underline;
}
<header class="site-header">
<div class="headerdiv">
<div class="backtotop">
<a class="material-symbols-outlined" href="#">arrow_upward</a>
<a class="backtotoptext" href="#">Voltar ao topo</a>
</div>
<div class="githubcontainer">
<a
href="https://github.com/maruan-achkar/javascript_exercicios"
target="_blank"
class="githublink"
>//GITHUB LINK</a
>
</div>
<div class="dropdown">
<div class="dropdown-title-container">
<p class="dropdown-title">MENU</p>
</div>
<div class="dropdown-content">
<a class="dropdowna" href="#trocarvariaveis"
>// Trocar Variaveis<br
/></a>
<a class="dropdowna" href="#celsiusparafarenheit"
>// Celsius para Farenheit<br
/></a>
<a class="dropdowna" href="#farenheitparacelsius"
>// Farenheit para Celsius<br
/></a>
<a class="dropdowna" href="#areacirculo">// Area Circulo<br /></a>
<a class="dropdowna" href="#parouimpar">// Par ou Impar<br /></a>
<a class="dropdowna" href="#intervalo"
>// Intervalo entre numeros<br
/></a>
<a class="dropdowna" href="#intervalovetor"
>// Intervalo entre maior e menor de vetor<br
/></a>
<a class="dropdowna" href="#maiormenor"
>// Maior e menor numero<br
/></a>
<a class="dropdowna" href="#paisagemouretrato"
>// Paisagem ou retrato<br
/></a>
<a class="dropdowna" href="#fizzbuzz">// Fizz ou Buzz<br /></a>
<a class="dropdowna" href="#stringobject"
>// String do objeto<br
/></a>
<a class="dropdowna" href="#parimparlimite"
>// Par ou impar ate limite<br
/></a>
</div>
</div>
</div>
</header>
:D
此鏈接將來應該對您有所幫助。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/534729.html
標籤:网页格式CSS
