根据另一个动态div标签的数据展开div标签

时间:2014-03-27 14:37:44

标签: html css

'我试图将带有id名称结果的div标签与div标签数据的大小相同,这将是动态的。我该怎么做呢?

谢谢

<!DOCTYPE html>
<html>
<head>
<style>
#main
{
border:5px solid black;
float:left;
}

#result
{
border:5px solid red;
float:left;
width: 200px; 
}

#data
{
border:5px solid red;
float:left;
width: 200px; 
}
</style>
</head>
<body>

<h1>Test</h1>

<div id="main">
<div id="result">Result:</div>
<div id="data">Dynamic Data etc...blah Dynamic Data etc...blah Dynamic Data etc...blah     Dynamic    Data etc...blah Dynamic Data etc...blah Dynamic Data etc...blah Dynamic Data etc...blah Dynamic Data etc...blah </div>
</div> 
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您可以使用表格布局:

<强> Demo using table

<table id="main">
    <tr>
        <td id="result">Result:</td>
        <td id="data">Dynamic Data etc...blah Dynamic Data etc...blah Dynamic Data etc...blah     Dynamic    Data etc...blah Dynamic Data etc...blah Dynamic Data etc...blah Dynamic Data etc...blah Dynamic Data etc...blah </td>
    </tr>
</table> 

或者只使用display: table-cell#data div的#result属性:

<强> Demo using display: table-cell

#data, #result
{
    border:5px solid red;
    display: table-cell;
    width: 200px; 
}