[英]HTML/CSS Text Not aligning
I'm making a website and my text won't align to the center for the index-intro h1! 我正在建立一个网站,但我的文字无法与索引介绍h1的中心对齐!
.index-intro { width:100%; background-color: #00C8FF; height: 20px; float:center; } .index-intro h1 { font-family: tpeb; font-size: 15px; text-transform: uppercase; text-align:center; display:inline-block; }
<section> <div class="index-intro"> <div class="wrapper"> <h1>Welcome to Anime!</h1> </div> </div> </section>
And thanks :) 谢谢:)
Here is a trimmed down set of HTML and CSS: 这是一组精简的HTML和CSS:
.index-intro { background-color: #00C8FF; text-align:center; } .index-intro h1 { font-size: 15px; text-transform: uppercase; }
<div class="index-intro"> <div class="wrapper"> <h1>Welcome to Anime!</h1> </div> </div>
This aids the vertical alignment issues too, since you had fixed the height of the containing <div>
. 这也有助于垂直对齐问题,因为您已经固定了包含的
<div>
的高度。 Although I guess you may have wanted that? 虽然我想你可能想要那个?
Here it is with some padding thrown in: https://jsfiddle.net/9a3b4f7g/1/ 这是带有一些填充的: https : //jsfiddle.net/9a3b4f7g/1/
Please try following code snippet 请尝试以下代码段
.index-intro { width:100%; background-color: #00C8FF; height: 20px; text-align:center } .index-intro h1 { font-family: tpeb; font-size: 15px; text-transform: uppercase; }
<section> <div class="index-intro"> <div class="wrapper"> <h1>Welcome to Anime!</h1> </div> </div> </section>
Your Css is okay. 您的CSS没问题。
Just add this class in style tag 只需在样式标签中添加此类
<style type="text/css">
.wrapper
{
text-align: center;
}
</style>
Believe it or not, you can do what you're looking for with just 信不信由你,你可以做你想要的只是
.index-intro h1 {
font-family: tpeb;
font-size: 15px;
text-transform: uppercase;
text-align:center; /*this makes the text go in the middle*/
display:inline-block;
width:100%;
background-color: #00C8FF; /*your bar color*/
padding-top:20px; /* this "fattens" the blue bar topside */
padding-bottom:20px; /* this "fattens" the blue bar bottomside */
}
What this basically does is, 'make a blue bar that fits 100% the window width, with text in the middle, fatten it top and bottom'. 这基本上是做的是,“制作一个适合窗口宽度100%的蓝色条,中间带有文本,在顶部和底部加粗”。 It's better to keep your CSS simple like this if you can.
如果可以的话,最好像这样保持CSS简单。 Keeps you from getting confused in the long run.
从长远来看,可以避免您感到困惑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.