Why can I center a button with flex but not a link?
#quote-btn-div {
display: flex;
}
#quote-btn,
#twitter-link {
background-color: #999;
/* Green */
border: none;
width: 300px;
height: 100px;
margin: 0 auto;
color: white;
text-align: center;
text-decoration: none;
font-size: 16px;
}
#twitter-link {
background-color: red;
}
<div id="quote-box">
<div id="quote-btn-div">
<button id="quote-btn">New Quote</button>
<a id="twitter-link">Twitter link</a>
</div>
</div>
Sorry if this is a stupid question, I'm still learning.
答案 0 :(得分:0)
line-height
通常用于垂直居中单行文本。由于您已在按钮上设置了高度,因此请将line-height
设置为该值。
#twitter-link { line-height: 100px; }
#quote-btn-div {
display: flex;
}
#quote-btn,
#twitter-link {
background-color: #999;
/* Green */
border: none;
width: 300px;
height: 100px;
margin: 0 auto;
color: white;
text-align: center;
text-decoration: none;
font-size: 16px;
}
#twitter-link {
background-color: red;
line-height: 100px;
}
<div id="quote-box">
<div id="quote-btn-div">
<button id="quote-btn">New Quote</button>
<a id="twitter-link">Twitter link</a>
</div>
</div>
答案 1 :(得分:0)
#twitter-link {
line-height: 100px;
}