0

我在放置图像和输入字段时遇到问题。它们以交错的方式放置。我希望它们彼此相邻放置,在一条水平直线上。您可以在下图中看到问题。

图片

现场演示

HTML:

    <div id="wrapper">

            <!--Inbox list and button to add a card-->
            <div id="inboxList" class="cellContainer">
                <p style="display: inline">Inbox</p> 
                <!--Button to add a Card-->
                <input type="button" id="AddCardBtn" value="+ Add a Card..."/> 
                <hr class="fancy-line"/> <br/>

                <!--Card div-->
                <div id="userAddedCard"> <br/>
                    <div>

                    </div>
                </div>
            </div>


        </div>

查询:

var $div = $('<div />').addClass('sortable-div'); 
    $('<img />', { "src": "/Pages/Images/calendar.png" }).addClass('image').appendTo($div);
    $('<input/>', { "type": "text", "class": "ctb" }).addClass('ctb').appendTo($div);

CSS:

.ctb {
    display:inline-block;
    width: 20px;    
    padding-left:2%;
}

.image {
    display:inline-block;
    height:19px;
    width:19px;
    padding-top:7%;
    padding-left:5%;

}
4

5 回答 5

2

如果您将 vertical-align: bottom 添加到您的 .image 元素中,则应该正确排列所有内容。

于 2014-04-04T08:26:48.337 回答
1

为类CSS添加

.ctb
{
vertical-align: bottom;
padding: 0px 0px 0px 2%;
margin: 0px;
}
.image
{
vertical-align: bottom;
}
于 2014-04-04T08:30:12.023 回答
1

这是我的小提琴。更新了以下课程

CSS:

.image {
    display:block;
    float:left;
    height:19px;
    width:19px;
    padding-left:5%;
     margin-top: 0.4%;
}


#inboxList {
    width: 275px;
    height: 700px;
    background-color: #f0f0f0;
    border: 1px solid black;
    margin-left: 0.5%;
    margin-top: 0.4%;
    border-radius: 10px;
    box-shadow: 7px 7px 7px #828282;
    overflow: auto;
    display:inline-block;
}
于 2014-04-04T08:30:44.667 回答
1

请检查更新的小提琴,

演示更新

<!--Card div-->
        <div id="userAddedCard"> <br/>

        </div>
  .image {
   display:inline-block;
   height:19px;
   width:19px;
   /*padding-top:7%;
   padding-left:5%;
   padding-right:2%;*/
   vertical-align:top;

}

干杯:)

于 2014-04-04T08:29:00.083 回答
1

您只需要同时应用于display: block;文本和图像而不是display:inline-block;

.ctb {
    display: block;
    width: 20px;    
    padding-left:2%;
}

.image {
    display: block;
    height:19px;
    width:19px;
    padding-top:7%;
    padding-left:5%;

}

更新小提琴

于 2014-04-04T08:29:44.247 回答