浮动物品垂直对齐

时间:2014-03-18 14:34:41

标签: html css css-float alignment vertical-alignment

我不知道为什么,但我的浮动图像div class="social">...</div>停止正常工作。我的目标:垂直对齐图像,就像一列。

检查设计,更容易理解:design preview

它们位于窗口/浏览器屏幕的右侧,效果为:hover,但现在无效。

代码有什么问题?

继承我的JSfiddle

HTML

<div id="home">

        <div id="nav">
            <div class="container clearfix">
                    <ul id="menu">
                        <li><a href="#home">Home</a></li>
                        <li><a href="#services">Serviços</a></li>
                        <li><a href="#team">Equipa</a></li>
                        <a href="#" id="logo" alt="Style Euclides"><img src="http://styleeuclides.site50.net/img/logo.png" alt="Logo Style Euclides" width="90px" height="40px"></a> 
                        <li><a href="#space">Espaço</a></li>
                        <li><a href="#gallery">Galeria</a></li>
                        <li><a href="#contact">Contatos</a></li>
                    </ul>
            </div>
        </div>

                <div class="social">
                    <a href="http://www.facebook.com" target="_blank"><img src="http://styleeuclides.site50.net/img/fb.png" alt="facebook"></a>
                    <a href="http://www.instagram.com" target="_blank"><img src="http://styleeuclides.site50.net/img/ins.png" alt="instagram"></a>
                    <a href="http://www.twitter.com" target="_blank"><img src="http://styleeuclides.site50.net/img/twi.png" alt="twitter"></a>          
                        </div></div>

CSS

#home .social{ /* SOCIAL ICONS */
    display: inline-block;
    position: fixed;
    z-index: 1;
}

#home .social a{
    float: right;
    padding: 1px;
    opacity: 0.7;
    margin-right: auto;
    margin-left: auto;
}

#home .social a:hover{
    opacity: 1.0;
}

#home .social img{
    top: 0;  
    bottom: 0;  
    left: 0;  
    right: 0; 
    margin-top: 2px;
    margin-top: 150px;
}

4 个答案:

答案 0 :(得分:1)

我已经更新了你的小提琴,以反映我的想法。

http://jsfiddle.net/aq3T7/1/

#home .social{ /* SOCIAL ICONS */
float: right;
display: inline-block;
position: fixed;
z-index: 99;
right: 0;
top:150px;
}

#home .social a{
clear:both;
display:block;
padding: 1px;
opacity: 0.7;
margin-right: auto;
margin-left: auto;
}

#home .social a:hover{
opacity: 1.0;
}

#home .social img{
margin-top: 2px;
}

此外,我还删除了一些元素上不必要的边距。 但基本上,你的A标签是内联元素,它们会自然地显示在一起。 如果你将它们作为块元素,它们将占用它们自己的水平行(最多为其父级的宽度)。这是CSS最重要和最基本的概念。

答案 1 :(得分:1)

更新了 fiddle : - 增加顶部:150px;和宽度:40px;对于社会div,并重新审视了图像的边缘。

#home .social{ /* SOCIAL ICONS */
float: right;
display: inline-block;
position: fixed;
z-index: 99;
right: 0;
width:40px;
top:150px;
}

#home .social a{
padding: 1px;
opacity: 0.7;
margin-right: auto;
margin-left: auto;
}

#home .social a:hover{
opacity: 1.0;
}

#home .social img{
}

答案 2 :(得分:0)

试试这个:

   #home .social{ /* SOCIAL ICONS */
        position: absolute;
        z-index: 1;
        right: 0;
    }

    #home .social a{
        float: right;
        padding: 1px;
        opacity: 0.7;
        margin-right: auto;
        margin-left: auto;
    }

    #home .social a:hover{
        opacity: 1.0;
    }

    #home .social img{

    }

答案 3 :(得分:0)

你在这里交配,为你排序。 http://jsfiddle.net/aq3T7/

#home .social{ /* SOCIAL ICONS */
    position: fixed;
    top: 110px;
    right: 10px;
    z-index: 1;
}

#home .social a{
    opacity: 0.7;
}

#home .social a:hover{
    opacity: 1.0;
}

#home .social img{
    float: right;
    clear: right;
    margin-top: 5px;
}