Div高度不符合内容的高度

时间:2017-03-21 11:02:22

标签: css

我试图自动调整主要div的高度,但我无法让它发挥作用。我已经输入620px,因此您可以查看内容,但希望使其符合其内容。

CSS代码:

#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/

1 个答案:

答案 0 :(得分:1)

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

$scope.user = {};
$scope.fetchInfoById = function() {     
   $http.get("https://randomuser.me/api/?id="$scope.user.id)
      .success(function(data) {
        $scope.oneUserResult = data.results; 
   }); 
}

Updated fiddle