【问题标题】:Making text show on right side of div使文本显示在 div 的右侧
【发布时间】:2013-09-30 23:06:59
【问题描述】:

Here 是小提琴。我正在制作一个购物清单网络应用程序,当您单击按钮时,它会出现一个复选框和您想要的内容。我想设计我的复选框,所以我自己做了。但是当我勾选复选框时,它附带的文本会出现在 div 的底部。

附:代码是整个部分。

HTML(整个,而不仅仅是复选框):

<div id='top'>Kitchen List</div>
<br />
<input type='text' id='input'><button id='click'>Add</button>
<ol>

</ol>
<div id='error'>Please enter a grocery item<br /><button id='eb'>Close</button></div>

CSS:

body {
    margin: 0;
    padding: 0;
    background: #252525;
    color: #96f226
}
#top {
    width: 100%;
    height: 40px;
    background: #96f226;
    text-align: center;
    font-size: 30px;
    color: #252525;
}
#input {
    background: #4a4a4a;
    border: 1px solid #454545;
    color: #96f226;
}
#input:hover {
    background: #656565;
}
#input:focus {
    box-shadow: 0 0 30px #96f226
}
#click {
    background: #4a4a4a;
    border: 1px solid #454545;
    border-radius: 0;
    color: #96f226;
    cursor: pointer;
}
#click:hover {
    background: #656565;
}
#click:active {
    box-shadow: 0 0 30px #96f226;
}
#error {
    height: 55px;
    width: 100%;
    background: red;
    text-align: center;
    font-size: 23px;
    color: orange;
}
#eb {
    background: orange;
    color: red;
    border-radius: 0;
    border: 0;
    cursor: pointer
}
#eb:hover {
    background: #e59400;
}
#eb:active {
    box-shadow: 0 0 30px #e59400;
}
.check {
    width: 15px;
    height: 15px;
    background: #4a4a4a;
}

JS/jQuery:

$(document).ready(function(){
    $('#error').hide();
    $('#click').click(function(){
        var i = $('#input').val();
        if (i != "") {
            $('ol').prepend('<div class="check"></div> ' + i + '<br /><br />');
        }
        else {
            $('#error').show();
            $('#eb').click(function(){
                $('#error').hide();
            });
        }
    });
});

【问题讨论】:

    标签: jquery html text text-alignment


    【解决方案1】:

    将您的文本 (i) 放在一个 div 中,并将两个 div 设置为 display:inline-block。

    $(document).ready(function(){
     $('#error').hide();
     $('#click').click(function(){
        var i = $('#input').val();
        if (i != "") {
            $('ol').prepend('<div class="check" style="display:inline-block"></div> <div style="display:inline-block">' + i + '</div><br /><br />');
        }
        else {
            $('#error').show();
            $('#eb').click(function(){
                $('#error').hide();
            });
        }
     });
    });
    

    【讨论】:

    • 哇!谢谢!+1!接受!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-06
    • 2016-02-11
    • 1970-01-01
    • 2019-01-09
    • 2011-06-24
    • 1970-01-01
    相关资源
    最近更新 更多