1

我目前正在做我的第一年作业(考试作业)。我对绝对定位的文章有疑问,即在相对定位的文章中。为此,它似乎必须是绝对定位的,但是当内容变大时,它不会自动扩展自身的高度。谁能帮我获得一个灵活的高度,而不破坏其余的布局?

content 是相对的 content-1 等是绝对的。

测试页面

html

 <div class="content">
        <div class="content-1">
            <article id="info_about"></article>
            <article id="google_map"></article>
            <article id="misc_info" class="clearfix"></article>
        </div>
        <div class="content-2">

        </div>
        <div class="content-3">

        </div>
        <div class="content-4">

        </div>
    </div>

CSS:

.tabs {
    position: relative;
    margin: 40px auto;
    width: 100%;
}

.tabs input {
    position: absolute;
    z-index: 999;
    width: 120px;
    height: 40px;
    left: 0px;
    top: 0px;
    opacity: 0;
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
    filter: alpha(opacity=0);
    cursor: pointer;
}
.tabs input#tab-2{
    left: 120px;
}
.tabs input#tab-3{
    left: 240px;
}
.tabs input#tab-4{
    left: 360px;
}

.tabs label {
    background: rgba(30, 30, 30, 0.8);
    font-size: 10pt;
    line-height: 40px;
    height: 40px;
    position: relative;
    padding: 0 20px;
    float: left;
    display: block;
    width: 80px;
    color: #ffffff;
    letter-spacing: 1px;

    text-align: center;
text-shadow: 1px 1px 1px rgba(255,255,255,0.3);

    box-shadow: 2px 0 2px rgba(0,0,0,0.1), -2px 0 2px rgba(0,0,0,0.1);

    /* CSS3 TRANSITION */
    -webkit-transition-property: background;
    -webkit-transition-duration: 0.2s;
    -moz-transition-property: background;
    -moz-transition-duration: 0.2s;
    -o-transition-property: background;
    -o-transition-duration: 0.2s;
    transition-property: background;
    transition-duration: 0.2s;
}

.tabs label:after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 100%;
    height: 2px;
    display: block;
}

.tabs input:hover + label {
    background: rgba(40, 40, 40, 0.8);
}

.tabs label:first-of-type {
    z-index: 4;
    box-shadow: 2px 0 2px rgba(0,0,0,0.1);
}

.tab-label-2 {
    z-index: 3;
}

.tab-label-3 {
    z-index: 2;
}

.tab-label-4 {
    z-index: 1;
}

.tabs input:checked + label {
    background: rgba(0, 0, 0, 0.8);
    z-index: 6;
}

.clear-shadow {
    clear: both;
}

.content {
    position: relative;
    width: 100%;
    background-color: red;
    z-index: 5;
    min-height: 480px;
}

.content div {
    position: absolute;
    height: 100%;
    top: 0;
    left: 0;
    z-index: 1;
    opacity: 0;

    -webkit-transition: opacity linear 0.1s;
    -moz-transition: opacity linear 0.1s;
    -o-transition: opacity linear 0.1s;
    -ms-transition: opacity linear 0.1s;
    transition: opacity linear 0.1s;
}

.tabs input.tab-selector-1:checked ~ .content .content-1,
.tabs input.tab-selector-2:checked ~ .content .content-2,
.tabs input.tab-selector-3:checked ~ .content .content-3,
.tabs input.tab-selector-4:checked ~ .content .content-4 {
    z-index: 100;
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
    filter: alpha(opacity=100);
    opacity: 1;

    -webkit-transition: opacity ease-out 0.2s 0.1s;
    -moz-transition: opacity ease-out 0.2s 0.1s;
    -o-transition: opacity ease-out 0.2s 0.1s;
    -ms-transition: opacity ease-out 0.2s 0.1s;
    transition: opacity ease-out 0.2s 0.1s;
}
.content div h2,
.content div h3{
    color: #398080;
}
.content div p {
    font-size: 14px;
    line-height: 22px;
    font-style: italic;
    text-align: left;
    margin: 0;
    color: #777;
    padding-left: 15px;
    font-family: Cambria, Georgia, serif;
    border-left: 8px solid rgba(63,148,148, 0.1);
}


/* CONTENT PAGES*/

/* om os */

article#info_about{
    width: 530px;
    background: rgba(0, 0, 0, 0.8);
    height: 480px;
    margin-right: 20px;
    float: left;
}

article#google_map{
    width: 350px;
    height: 350px;
    background: rgba(0, 0, 0, 0.8);
    margin-bottom: 20px;
    float: left;
}

article#misc_info{
    width: 350px;
    height: 110px;
    background: rgba(0, 0, 0, 0.8);
    float: left;
}
4

1 回答 1

0

我不确定您为什么使用单选按钮进行导航。我建议从一个简单的 jQuery 选项卡解决方案重新开始并使用类似的东西,http://css-tricks.com/examples/OrganicTabs/但我能够通过以下更改让您的 div 与内容一起增长:

HTML 向 content-1 到 content-4 添加一个 clearfix 类。

例子:<div class="content-1 clearfix">

CSS

.content div {
opacity: 0;
-webkit-transition: opacity linear 0.1s;
    -moz-transition: opacity linear 0.1s;
    -o-transition: opacity linear 0.1s;
    -ms-transition: opacity linear 0.1s;
    transition: opacity linear 0.1s;
}

.content-2, .content-3, .content-4{
position: absolute;
top: 0;
}


article#info_about {
width: 530px;
min-height:480px;
background: rgba(0, 0, 0, 0.8);
margin-right: 20px;
float: left;
}
于 2012-12-15T20:38:31.163 回答