【问题标题】:Centering Buttons in HTML5 with CSS使用 CSS 在 HTML5 中居中按钮
【发布时间】:2013-10-30 19:33:44
【问题描述】:

我想知道如何将一组社交媒体按钮集中在我的网站上。

我之前使用了<center> 标签,但切换到了 HTML5,所以我在 css 中拥有其他文本和图像的居中属性。但是,我有 4 个不同社交媒体网站的链接,它们都使用不同的编码风格来实现按钮。 以下是我的代码


<div class="fb-like" data-href="https://www.facebook.com/pages/La-Condesa/242967619184322" data-width="20" data-height="20" data-colorscheme="light" data-layout="standard" data-action="like" data-show-faces="false" data-send="false"></div>

<style>.ig-b- { display: inline-block; } .ig-b- img { visibility: hidden; } .ig-b-:hover { background-position: 0 -60px; } .ig-b-:active { background-position: 0 -120px; } .ig-b-32 { width: 32px; height: 32px; background: url(//badges.instagram.com/static/images/ig-badge-sprite-32.png) no-repeat 0 0; } @media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min--moz-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2 / 1), only screen and (min-device-pixel-ratio: 2), only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx) {.ig-b-32 { background-image: url(//badges.instagram.com/static/images/ig-badge-sprite-32@2x.png); background-size: 60px 178px; } }</style><br><br>

&lt;a href="http://instagram.com/lacondesafitzroy?ref=badge" class="ig-b- ig-b-32"&gt;img src="//badges.instagram.com/static/images/ig-badge-32.png" alt="Instagram" /&gt;&lt;/a&gt;

&lt;a href="https://twitter.com/LaaCondesa" class="twitter-follow-button" data-show-count="false" data-show-screen-name="false"&gt;Follow @LaaCondesa&lt;/a&gt;
&lt;script&gt;!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');&lt;/script&gt;

&lt;iframe class="btn" frameborder="0" border="0" scrolling="no" allowtransparency="true" height="25" width="114" src="http://platform.tumblr.com/v1/follow_button.html?button_type=2&amp;tumblelog=LaaCondesa&amp;color_scheme=light"&gt;&lt;/iframe&gt;


有没有一种简洁的方式在 HTML5 中将所有这些项目居中?还是我必须为每个单独做?如果是这种情况,我怎样才能使这些项目居中?

谢谢

编辑:对不起,我遗漏了,它们都包含在具有以下属性的容器中 .container { position: static;
height: 700px; width: 780px; top: 50%; left: 50%; margin: 10px;
margin-left: auto; margin-right: auto; }

查看 www.lacondesa.com.au/test.html 了解

【问题讨论】:

    标签: css html button alignment center


    【解决方案1】:

    尝试将按钮放在具有样式的 div 中

    text-align:center;
    margin:auto;
    

    【讨论】:

    • 完美运行!非常感谢
    • margin:auto; 真的需要吗?
    • margin:auto 行使 div 居中。
    【解决方案2】:

    在 div 中指定特定宽度,然后输入margin:auto

    div
    {
    width://your width;
    margin:auto;
    }
    

    【讨论】:

      【解决方案3】:

      这可能有效。试试看,

      margin : 0px auto;
      

      【讨论】:

        猜你喜欢
        • 2014-03-14
        • 2016-08-26
        • 2012-02-05
        • 2013-09-13
        • 2013-06-06
        • 1970-01-01
        • 1970-01-01
        • 2015-02-14
        • 1970-01-01
        相关资源
        最近更新 更多