【问题标题】:How do I get these social icons to be straight centered on the page on all browsers?如何让这些社交图标在所有浏览器的页面上直接居中?
【发布时间】:2013-06-26 21:02:14
【问题描述】:

网站链接:foxweb.marist.edu/users/kf79g/contact.php

就是这样。在部署我的网站并最终完成之前,我必须修复的最后一步。但我不知道如何解决这个问题。在中小屏幕上,我的社交图标遇到了很多麻烦。我希望中小型设备上的所有内容都集中在中心并 100% 响应。我尝试制作一个容器来让它们响应,但无论我做什么,它在 IE 7-10 中总是看起来很乱。随着页面宽度越来越小,图标正在移动到下一行,而不是均匀地停留在一行上。我尝试调整页边距,但这并没有帮助,因为这破坏了整个页面的中心属性。我根本不知道该怎么做或如何解决这个问题。如果有人可以帮助我,我将不胜感激。

问题的可视化表示(IE):

http://tinypic.com/r/nla7eq/5

我希望它看起来像什么(现代浏览器):

http://tinypic.com/view.php?pic=vp9gg7&s=5

HTML:

<h2> Social networks </h2><br/>

                        <div id = "center_icons">
                            <a href="https://www.facebook.com/lenny.pfautsch" target="_blank"><img src="images/facebook.png" alt="facebook" style="margin:1px;"></a> 

                            <a href="https://plus.google.com/113122168458946246215/posts" target="_blank"><img src="images/google-plus.png" alt="google plus" style="margin:1px;"></a>

                            <a href="http://www.linkedin.com/pub/leonard-pfautsch/53/b34/1a2" target="_blank"><img src="images/linkedin.png" alt="linkedin" style="margin:1px;"></a>

                            <a href="https://github.com/LeonardPfautsch" target="_blank"><img src="images/github.png" alt="github" style="margin:1px;"></a>
                        </div>
                    <br/>

                    </div>

            </section>      


Main CSS:   

    #details_section {
        max-width:100%;
        float:left;
        margin-right:20px;
    }


Large screens:    

    #details_section {
        width:320px;
    }




Medium screens:    

    #center{
    width: 450px;
      display: block;
      margin-left: auto;
      margin-right: auto;
    }

    #center_icons{
    width: 213px; /*this value is changing for IE and chrome*/
      display: block;
      margin-left: auto;
      margin-right: auto;
    }



Small screens:    

    #center{
    width: 220px;
      display: block;
      margin-left: auto;
      margin-right: auto;
      max-width:100%;
    }

    #center_icons{
    width: 214px; /*this value is changing for IE and chrome*/
      display: block;
      margin-left: auto;
      margin-right: auto;
      max-width:100%;
    }

【问题讨论】:

  • 请只显示相关代码。没有人会阅读这篇太长的摘录。
  • 好的,给我一分钟,我会让它更简单
  • 我已经做了相应的修改。
  • 您是否尝试过应用 img{border:0;}。 IE 倾向于对图像应用愚蠢的边框。
  • @AurelioDeRosa 我试过你说的,但没有任何改变。

标签: html css internet-explorer responsive-design


【解决方案1】:

您还可以删除“=”之间的空格,并使用“而不是'。

<div id = "center">
<div id='details_section'>

应该是

<div id="center">
<div id="details_section">

您还应该在某处指出图像大小。

<div id="container">
<div id="center_icons">
<a href="https://www.facebook.com/lenny.pfautsch" target="_blank"><img src="images/facebook.png" alt="facebook" width="40" height="40"></a>

<a href="https://plus.google.com/113122168458946246215/posts" target="_blank"><img src="images/google-plus.png" alt="google plus" width="40" height="40"></a>

<a href="http://www.linkedin.com/pub/leonard-pfautsch/53/b34/1a2" target="_blank"><img src="images/linkedin.png" alt="linkedin" width="40" height="40"></a>

<a href="https://github.com/LeonardPfautsch" target="_blank"><img src="images/github.png" alt="github" width="40" height="40"></a>
</div>
</div>

更简单的 CSS 是:

div {border: 1px red solid;padding: 5px}   /*this is only for us to see it when testing*/

#container {
        text-align:center;
    }

    #center_icons{
    width: 214px; /*this value is changing for IE and chrome*/
      display: block;
      margin-left: auto;
      margin-right: auto;
      max-width:100%;
    }

在这里检查它是否工作:http://codepen.io/anon/pen/mAjzo

【讨论】:

  • 如何回答这个问题?
  • 我还删除了 style="margin:1px;"从您的图像 html 中,如果需要,您可以将其添加到 css 中。
  • 您先生,引导我朝着正确的方向前进,我离部署我的网站又近了一步。我能够修复图标。非常感谢你的努力。我剩下的就是修复页面上的表单,因为由于某种原因它没有均匀地居中。我会在这里问另一个问题,如果你也能帮助我,我会永远感激我现在的样子。非常感谢!
  • 您对不同的元素尝试相同的过程:使用 div 作为容器,将您的内容放在中心,例如 #container {text-align:center} 和另一个将您的内容放在中心,例如#formcontent {width:250px; margin:auto; text-align:left}
  • 抱歉 @MohammadAreebSiddiqui 和 aurelio 如果当时的回复不完整。
【解决方案2】:

只需在代码中使用&lt;center&gt; &lt;/center&gt; 而不是 Div id "center"。

【讨论】:

  • 这是什么意思?您的意思是在 html 内部设置样式而不是外部链接?
  • @user2521978 天哪,不要! center 是一个绝对不推荐使用的标签!
  • 如果我这样做,我会收到大量的 html5 验证错误。我想让我的页面没有错误。
  • @Aurelio De Rosa 我很清楚谢谢你提醒我。
【解决方案3】:

您需要更改您的 CSS 属性,只需测量您的屏幕坐标并将其放在边距中,或者您可以使用 HTML5 来解决这个问题。

【讨论】:

  • 使用标签是什么意思?如何使用 HTML5 来解决这个问题?您能否详细说明您的答案,并举例说明您的意思?我真的很感激。
  • 我的意思是使用 HTML5 Canvas 将您的社交图标放在上面。要了解有关画布的更多信息,请访问此处w3schools.com/html/html5_canvas.asp
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-25
  • 1970-01-01
  • 2019-02-23
  • 1970-01-01
相关资源
最近更新 更多