首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用iCheck:复选框和不同行上的标签(希望它们是内联的)

使用iCheck:复选框和不同行上的标签(希望它们是内联的)
EN

Stack Overflow用户
提问于 2013-10-04 21:47:21
回答 3查看 5.1K关注 0票数 0

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

以下是主要代码:

代码语言:javascript
复制
<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:

代码语言:javascript
复制
.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框呈现如下所示:

代码语言:javascript
复制
<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。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-10-08 14:58:07

把你的input/checkbox移到标签里,就像

代码语言:javascript
复制
<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>

票数 2
EN

Stack Overflow用户

发布于 2013-10-08 07:07:04

你可能漏掉了一个小错误,

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

只需像这样修改你的代码。

代码语言:javascript
复制
  <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> 

我已经把style="display:block"label标签上去掉了,这真的很管用,

检查小提琴是否有小样本,

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

代码语言:javascript
复制
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:更新的Fiddle

我已经更新了小提琴来验证您的代码fiddle2,但是这里也很好。!!

请提供您的网页的现场链接,以获得进一步帮助,谢谢

票数 0
EN

Stack Overflow用户

发布于 2016-03-17 12:22:02

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

检查这里的小提琴

似乎对齐复选框的诀窍是在它周围有另一个容器(在我的例子中是<i>),我将其定位为绝对,更改默认的复选框容器位置将使可单击区域变得混乱。

代码语言:javascript
复制
<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

代码语言:javascript
复制
.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;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19191326

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档