【问题标题】:Images are overlapping when resizing the page调整页面大小时图像重叠
【发布时间】:2017-01-12 06:05:10
【问题描述】:

你好 stackoverflow 社区。当图像元素(社交媒体按钮)进入我网页上的图像时,我遇到了这个问题。首先,我的元素溢出了它们所在的 div 框。我试图用overflowproperty 来修复它,但这不是我想要的。所以我尝试使用clearfix 将元素保留在 div 中,结果就失控了。所以2小时后我仍然没有解决这个问题。我试图使用margin-right 将社交按钮从图像上移开,但它不起作用。同样稍微超出了这个话题,在我实现了具有相对位置的社交按钮之后,我在页面顶部的行在一端变得更短了。用来拉伸几乎整个页面,现在它被剪切了。所以,是的,这里有两个问题。我真的很感激一些帮助。这是我对以下两个问题的关键代码:

HTML:

<!Doctype html>
<html>
<body>
<link href="style.css" rel="stylesheet">
<div class="top_page">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<ul id="nav_container">

<li><a href="about_proper.html">About</a></li>
<li><a href="articles.html">Articles</a></li>
<li><a href="news.html">News</a></li>
</div>
<div class="media_buttons">
<ul>
<li><a href="about_proper.html"><img src="social/facebook.png" alt="facebook_social_button" style="width:30px;height:30px;"/></a></li>
<li><a href="news.html"><img src="social/twitter.png" alt="twitter_social_button" style="width:30px;height:30px;"/></a></li>
</ul>
</div>

<hr>
<h1>Travel locally and globally</h1>

<div class="content">
<img src="travel.jpg" alt="Go Travel" style="text-align:centre;width:504px;height:228px;"/>
</div>

CSS:

 #nav_container {

        margin: 0%;
        text-align: center;
        padding-top: 5px; 
        left:5px;
        right:5px;
        width:auto;

    }

    #nav_container li {
        display: inline;
        margin: 4%;
        font-family: Arial; 
    }

    #nav_container a {
        color:#3e3e3e;
        background-color:#ffffff;
        text-decoration: none;   
    }
    #nav_container a:hover {

        background-color:#ffffff;
        color: #3e5869;
    }

    #nav_container a:visited {
        color:#357c49;
        background-color: #ffffff;
    }

    div {
        padding-top: 50px; 
        left:5px;
        right:5px;

    }

    h1 {
        text-align:center;
        margin: auto;
        width:60%;
        color: #73AD21;
        font-family: Arial;
        top:-40px;
        height: 6%;
        padding: 3%;
    }
    .content {
        margin:auto;
        text-align:center;
        top: 5px;
        padding-bottom:45px;
}
    .media_buttons {
        position:relative;
        top:300px;
        left:20%;
        border:solid;
        padding:5px;
        display:block;
        text-decoration: none;
        list-style-type:none;
    }

    .media_buttons li {
        list-style-type:none;
        width:100%;
        height:100%;
        margin-right:50px;
        float:left;
    }

【问题讨论】:

  • 欢迎来到 SO,请注意:&lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt; 必须是 &lt;head&gt; 而不是 &lt;body&gt;,我会检查我能为你做些什么 :)
  • 那么你到底想把社交图标放在哪里?
  • 嗨,Mools,我希望他们在图片上 :)

标签: html css responsive-design responsive responsive-images


【解决方案1】:

jsFiddle

编辑

#nav_container {

        margin: 0%;
        text-align: center;
        padding-top: 5px; 
        left:5px;
        right:5px;
        width:auto;

    }

    #nav_container li {
        display: inline;
        margin: 4%;
        font-family: Arial; 
    }

    #nav_container a {
        color:#3e3e3e;
        background-color:#ffffff;
        text-decoration: none;   
    }
    #nav_container a:hover {

        background-color:#ffffff;
        color: #3e5869;
    }

    #nav_container a:visited {
        color:#357c49;
        background-color: #ffffff;
    }

    div {
        padding-top: 50px; 
        left:5px;
        right:5px;

    }

    h1 {
        text-align:center;
        margin: auto;
        width:60%;
        color: #73AD21;
        font-family: Arial;
        top:-40px;
        height: 6%;
        padding: 3%;
    }
    .content {    
	margin: auto;
    text-align: center;
    top: 5px;
    width: 596px;
    padding-bottom: 45px;
    position: relative;
}

    .media_buttons { 
	    position: absolute;
    padding: 5px;
    display: block;
    top: 30px;
    width: 0px;
    text-decoration: none;
    z-index: 1;
    list-style-type: none;

    }

    .media_buttons li {
	    list-style-type: none;
    width: auto;
    height: auto;
    margin-right: 10px;
    display: inline-block;

    }
<div class="top_page">
<ul id="nav_container">

<li><a href="about_proper.html">About</a></li>
<li><a href="articles.html">Articles</a></li>
<li><a href="news.html">News</a></li>
</div>

<hr>
<h1>Travel locally and globally</h1>

<div class="content">

<div class="media_buttons">
<ul>
<li><a href="about_proper.html"><img src="social/facebook.png" alt="facebook_social_button" style="width:30px;height:30px;"/></a></li>
<li><a href="news.html"><img src="social/twitter.png" alt="twitter_social_button" style="width:30px;height:30px;"/></a></li>
</ul>
</div>
<img src="travel.jpg" alt="Go Travel" style="text-align:center;width:504px;height:228px;"/>
</div>

【讨论】:

  • 嗨 Mools,谢谢你,问题是我希望它们在图像旁边,因此在调整页面大小时它不会与该图像重叠。
  • 你的意思是在图片的左上角?
  • 太好了。您是如何设法仅使用绝对定位的。我以为你只能在相对定位的 div 内移动它?
  • 你必须把它设为absolute,这样你就可以把它放在图片上on而不是relative,它会放在你的图片旁边,然后使用z-index:1使它成为@987654328 @大于图片​​,所以用户可以click它而不是点击图片
  • 嗨 Mols,当我实现代码时,我遇到了和以前一样的问题。它仍然重叠。当我调整页面大小(缩小)时,如何确保社交按钮和空间之间始终存在空间?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-02-15
  • 2014-04-24
  • 1970-01-01
  • 1970-01-01
  • 2012-12-21
  • 2014-05-26
  • 1970-01-01
相关资源
最近更新 更多