javascript - 如何调整一个div属性使其可以根据内容展开

标签 javascript html css

我正在制作一个包含多个部门的应用程序。在一个特定的部门中,内容不止一行。正如我们所知,它将使 div 可滚动以让我们看到内容。

但在这种情况下,我希望 div 根据内容调整其高度,以便一次性看到所有内容,并且不应该有滚动条......有什么办法吗??

HTML:

<!DOCTYPE html>
<html ng-app='myApp'>
<head>
<meta charset="ISO-8859-1">
<meta name="viewport" content="initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
<title>Screen1</title>
<link rel="stylesheet" type="text/css" href="Screen1.css">
</head>
<body BGCOLOR="#e9ecf1" ng-controller='screen1Controller'>
        <div class="main">
        <div id="header1Main">
            <div id="header1">Timeliness</div>
            <div id="header2">

            </div>
        </div>
         <div class="clear"></div>
           <div class="opporMain">
                <div class="opporHeader">
                    <div class="circleIcon">I</div>
                    <div class="opporHeading">Heading is the main thing that we need now it is a very important propert and wee need it we will have the thing according to the needs .........</div>
                </div>
            <div class="lineDiv"></div>
            <div class="opporContent">
                <div class="contentStatus">one three</div>
                <div class="contentStatusDate">main thing</div>
                <div class="clearContent"></div> 
                <div class="contentMainContent">"Things have been changed according to the needs"</div>
                <div class="contentUpdateTime"><img src="images/timeline-3.png" alt="clock">&nbsp;Just Now</div>
                <div class="clearContent"></div> 
                <div class="contentUpdateBy">updated by <font color="black">ziong zhu</font></div>     
            </div>
            <div class="lineDiv"></div>
            <div class="opporComment">
                <img class="commentIcon" src="comment.png" alt="img"/>
                <div class="opporCommentContent">Comments</div>            
                <div class="opporCommentDetails">3 Comments</div>
            </div>
         </div>


            <div class="clearOppr"></div>


            </div>



      </div>
        <script type="text/javascript" src="js/angular-1.0.1.js"></script>
        <script src="js/application.js"></script>
        <script src="js/Controller.js"></script>
    </body>
</html>

CSS:

/*ROBOTO SLAB*/


@font-face {
     font-family: 'RobotoSlab-bold';
     src:url('fonts/RobotoSlab-Bold.woff') format('woff');
}

@font-face {
     font-family: 'RobotoSlab-light';
     src:url('fonts/RobotoSlab-Light.woff') format('woff');
}

@font-face {
    font-family: 'RobotoSlab-regular';
    src:url('fonts/RobotoSlab-Regular.woff') format('woff');
}

@font-face {
    font-family: 'RobotoSlab-thin';
    src:url('fonts/RobotoSlab-Thin.woff') format('woff');
}



/*ROBOTO*/

@font-face {
    font-family: 'Roboto-regular';
     src:url('fonts/Roboto-Regular-webfont.woff') format('woff');
}


@font-face {
    font-family: 'Roboto-bold';
    src:url('fonts/Roboto-Bold-webfont.woff') format('woff');
}


@font-face {
    font-family: 'Roboto-thin';
    src:url('fonts/Roboto-Thin-webfont.woff') format('woff');
}

@font-face {
    font-family: 'Roboto-light';
    src:url('fonts/Roboto-Light-webfont.woff') format('woff');
}

@font-face {
    font-family: 'Roboto-medium';
    src:url('fonts/Roboto-Medium-webfont.woff') format('woff');
}


    body 
    {   
    margin:0px; 
    }
#header1Main
{
  background-color:#ffffff;
  overflow:auto;
}
#header1 {
    display:inline-block;
    font-family:Roboto-regular;
    font-size: 12px;
    color:#4f4f51;
    height: 36px;
    width:70%;
    margin-left: 18px;
    vertical-align: middle;
    line-height: 36px;
    float: left;
    overflow: hidden;
}
#header2 {
    display:inline-block;
    margin-right:20%;
    right:0px;
    float:right;
    margin-right: 14px;
    vertical-align: middle;
    line-height: 36px;

}
.img
{
    height:15px;
    width:15px;
}
.opporMain {

-webkit-box-shadow: 0px 1px 1px 1px rgba(194, 194, 194, 0.4);
-moz-box-shadow:    0px 1px 1px 1px rgba(194, 194, 194, 0.4);
box-shadow:         0px 1px 1px 1px rgba(194, 194, 194, 0.4);

    /*-webkit-box-shadow: 1px 1px 2px 1px rgba(194,194,194,0.4);
-moz-box-shadow: 1px 1px 2px 1px rgba(194,194,194,0.4);
    box-shadow: 1px 1px 2px 1px rgba(194,194,194,0.4);*/
margin-left:12px;
    margin-right:12px;
}
.opporHeader {
    clear:both;
    position:relative;
    display:inline-block;
    display:block;
    background-color:#ffffff;
    overflow:auto;

    min-height:40px;

}
.clear {
    clear:both;
    height:12px;
}
.clearOppr {
    clear:both;
    height:10px;
}
.circleIcon {
    float:left;
    display:inline-block;
    width: 28px;
    height: 28px;
    margin-top:6px;
    -wsebkit-border-radius: 14px;
    -moz-border-radius: 14px;
    border-radius: 14px;
    background-color:#ffb400;
    margin-left: 8px;
    text-align: center;
    font-family: Roboto-Light;
    font-size:18px; 
    color:White;
    vertical-align: middle;
    line-height: 25px;
}
.opporHeading {
    position: absolute;
    float: right;
    display: inline-block;
    font-family: Roboto-bold;
    font-weight: 700;
    font-size: 14px;
    column-rule: #000;231f20;
    margin-top: 10px;
    margin-left: 8px;
}
hr {
    clear:both;
    padding:0px;
    margin:0px;
}
.lineDiv {
    border-bottom: 1px solid #c2c2c2;


}
.opporContent {

    background-color:#ffffff;
    overflow:auto;

    padding-bottom:12px;    

}
.opporComment
{
    height:30px;
    background-color:#ffffff;
    overflow:auto;

}
.contentStatus
{

    display: inline-block;
    float:left;
    font-family:RobotoSlab-Regular;
    font-weight:400;
    font-size:13px;
    color:#4554a5;
    margin-top:10px;   
    margin-left:8px;

}
.contentStatusDate
{

    display: inline-block;
    float:left;
    font-family:RobotoSlab-Bold;
    font-size:13px;
    font-weight:700;
    color:#4554a5;
    margin-top:10px;   
    margin-left:5px;

}
.contentMainContent
{
    font-family:'RobotoSlab-Light';
    font-weight: 300;
    font-size:12px;
    margin-top:8px;    
    margin-left:8px;
}
.clearContent
{
    clear:both;    
}
.contentUpdateTime
{

    float:right;
    font-family:Roboto-Light;
    font-weight:100;
    font-size:10px;    
    color:#b1b3b6;
    margin-top:20px;
    margin-right:10px;

}
.contentUpdateBy
{
    float:right;
    font-family:Roboto-Light;
    font-size:12px;    
    font-weight:300;
    color:#b1b3b6;
    margin-top:4px;
    margin-right:10px;

}    

.opporCommentContent
{
    display: inline-block;
    float:left;
    font-family: Roboto-Medium;
    font-weight: 500;
    font-size:12px;
    margin-top:8px;
    margin-left:6px;
    color:#4f4f51;
}
.commentIcon
{
    display: inline-block;
    float:left;
    margin-top:8px;
    margin-left:8px;
}
.opporCommentDetails
{
    float:right;
    margin-top:8px;
    margin-right:10px;
    font-family: Roboto-Light;
    font-size:12px;
    color:#b1b3b6;
    }

http://jsfiddle.net/tvaibhav/4ou13gts/

最佳答案

我已经更改了 .circleIcon.opporHeading 的 CSS:

.circleIcon {
    position: absolute;
    top: 0;
    left: 0;
    width: 28px;
    height: 28px;
    margin-top:6px;
    -wsebkit-border-radius: 14px;
    -moz-border-radius: 14px;
    border-radius: 14px;
    background-color:#ffb400;
    margin-left: 8px;
    text-align: center;
    font-family: Roboto-Light;
    font-size:18px; 
    color:White;
    vertical-align: middle;
    line-height: 25px;
}

.opporHeading {
    display: inline-block;
    font-family: Roboto-bold;
    font-weight: 700;
    font-size: 14px;
    column-rule: #000;231f20;
    margin-top: 8px;
    margin-bottom: 8px;
    padding-left: 45px;
}

JSFiddle:here

关于javascript - 如何调整一个div属性使其可以根据内容展开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27637987/

相关文章:

javascript - 我可以使用 cron 表达式来开始和结束工作吗

javascript - 无法在下拉菜单中使用 .hasClass ("active") 方法

css - 无法应用显示 :flex to body element of iframe on Safari?

javascript - jQuery - 在函数中使用计算+变量来改变css

javascript - 基于node.js服务器setTimeout()更改html文本

javascript - 在我的日期验证中合并前导零

javascript - 单击按钮时使字段可编辑

html - 针对特定 block 级元素的最简单方法是什么

Javascript - 在 div 内移动多个图像,并带有边框控制

css - 子元素延伸过去的容器元素