Reputation: 12945
I am using the jquery plugin iCheck to style my checkboxes. I have successfully done this, but now I am not able to get the checkbox and label on the same line.
Here is the main code:
<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;
}
The iCheck box renders like so:
<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>
The image that I am using for the label for the checkbox appears on the line under the check boxes. Do you see anything that would make this be the case? I would like them in line. I am using Laravel 4.
Upvotes: 0
Views: 5422
Reputation: 2184
I have solved a similar issue where I also want the checkbox aligned inline, but I needed the text on the right to be able to span on 2 lines without going below the checkbox
Seems the trick with aligning the checkbox is to have another container around it (in my case <i>
) that i positioned absolute, changing the default checkbox container position will mess up the clickable area.
<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 & 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 & Development</a>
</span>
</div>
</div>
</div>
The 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;
}
Upvotes: 0
Reputation: 5785
There is a small mistake that you might have missed,
I have creates a sample fiddle
to explain the proof,
Just modify your code like this ..
<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>
I have removed style="display:block"
from label
tag, that did trick,
Check the fiddle for small sample,
Edit: As these one is not working changing the style sheet that might be adding more style,
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;
}
Edit 2 :Updated Fiddle
I have updated fiddle to verify your code fiddle2
but here also this works fine..!!
Please provide live link of your page for further help, thank you
Upvotes: 0
Reputation: 146219
Just move you input/checkbox
inside the label, like
<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>
Upvotes: 2