简体   繁体   English

垂直对齐单选按钮到图标

[英]Vertical align of radio button to icon

在此输入图像描述

I want to align my Radio Buttons vertically that they are on the middle. 我想垂直对齐我的单选按钮,它们位于中间。 As you can see in this screen they start on the bottom line next to the icon. 正如您在此屏幕中看到的那样,它们从图标旁边的底线开始。 I think its clear what I want to achieve. 我认为它清楚我想要实现的目标。 What do I have to do to reach this in a beatiful way ? 我需要做些什么才能以美丽的方式实现这一目标?

HTML: HTML:

<div class="payment-methods">
    <div class="method"><input name="1" type="radio"><label class="radio"><img src="https://lol-accs.com/images/ico_visa.jpg" alt=""></label></div>
    <div class="method"><input name="1" type="radio"><label class="radio"><img src="https://lol-accs.com/images/ico_visa.jpg" alt=""></label></div>
    <div class="method"><input checked="" name="1" type="radio"><label class="radio"><img src="https://lol-accs.com/images/ico_visa.jpg" alt=""></label></div>
    <div class="method"><input name="1" type="radio"><label class="radio"><img src="https://lol-accs.com/images/ico_visa.jpg" alt=""></label></div>
    <div class="method"><input name="1" type="radio"><label class="radio"><img src="https://lol-accs.com/images/ico_visa.jpg" alt=""></label></div>
</div>

CSS: CSS:

.method {
    display: inline-block;
}

.payment-methods input[type=radio] {
    margin: 5px 5px 0px 15px;
}

I prepared a JSFiddle which shows my HTML / CSS. 我准备了一个显示我的HTML / CSS的JSFiddle。

http://jsfiddle.net/fk0zch3d/ http://jsfiddle.net/fk0zch3d/

  1. Apply vertical-align: middle to img and input . vertical-align: middle应用于imginput
  2. Remove margin-top from .payment-methods input[type=radio] ( margin: 5px 5px 0px 15px; ---> margin: 0px 5px 0px 15px; ). .payment-methods input[type=radio]删除margin-topmargin: 5px 5px 0px 15px; ---> margin: 0px 5px 0px 15px; )。

 .method, img, input { display: inline-block; vertical-align: middle; } .payment-methods input[type=radio] { margin: 0px 5px 0px 15px; } 
 <div class="payment-methods"> <div class="method"> <input name="1" type="radio"> <label class="radio"> <img src="https://lol-accs.com/images/ico_visa.jpg" alt=""> </label> </div> <div class="method"> <input name="1" type="radio"> <label class="radio"> <img src="https://lol-accs.com/images/ico_visa.jpg" alt=""> </label> </div> <div class="method"> <input checked="" name="1" type="radio"> <label class="radio"> <img src="https://lol-accs.com/images/ico_visa.jpg" alt=""> </label> </div> <div class="method"> <input name="1" type="radio"> <label class="radio"> <img src="https://lol-accs.com/images/ico_visa.jpg" alt=""> </label> </div> <div class="method"> <input name="1" type="radio"> <label class="radio"> <img src="https://lol-accs.com/images/ico_visa.jpg" alt=""> </label> </div> </div> 

You're looking for vertical-align: middle; 你正在寻找vertical-align: middle; , used with display: inline-block; ,用于display: inline-block; .

.method inpuit,
.method label{
    display: inline-block;
    vertical-align: middle;
}

http://jsfiddle.net/daCrosby/fk0zch3d/1/ http://jsfiddle.net/daCrosby/fk0zch3d/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM