php - DIV的高度自动调整

标签 php css html

我正在使用 div 的 en css 代码,从 mysql 数据库中获取一些值。

它工作正常。但是,如果数据库中的值超过 1 行,则带有 div 的表格看起来不好看。

这是我正在使用的代码:

 $result = mysql_query("SELECT * FROM boxen ");
    while ($row = mysql_fetch_assoc($result))
    {
    echo '<div class="a naam">';
    echo '<a href="boxen.php?boxid=' .  $row['ID'] . '">' . $row['naam'] . '</a>';
    echo '</div>';

    echo '<div class="a datum">';
    echo $row['datum'];
    echo '</div>';

    echo '<div class="a land">';
    echo $row['land'];
    echo '</div>';

    echo '<div class="a naam">';
    echo $row['starter'];
    echo '</div>';
    }

CSS 代码调整颜色和宽度。 简短:如何固定高度?

附言我在 stackoverflow 上搜索过,但没有找到任何可以帮助我的东西,也许我使用了错误的关键字?

编辑:

<div class="inhoud">
<h2>Inhoud van de box: </h2><br />
<div class="header naam">
    Naam product
</div>
<div class="header omschrijving">
    Omschrijving
</div>
<div class="header aantal">
    Aantal
</div>
<div class="header datum">
    Datum toegevoegd
</div>
<div class="header naam">
    Naam toeveoger
</div>
<div class="header datum">
    Datum verwijderd
    </div>
<div class="header naamVerwijderaar">
    Naam verwijdereraar
</div>
<div class="header icon">
    &nbsp;
</div>
<div class="header icon">
    &nbsp;
</div>
<div class="header icon">
    SAMPLE SAMPLE SAMPLE SAMPLE SAMPLE
</div>

这是标题,但它有同样的问题。最后一列将有 2 行,如果我再添加一行,它会变得非常困惑。

CSS 代码:

/* Algemeen voor header*/
.header {
    background-color:#4DA0FF;   
    float:left;
    margin-left:4px;
    margin-bottom:4px;
    color:white;

}
/* END HEADER*/
/* ALGEMEEN OVERIZCHT*/
/* naam */
.naam{
width:200px;
height:auto;
}
/* naam die het product er uit heeft gehaald*/
.naamVerwijderaar{
width:210px;
height:auto;

}
/* datum  */
.datum{
width:150px;
height:auto;

}


/* omschrijinvg */
.omschrijving{
    width:200px;
    height:auto;

}
.aantal {
    width:80px;
    height:auto;

}
/* land */
.land{
width:150px;
height:auto;

}
inhoud{
    width:1305px;
}

我不需要这个例子的所有 css 代码!

最佳答案

你需要一张 table 来处理这类事情。

表格并不都是坏的,当用于正确类型的数据(表格数据,即最适合表格的数据类型)时,表格是完全可以接受的。

示例代码:

<style type="text/css">
    th {
        background-color: rgb(77, 160, 255);
        margin-left:      4px;
        margin-bottom:    4px;
        color:            rgb(255, 255, 255);
    }
    table caption {
        font-size:   2em;
        font-weight: bold;
    }
</style>
<table>
    <caption>Inoud van de box:</caption>
    <thead>
        <tr>
            <th>Naam product</th>
            <th>Omschrijving</th>
            <th>Antal</th>
            <th>Datum toegevoegd</th>
            <th>Naam toevegoer</th>
            <th>Datum verwijderd</th>
            <th>Naam verwijderd</th>
            <th>&nbsp;</th>
            <th>&nbsp;</th>
            <th>SAMPLE SAMPLE SAMPLE SAMPLE</th>
        </tr>
    </thead>
</table>

关于php - DIV的高度自动调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10663375/

相关文章:

javascript - 404 和 500 上的 JQuery Mobile “Error Loading Page”

PHP 正则表达式删除 <h1> 标签(及其内容)

php - 用户名和密码参数的 AFNetworking 异步 POST 请求(Objective-C iOS)

javascript - 针对移动/低速连接进行优化 - 全背景视频

javascript - 使用 jQuery 第一次调整大小后,drop 和 resize 似乎不起作用

php - HttpURLConnection setRequestMethod 无法正常工作

css - div 背景 repeat-x 的问题

css - 单击按钮更改响应和无响应的站点

html - 如何在 CSS 中的 Font Awesome 图标旁边输入文本 block ?

javascript - 站点内容扩展和收缩