【问题标题】:Using iCheck: checkbox and label on different lines (want them inline)在不同的行上使用 iCheck:复选框和标签(希望它们内联)
【发布时间】:2026-02-01 13:15:01
【问题描述】:

我正在使用 jquery 插件 iCheck 来设置我的复选框的样式。我已经成功地做到了这一点,但现在我无法在同一行获得复选框和标签。

这里是主要代码:

<ul class="facebook-friends">

        @foreach ($friends as $friend)

        <li>
        <div class="facebook_friend">
        <input tabindex="1" type="checkbox" name="friend" id="{{$friend}}" value="{{$friend}}">
        <label for="{{$friend}}" style="display:block;">
        <span class="icon"><a href="http://www.facebook.com/{{ $friend }}"><img src="https://graph.facebook.com/{{ $friend }}/picture" alt="" height="40" width="40"></a></span>
        </label>
        </div>
        </li>

        @endforeach                     
</ul>

CSS:

.facebook_friend {
    width:150px;
}

.icon {
    width:45px;
}

ul.facebook-friends {
    margin:0;
    padding:0;
    border:0;
    overflow:hidden;
    *zoom:1;
    width:500px;
    font-family:'proxima-nova';
    font-size:12px;


    color:#999

}

ul.facebook-friends li {

    list-style-image:none;
    list-style-type:none;
    margin-left:0;
    white-space:normal;
    display:inline;
    float:left;
    padding-left:0px;

    margin: 5px;

}

iCheck 框呈现如下:

<div class="icheckbox_square-blue" style="position: relative;">
<input tabindex="1" type="checkbox" name="friend" id="3607" value="3607" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background-color: rgb(255, 255, 255); border: 0px; opacity: 0; background-position: initial initial; background-repeat: initial initial;">
<ins class="iCheck-helper" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background-color: rgb(255, 255, 255); border: 0px; opacity: 0; background-position: initial initial; background-repeat: initial initial;"></ins>
</div>

我用于复选框标签的图像出现在复选框下方的行上。你有没有看到任何事情会导致这种情况发生?我希望他们排队。我正在使用 Laravel 4。

【问题讨论】:

  • 我仍然想知道这与 laravel 有什么关系。没有人关心你在哪里生成 HTML 代码,当你对结果的样式有问题时。

标签: css laravel laravel-4 icheck


【解决方案1】:

只需在标签内移动input/checkbox,就像

<ul>
    @foreach ($friends as $friend)
        <li>
            <div class="facebook_friend">
                <label for="{{$friend}}" style="display:block;">
                    <input tabindex="1" type="checkbox" name="friend" id="{{$friend}}" value="{{$friend}}">
                        <span class="icon">
                            <a href="http://www.facebook.com/{{ $friend }}">
                                <img src="https://graph.facebook.com/{{ $friend }}/picture" alt="" height="40" width="40">
                            </a>
                        </span>
                </label>
            </div>
        </li>
    @endforeach
</ul>

DEMO HERE.

【讨论】:

  • 没有用。我相信由 iCheck 形成的“div”将标签强制到下一行。任何想法如何处理?
  • 您可以看到 iCheck 如何呈现我的问题中的输入。
  • ins 定位于absolute,如果您可以更改它,那么您可以获得所需的结果,这可能还是插件生成的?
  • 插件生成
  • 你能改一下.icheckbox { width: 20px; }吗?
【解决方案2】:

你可能错过了一个小错误,

我创建了一个示例fiddle 来解释证明,

只需像这样修改您的代码..

  <ul>
  @foreach ($friends as $friend)
    <li>
    <div class="facebook_friend">
    <input tabindex="1" type="checkbox" name="friend" id="{{$friend}}" value="{{$friend}}">
    <label for="{{$friend}}"> /* Removed display:block here */
    <span class="icon"><a href="http://www.facebook.com/{{ $friend }}"><img src="https://graph.facebook.com/{{ $friend }}/picture" alt="" height="40" width="40"></a></span>
    </label>
    </div>
    </li>
    @endforeach
  </ul> 

我已经从label 标记中删除了style="display:block",这确实是骗人的,

检查小提琴的小样本,

编辑:由于这些无法更改可能会添加更多样式的样式表,

ul.facebook-friends li {
    list-style-image:none;
    list-style-type:none;
    white-space:normal;
    display:inline;
    padding-left:0px; /* this was lfet you need to correct it*/
    margin: 5px;
    margin-left:0; /* this was over ridden by the 5px as it was specified after */
    position:relative;
}

编辑 2:更新小提琴

我已更新小提琴以验证您的代码 fiddle2 但这里也可以正常工作..!!

请提供您页面的实时链接以获得进一步的帮助,谢谢

【讨论】:

  • 没有用。我相信由 iCheck 形成的“div”将标签强制到下一行。任何想法如何处理?
  • 我认为这是唯一的问题,请尝试从 li 样式中删除左侧浮动请查看更新的答案,在我的小提琴中它正在工作,所以在这里它也应该工作,否则请发布实时页面的链接为了更好的主意。谢谢
  • 请检查更新后的 fiddle2 是否与您提供的 CSS 工作正常
  • Fiddle 不起作用,包括 icheck.min.js 在内的主机不再托管此文件
【解决方案3】:

我已经解决了一个类似的问题,我也希望复选框内联对齐,但我需要右侧的文本能够跨越 2 行而不低于复选框

Check fiddle here

似乎对齐复选框的技巧是在它周围放置另一个容器(在我的情况下为&lt;i&gt;),我定位为绝对位置,更改默认复选框容器位置会弄乱可点击区域。

<div class="rcb-recent">
<div class="rcb-recent-items">
    <!-- ROW -->
    <div class="rcb-recent-item">
        <i>
            <input type="checkbox" class="recent-cb" checked="checked" />
        </i>
        <span>
            <a href="#">1-year Master in International Cooperation &amp; Development</a>
        </span>
    </div>
    <!-- ROW -->
    <div class="rcb-recent-item">
        <i>
            <input type="checkbox" class="recent-cb" checked="checked" />
        </i>
        <span>
            <a href="#">1-year Master in International Cooperation &amp; Development</a>
        </span>
    </div>
</div>
</div>

CSS

.rcb-recent {
  width: 200px
}

.rcb-recent-item {
  position: relative;
  margin-bottom: 10px
}

.rcb-recent-item i {
  position: absolute;
  left: 0;
  top: 0;
}

.rcb-recent-item span {
  display: block;
  margin-left: 30px;
}

【讨论】:

    最近更新 更多