如何解决div定位问题

时间:2013-08-09 16:19:04

标签: css css3 html responsive-design

我在这里有一个测试网站:

http://www.hugoproject.com/test.html

我正在尝试将第二行书图标放在第一行之下,但无论我尝试什么都行不通。以下代码显示单个书籍图标:

<div class="project">
<a href="#" class="HS" class="project-link">Arrow<span></span></a>
</div>

当我有两组代码时,会出现两个图标,当有三组代码时,会出现三个图标。但是,如果我有四组或更多组代码仍然只显示三个图标。我想要额外的代码集来使图标低于前三个。

此时,当您调整浏览器窗口大小时,这会使图标动态调整大小。我想保留此功能,并使两行图标都适合一页,这样就没有滚动条了。

有什么想法吗?

HTML

<div id="content">
<div id="home-projects-wrapper">

<h1 class="home">Hello! My name is Brandon</h1>

<div id="home-projects">
<div id="projects" class="circle">
<div class="project-group">

<div class="project">
<a href="#" class="HS" class="project-link">Arrow<span></span></a>
</div>

<div class="project">
<a href="#" class="HS" class="project-link">Arrow<span></span></a>
</div>
                                           <div class="project">
<a href="#" class="HS" class="project-link">Arrow<span></span></a>
</div>

<div class="project">
<a href="#" class="HS" class="project-link">Arrow<span></span></a>
</div>

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

CSS

#container {
    transition: left .3s;
    -moz-transition: left .3s;
    -webkit-transition: left .3s;
    position: absolute;
    width: 100%;
    height: 100%;
    left: 0;
    overflow-x: hidden;
}
#container.open {
    left: 270px;
    position: absolute;
    width: 100%;
    height: 100%;
    transition: left .3s;
    -moz-transition: left .3s;
    -webkit-transition: left .3s;
    overflow-x: hidden;
}
#content {
    width: 80%;
    max-width: 1170px;
    margin: 7% auto;
    position: relative;
    font-size: 14px;
    line-height: 22px;
    color: #777777;
}
.page-template-page-templateshome-php #content {
    width: auto;
    margin: 0 auto;
    position: static;
}
.single-post #content { width: 60% }
#home-projects {
    text-align: center;
    overflow: hidden;
    position: relative;
}
#projects { width: 100% }
.project-group {
    width: 100%;
    height: 100%;
    position: absolute;
}
.project {
    float: left;
    text-align: center;
    width: 33.3%;
    height: 100%;
}
.project-link {
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
    background-color: #adadad;
    position: relative;
    overflow: hidden;
    display: inline-block;
    width: 80%;
}
.circle .project-link,
.circle .project-link .hover {
    border-radius: 100%;
    -moz-border-radius: 100%;
    -webkit-border-radius: 100%;
}
.project-link .hexagon-top {
    content: '';
    display: block;
    position: absolute;
    left: 0;
    border-style: solid;
    border-bottom-color: transparent;
    border-left-color: #dfdfdf;
    border-right-color: #dfdfdf;
    width: 0;
    height: 0;
    z-index: 2;
}
.project-link .hexagon-bottom {
    content: '';
    display: block;
    position: absolute;
    left: 0;
    bottom: 0;
    border-style: solid;
    border-top-color: transparent;
    border-left-color: #dfdfdf;
    border-right-color: #dfdfdf;
    width: 0;
    height: 0;
    z-index: 2;
}
.project-link .hover {
    position: absolute;
    width: 100%;
    height: 100%;
    font-size: 14px;
    text-align: center;
    color: #fff;
    background: #ec6136;
    text-decoration: none;
    text-transform: uppercase;
    display: block;
    opacity: 0;
    transition: all .3s;
    -moz-transition: all .3s;
    -webkit-transitin: all .3s;
}
.project-link .hover-text {
    display: block;
    margin-top: 45%;
}
.project-link .hover-text:after {
    content: '>';
    font-family: 'icon';
    font-size: 12px;
    margin-left: 15px;
}
.project-link:hover > .hover { opacity: .9 }

3 个答案:

答案 0 :(得分:1)

看起来你的css(style.css)中有这个:

.project-group{
    width: 100%;
    height: 100%;
    position: absolute;
}

只需按相对值切换绝对值,就会出现第二行。这对你来说够了吗?

.project-group{
    width: 100%;
    height: 100%;
    position: relative;
}

答案 1 :(得分:0)

我建议您从样式表中的height: 100%.project类中删除.project-group。我的猜测是,在元素上设置100%的高度与来自overflow: hidden的{​​{1}}语句的交互性很差。

答案 2 :(得分:0)

首先,您必须将#projects的高度加倍,并将.project的高度设置为50%。

你是什么意思:

  

此时,当您调整浏览器窗口大小时,这会使图标动态调整大小。我想保留此功能,并使两行图标都适合一页,这样就没有滚动条了。