将元素并排放置

时间:2013-01-17 04:41:18

标签: html css

我有一点问题。我试图将一些图像并排放在一起,所以它看起来像一个投资组合。实现这一目标的最佳方式是什么。先感谢您。你可以参考jsfiddle:

http://jsfiddle.net/cntra/E7Ydz/

这[HTML]如下:

<div id="portfolio" style="height: 3020px;">

 <div id="project" class="cms design html-css " data-col="1" data-row="0" style="right: 0px; opacity: 1; top: 0px;">
    <div id="workEntry1" class="workEntry">

       <div id="thumbAttachment">
                    <div id="inThumb">
                    <img src="http://www.enjoythis.co.uk/wp-content/files_mf/work_thumbnail275.jpg">
        </div>

         <div id="blackCross"> <a href="http://www.enjoythis.co.uk/jane-stockdale/"><img src="http://www.enjoythis.co.uk/wp-content/themes/enjoyThis/images/thumb_transparency.png"></a></div>

          </div>


        <!--<div id="attachmentShadowThumb"></div>-->


        <div id="workTitle">
                </div>
            <div id="workTags">


            </div>
      </div>
    </div>


          <div id="project" class="design illustration html-css " data-col="2" data-row="0" style="right: 0px; opacity: 1; top: 0px;">
    <div id="workEntry2" class="workEntry">

       <div id="thumbAttachment">
                    <div id="inThumb">
                    <img src="http://www.enjoythis.co.uk/wp-content/files_mf/work_thumbnail2.jpg">
        </div>

         <div id="blackCross"> <a href="http://www.enjoythis.co.uk/street-child-world-cup-i-am-somebody/"><img src="http://www.enjoythis.co.uk/wp-content/themes/enjoyThis/images/thumb_transparency.png"></a></div>

          </div>


        <!--<div id="attachmentShadowThumb"></div>-->


        <div id="workTitle">
      </div>
            <div id="workTags">                 

            </div>
      </div>
    </div>
          <div id="project" class="app database design " data-col="0" data-row="1" style="right: 0px; opacity: 1; top: 0px;">
    <div id="workEntry3" class="workEntry">

       <div id="thumbAttachment">
                    <div id="inThumb">
                    <img src="http://www.enjoythis.co.uk/wp-content/files_mf/pgtips_thumb37.jpg">
        </div>

         <div id="blackCross"> <a href="http://www.enjoythis.co.uk/pg-tips-vs-january/"><img src="http://www.enjoythis.co.uk/wp-content/themes/enjoyThis/images/thumb_transparency.png"></a></div>

          </div>


        <!--<div id="attachmentShadowThumb"></div>-->


        <div id="workTitle">
        </div>
            <div id="workTags">


            </div>
      </div>
    </div>

和[css]:

#project{
    float:left;
    position:relative;
    padding: 0px 0px 0px 2px;
    height:250px;
    width:325px;
    display: inline;
}

.workEntry{ 
    width:310px;
    overflow:hidden;
}



#thumbAttachment{
    float:left;
    width: 310px;
    height:200px;
    overflow: hidden;
}

#inThumb{
    float:left;
}

#blackCross{
    float:left;
    width: 310px;
    height:200px;
    margin-top:-200px;
    khtml-opacity:0;
    -moz-opacity:0;
    -ms-filter:"alpha(opacity=0)";
    filter:alpha(opacity=0);
    opacity:0;

}

#blackCross:visited{

    khtml-opacity:0;
    -moz-opacity:0;
    -ms-filter:"alpha(opacity=0)";
    filter:alpha(opacity=0);
    opacity:0;
}

#blackCross:hover{
    khtml-opacity:1;
    -moz-opacity:1;
    -ms-filter:"alpha(opacity=100)";
    filter:alpha(opacity=100);
    opacity:100;
}

2 个答案:

答案 0 :(得分:3)

.workEntry{ 
    width:310px;
    overflow:hidden;
    float:left;//make each element float left
}

#project{
    float:left;
    position:relative;
    padding: 0px; //no padding should be here
    height:250px;
    width:310px;//should be same size as .workEntry
    display: inline;
    overflow:hidden;//trick to ensure all elements fit in portfolio
}

你也可以将它放在工作条目列表的末尾,以阻止后续元素脱节:

<div style="clear:both;"></div>

答案 1 :(得分:2)

您将div.project的宽度设置为325px,但图像仅为310px。

http://jsfiddle.net/E7Ydz/2/

#project{
float:left;
position:relative;
padding: 0px 0px 0px 2px;
height:200px;
width:309px;
display: inline;

}