0

私は次のHTMLを持っています:

<div id="main">
    <div id="calendar">
    <div class="column" id="time_slots">
    </div>

        <div class="column" id="day1">
            <div class="route_container">
                <div class="date"></div>
                <button class="add_route" name="add_route" onclick="">Add New Route - 1</button>
                <div class = "truck" id="day1_route1">
                    <div class="ts8-10">J Smith</div>
                    <div class="ts10-12">10-12 AM</div>
                    <div class="ts12-2">12-2 AM</div>
                    <div class="ts2-4">2-4 AM</div>
                    <div class="ts4-6">4-6 AM</div>
                </div>
            </div>
        </div>

そして、次の CSS:

.label
{
    width:20px;
}

.table
{
    font-size: 1.2em;
}
#main
{
    border-style: solid;
    border-width: 1px;
    border-color: black; 
    width:97%;
    height:900px;
    margin:auto;
    overflow: auto; 
    white-space: nowrap;

}
h2
{
    font-size: 24px;
}
#calendar
{
    padding:1%;

}
.column
{
    border-style: solid;
    border-width: 1px;
    border-color: black; 
    min-width:10%;
    max-width:100%;
    width:17%;
    height:1000px;
    display: inline-block;
    overflow: auto;
    padding:5px;
    font-size: 0px;
}
.header
{
    padding:0;
    margin:0;
    text-align: center; 
    font-style: bold; 
}
.route_container
{
    height:100%;
    display: inline-block;
    font-size: 0px; 


    border-style: solid;
    border-width: 1px;
    border-color: black; 
    min-width:10%;
    max-width:100%;
    width:100%;
    overflow: auto;
    padding:5px;
    font-size: 0px;
}
.truck
{
    width:275px;
    height:100%;
    border-style: solid;
    border-width: 1px;
    border-color: black; 
    display:inline-block;
    margin:auto;
    font-size: 16px;
    padding:2%;

    position: relative;
}

.column#time_slots
{
    width:5%;
    min-width:5%;
    max-width: 10%; 
}
.date
{
    text-align: center;
    width:100%;
    border-style: solid;
    border-width: 1px;
    border-color: black; 
}
.column button
{
    display:block;
    width:100%;
    width:100%;
    border-style: solid;
    border-width: 1px;
    border-color: black; 
    font-size: 16px; 
}
.full_time
{
    display: none; 
}

.ts8-10, .ts10-12, .ts12-2, .ts2-4, .ts4-6
{
    border-style: solid;
    border-width: 1px;
    border-color: black; 
    width:90%;
    height:20%;
    font-size: 28px; 
    text-align: center;
    padding:5px;    
}

次の Javascript を使用して別の div を追加しています。

$(".add_route").click(function(){
        var truck = $(this).parent().find('.truck').length
        truck += 1; 
        var w = $(this).parent().width();
        $(this).parent().animate({width:(w+405)}, 1000);
        $(this).parent().parent().animate({width:(w+425)}, 1000);
        $(this).parent().append('<div class = "truck" id="'+$(this).parent().parent().attr('id')+'_route'+truck+'"><p>There are '+ truck +' routes</p></div>');
        $('#'+$(this).parent().attr('id')+'_route'+truck).hide();


        var route_num = $(this).parent().find('.truck').length;
        var route_w = (100/route_num)-1;        

        $('#'+$(this).parent().attr('id')+'_route'+truck).fadeIn(200);

        $(this).parent().parent().css("padding", "5px"); 
        console.log($(this).parent().parent().css("padding", "5px"))
        $(this).parent().find('.truck').css("margin-right", "3px"); 
   });

そして、次の結果が得られます。

ここに画像の説明を入力

ご覧のとおり、追加された div (「2 つのルートがあります」と表示されているもの) は、他の div よりもかなり低くなっています。さらに悪いことに、div (ts8-10 など) と境界線を展開してこの HTML の内容を変更すると、次のようになります。

<div class = "truck" id="day1_route1">
                    <div class="ts8-10">J Smith</div>
                    <div class="ts10-12">10-12 AM</div>
                    <div class="ts12-2">12-2 AM</div>
                    <div class="ts2-4">2-4 AM</div>
                    <div class="ts4-6">4-6 AM</div>
                </div>

オフセットはとても悪いです。実際には、最初の div (JSmith のあるもの) の一番下にあります。

これらが「インラインブロック」として設定されていることを理解しています。ご覧のとおり、調整を試みましたが、何も機能していないようです。余分なマージンやパディングの問題がないことを確認しました。Chrome Web 開発ツールを使用しても、少なくとも何も表示されません。

誰かがここで何が起こっているのか教えてもらえますか? 私は何を間違っていますか?どうすればこれを修正できますか?

4

2 に答える 2