【问题标题】:How to retain icon dimensions in a responsive design? Without using pixels如何在响应式设计中保留图标尺寸?不使用像素
【发布时间】:2016-03-24 23:24:04
【问题描述】:

首先,我只想说这个页面是针对网页设计课程的。

我正在构建的响应式页面中有社交媒体图标,并且我对所有图标都应用了max-width:3% 以减小它们的原始大小,因为它们以前太大了。现在,当我减小窗口大小时,我希望图标在保持新大小的同时保持响应。但是,图标也会缩放,使它们显得太小。我知道我可以使用像素来定义固定大小,但本练习的目标之一是以像素为单位设置图像值(只允许用于填充值)。

有没有办法做到这一点?

我的 html 代码

<div id="footwrap">     
        <footer>

            <div id="footh3">
                <h3 class="h3">Follow me on social media:</h3>
            </div>

            <div id="footlink">
                <a href="http://www.facebook.com" target="_blank">                  
                    <img src="images/facebook-icon.svg" alt="Facebook">             
                </a>

                <a href="http://www.instagram.com" target="_blank">                     
                    <img src="images/instagram-icon.svg" alt="Instagram">               
                </a>

                <a href="http://www.youtube.com" target="_blank">                       
                    <img src="images/youtube-icon.svg" alt="YouTube">               
                </a>

                <a href="http://www.twitter.com" target="_blank">                       
                    <img src="images/twitter-icon.svg" alt="Twitter">               
                </a>
            </di>

        </footer>
</div>

我的 CSS 样式:

#footwrap {
clear: both;
padding: 2%;
}

footer {
position: relative;
clear: both;
text-align: center;
width: 100%;
height: 8em;
margin-top: 12%;
}

#footh3 {
display: inline-block;
}

footer h3 {
display: inline-block;
font-family: 'Open Sans', sans-serif;
font-size: 1.17em;
margin-bottom: 2em;
margin-left: 0;
margin-right: 0;
font-weight: bold;
}

#footlink {
display: inline-block;
}

footer a {
text-decoration: none;
}

footer img {
display: inline-block;
max-width: 3%;
height: auto;   
margin-left: 1.5%;
margin-right: 10px;
vertical-align: middle;
}

希望的结果是当 Web 浏览器窗口缩小时此页面右上角的图标如何反应:http://www.omganeshaya.com/

【问题讨论】:

  • 那么期望的结果是什么?
  • 谢谢!很抱歉回复晚了。我会尝试你的建议,我还添加了更多关于我想要做什么的信息。

标签: html css responsive-design icons size


【解决方案1】:

随着页面变小,您可以使用媒体查询来调整到更高的百分比。见小提琴:https://jsfiddle.net/622r62mp/

有关媒体查询的更多信息,您可以参考本站https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries

CSS 示例

img{max-width:3%}
@media (max-width: 1000px){
  img{max-width:9%}
}
@media (max-width: 600px){
  img{max-width:15%}
}

【讨论】:

  • 我认为这与您在不使用任何 px 宽度的情况下获得的一样好。
猜你喜欢
  • 2013-05-19
  • 2014-05-05
  • 2015-10-27
  • 1970-01-01
  • 2015-05-22
  • 2014-11-05
  • 1970-01-01
  • 2016-05-08
  • 2016-12-18
相关资源
最近更新 更多