首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Div高度不符合内容的高度。

Div高度不符合内容的高度。
EN

Stack Overflow用户
提问于 2017-03-21 11:02:22
回答 1查看 44关注 0票数 0

我试图自动调整主div的高度,但我无法使它工作。我已经放了620‘s,这样你就可以看到内容,但想让它适合它的内容。

CSS代码:

代码语言:javascript
复制
#distributors {
}

#distributors input {
    height: 2.5em;
    visibility: hidden;
}

#distributors input.visible {
    visibility: visible !important;
}

#distributors label {
    background: #f9f9f9; 
    border-radius: .25em .25em 0 0;
    color: #888;
    cursor: pointer;
    display: block;
    float: left;
    font-size: 1em;
    height: 2.5em;
    line-height: 2.5em;
    margin-right: .25em;
    padding: 0 1.5em;
    text-align: center;
}

#distributors input:hover + label {
    background: #ddd; 
    color: #666;
}

#distributors input:checked + label {
    background: #f1f1f1; 
    color: #444;
    position: relative;
    z-index: 6;
    /*
    -webkit-transition: .1s;
    -moz-transition: .1s;
    -o-transition: .1s;
    -ms-transition: .1s;
    */
}

#content {
    background: #f1f1f1;
    border-radius: 0 .25em .25em .25em;
    min-height: 20em;
    position: relative;
    overflow: auto;
    width: 100%;
    height: 620px;
    z-index: 5;
}

#content .store-card {
    min-height: 240px;
    margin-bottom: 15px;
    display: inline-block;
}

#content .store-card img {
    margin-bottom: 10px;
}

#content .store-card h4 {
    font-weight: 700;
    margin-bottom: 0;
}

#content .store-card p {
    margin-bottom: 0;
}

#content .store-card a {
    font-weight: 700;
}

#content-1, #content-2, #content-3, #content-4 {
    opacity: 0;
    padding: 1.5em;
    position: absolute;
    display: block;
    z-index: -100;
    transition: all linear 0.3s;
}

#distributors input#tab-1:checked ~ #content #content-1,
#distributors input#tab-2:checked ~ #content #content-2,
#distributors input#tab-3:checked ~ #content #content-3,
#distributors input#tab-4:checked ~ #content #content-4 {
    opacity: 1;
    z-index: 100;
}

如果可能的话,请检查下面的jsfiddle并修复:https://jsfiddle.net/uydomdub/

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-21 11:11:36

您需要从子内容div中移除绝对位置,更改小提琴中的最后一个样式,并从内容div中移除固定高度:

代码语言:javascript
复制
#content-1,
#content-2,
#content-3,
#content-4 {
  opacity: 0;
  padding: 1.5em;
  display: none;
  transition: all linear 0.3s;
}

#distributors input#tab-1:checked ~ #content #content-1,
#distributors input#tab-2:checked ~ #content #content-2,
#distributors input#tab-3:checked ~ #content #content-3,
#distributors input#tab-4:checked ~ #content #content-4 {
  opacity: 1;
  z-index: 100;
  display:block;
}

更新小提琴

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42925230

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档