【问题标题】:How to center align div如何居中对齐div
【发布时间】:2014-09-30 16:09:09
【问题描述】:

我从 Mail chimp 获得了一些嵌入代码,用于在我的网站上显示新闻通讯注册框。我正在尝试使通讯框居中对齐,但不确定我需要将样式添加到哪个 div。我尝试使用 style="text-align: center" 但没有用。我认为可能会有过度骑行的风格?

www.skinmade.com.au(见页面底部)

提前致谢。

【问题讨论】:

    标签: html css alignment center


    【解决方案1】:

    给包含的 div 一个固定宽度,将显示设置为“块”并将左右边距设置为“自动”,如下所示:

    #mc_embed_signup {
        display: block;
        margin: 0 auto;
        width:300px;
    }
    

    您还可以解决提交按钮不显示全文的问题,如下所示:

    #mc_embed_signup input.button {
        width: auto;
    }
    

    【讨论】:

      【解决方案2】:

      在你的 CSS 中试试这个:

      #mc_embed_signup input.button {
      display: block;
      width: 133px;
      text-align: center;
      position: relative;
      height: 43px;
      /*margin:0;*/
      }
      

      【讨论】:

        【解决方案3】:

        试试这个

        input.button{ display: inline-block; }
        
        #mc_embed_signup{ text-align:center; }
        

        #mc_embed_signup{ width:200px; margin: auto auto; }
        

        【讨论】:

        • 好吧,虽然它没有与上面的图标内联。也许与图标在同一行看起来会更好。对代码有什么建议吗?
        猜你喜欢
        • 2013-10-13
        • 2011-03-13
        • 2016-08-17
        • 1970-01-01
        • 1970-01-01
        • 2011-11-21
        • 1970-01-01
        • 1970-01-01
        • 2022-01-10
        相关资源
        最近更新 更多