html - CSS 标题图像 div

标签 html css

我想在我的页面中使用 div。图像的标题位于顶部,然后是菜单 div。 我用图像设置了第四个 div,它的工作。但是当我设置第二个 div 时,它在第一个 div 中。我该如何解决这个问题?

     <div id="slideshow">
    <div>
        <img src="http://img2.wikia.nocookie.net/__cb20100409185740/gtawiki/images/e/e7/Fort_carsonn.jpg" width="1200" height="300" />
    </div>
    <div>
        <img src="http://i12.photobucket.com/albums/a230/buetforasif/FortCarson_ataglance.jpg" width="1200" height="300" />
    </div>
 </div>
 <div id="menu" class="div_menu">

 </div>

enter image description here

#slideshow { 
width: 1200px;
height: 300px;
position: absolute;
left: 0;
right: 0;
margin: auto;
box-shadow: 0 0 20px rgba(0,0,0,0.4); 
}

#slideshow > div { 
position: absolute; 
top: 0px; 
left: 0px; 
right: 0px; 
bottom: 0px; 
}

div.div_menu {
background-color: #F5F5F5;
width: 1200px;
height: 50px;

position: fixed;
left: 0;
right: 0;
margin: auto;
}

脚本:

<script>
    $(function() {

        $("#slideshow > div:gt(0)").hide();

        setInterval(function() { 
          $('#slideshow > div:first')
            .fadeOut(2000)
            .next()
            .fadeIn(2000)
            .end()
            .appendTo('#slideshow');
        },  4000);

    });
</script>

最佳答案

你的问题是因为 #slideshow 中的 position: absolute;,所以编辑你的 CSS 并试试这个:

#slideshow {
    width: 1200px;
    height: 300px;
    position: relative;
    margin: auto;
    box-shadow: 0 0 20px rgba(0,0,0,0.4);
}

或者如果你出于某种原因想要保持 position: absolute,将 margin-top 添加到 .div_menu,然后试试这个:

div.div_menu {
    background-color: #F5F5F5;
    width: 1200px;
    height: 50px;
    position: fixed;
    left: 0;
    right: 0;
    margin: auto;
    margin-top: 300px; /* Same as the height of #slideshow */
}

希望这对你有帮助..

关于html - CSS 标题图像 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25179259/

相关文章:

javascript - 样式选择选项最佳实践

javascript - Meteor 将 id 传递到链接中

javascript - Angular 标记错误

javascript - 部分隐藏的 jQuery 倒数计时器

jquery - 仅在默认页面 NopCommerce 上显示图像 slider ?

css - 为什么我的 div 太宽了?

html - 使用 XML/XSL 解析器定义 CSS 样式

javascript - 通过动画向左使 div 消失

html - css容器内的段落格式

javascript - 单击时如何显示文本?