简体   繁体   English

为什么我的文字不对齐:居中; 好好工作?

[英]Why isn't my text-align: center; working properly?

Why isn't my text-align: center; 为什么我的text-align: center; working? 工作? The text and the span are supposed to be in the center of the image, (I'm kind of new at this, please understand). textspan应该位于图像的中心(对此我有点陌生,请理解)。

HTML looks like this: HTML看起来像这样:

<div id="image">
    <div id="imageContainer">
        <span><h1>Responsive Web</h1></span>
    </div>
</div>

CSS looks like this: CSS看起来像这样:

   #imageContainer h1 {
    text-align: center;
    font-size: 60px;
    color: white;
    letter-spacing: 0.05em;
    } 
    #imageContainer span {
    display: inline-block;
    padding: 0.5em 0.2em;
    border: white solid 10px;
   }

I don't understand why it isn't working, my H1 tag isn't listening to my text-align: center; 我不明白为什么它不起作用,我的H1标签没有听我的text-align: center; and neither is my span . 我的span也不是。 This might be a newbie question, (lol) but this confuses me a lot, help please! 这可能是一个新手问题,(笑)但是这让我很困惑,请帮忙!

Remove the display property 删除显示属性

#imageContainer span {

padding: 0.5em 0.2em;
border: white solid 10px;
}

Or put the width: 100% on 或将宽度:100%

#imageContainer span {
  width: 100%;
}

When you assign display: inline-block; 当您分配display: inline-block; to your span , the span is only as width as its content. 到您的spanspan仅取决于其内容的宽度。 You will have to set its width to 100% to get it working, or remove the display: inline-block; 您必须将其width设置为100%才能正常工作,或者删除display: inline-block; .

try: 尝试:

#imageContainer{ text-align: center; }

and the rest (span and h1) 其余的(跨度和h1)

display: inline-block; or display: inline; display: inline;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM