【问题标题】:Vertical Align Bootstrap Radio Button Image垂直对齐引导单选按钮图像
【发布时间】:2016-02-25 22:14:55
【问题描述】:

我正在尝试将 input-group-addonradio 元素结合起来。示例代码如下。

http://www.bootply.com/1M34c3sy29

但是radio 图像 没有以价格 radio 部分居中。

是否可以将 Price 部分的图像居中?或者您是否为此类演示推荐其他解决方案。

【问题讨论】:

    标签: html css twitter-bootstrap radio


    【解决方案1】:

    Bootstrap 正在添加一些样式,这些样式不允许垂直对齐按您的需要运行。元素是绝对定位的。我会尝试使用top css 属性以另一种方式定位单选按钮:

    .input-group { display:inline-block;}
    
    #inlineradio2{ top: 13px; }
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    
    <form class="form-horizontal">
     <fieldset>
      <div class="form-group">
       <div class="col-lg-12">
        <div class="radio">
         <label>
          <input id="inlineradio1" name="sampleinlineradio" value="option1" type="radio">
          Automatic. Price will be set by the system!</label>
        </div>     
        <div class="radio">
         <label>
    		  <input id="inlineradio2" name="sampleinlineradio" value="option2" type="radio">
    		  <div class="input-group">
    			<span class="input-group-addon">Price</span>
    			<input type="text" class="form-control" placeholder="" id="price-box" aria-describedby="Price">
    		  </div><!-- /input-group -->
    	  </label>
        </div>
       </div>
      </div>
     </fieldset>
    </form>

    我还将相关单选按钮上的 HTML id 属性的名称更改为 the id should be unique

    【讨论】:

    • 非常感谢。请问13px是怎么计算的?如果用户为她的页面增加字体大小,13px 可能不可靠。我认为我的方式不标准,可能有问题。您是否仍然推荐 13px 解决方法或其他标准解决方案?
    • 我通过盯着中心点想出了 13px。除非您计划更改“input-group-addon”跨度的高度/填充或媒体查询或其他内容中位于其侧面的输入文本框,否则我认为这不是问题。如果是这种情况,您也可以更新媒体查询中的 top 属性。如果用户更新缩放单选按钮也将增加大小和比例将是相同的。您永远无法完全保证您的网站会正确显示,因为 css 在客户端呈现并且可以由用户操作。
    猜你喜欢
    • 2013-09-27
    • 2020-07-23
    • 1970-01-01
    • 2021-04-27
    • 1970-01-01
    • 2019-01-28
    • 2018-01-16
    • 1970-01-01
    相关资源
    最近更新 更多