简体   繁体   English

使用css或jquery在图标旁边放置文本

[英]position text alongside icon using css or jquery

My features HTML is code generated, I would like to display the text along side the icons but the only way I have managed to do it, is by position:absolute; 我的功能HTML是生成的代码,我想在图标旁边显示文本,但是我设法做到的唯一方法是按position:absolute; and this is NOT good as some products have a cart box directly above the features and some dont, therefore absolute position doesnt work. 这是不好的,因为有些产品的功能框正上方有一个购物车盒,有些则没有,因此绝对位置无效。

Is there a way to relatively position the feature names along side the icons using either css or jquery? 是否可以使用css或jquery在图标旁边相对放置功能名称?

I have tried this: http://jsfiddle.net/nHHkQ/ 我已经尝试过: http : //jsfiddle.net/nHHkQ/

HTML: HTML:

<div id="FeatureIconsWrapper">
    <div class="FeatureIconImages">
      <a title="CapacityChildren" href=
      "popup.aspx?title=CapacityChildren&amp;topic=feature_CapacityChildren" rel="icons"
      class="iconClick"><img title="CapacityChildren" alt="CapacityChildren" src=
      "http://i50.tinypic.com/hwh0ud.png" /></a>
    </div>

    <div class="FeatureIconImages">
      <a title="EasyBackpackingSystem" href=
      "popup.aspx?title=EasyBackpackingSystem&amp;topic=feature_EasyBackpackingSystem"
      rel="icons" class="iconClick"><img title="EasyBackpackingSystem" alt=
      "EasyBackpackingSystem" src="http://i50.tinypic.com/hwh0ud.png" /></a>
    </div>

    <div class="FeatureIconImages">
      <a title="EasyInflationSystem" href=
      "popup.aspx?title=EasyInflationSystem&amp;topic=feature_EasyInflationSystem" rel=
      "icons" class="iconClick"><img title="EasyInflationSystem" alt=
      "EasyInflationSystem" src="http://i50.tinypic.com/hwh0ud.png" /></a>
    </div>

    <div class="FeatureIconImages">
      <a title="MaxLoadCapacity" href=
      "popup.aspx?title=MaxLoadCapacity&amp;topic=feature_MaxLoadCapacity" rel="icons"
      class="iconClick"><img title="MaxLoadCapacity" alt="MaxLoadCapacity" src=
      "http://i50.tinypic.com/hwh0ud.png" /></a>
    </div>

    <div class="FeatureIconImages">
      <a title="Weight" href="popup.aspx?title=Weight&amp;topic=feature_Weight" rel=
      "icons" class="iconClick"><img title="Weight" alt="Weight" src=
      "http://i50.tinypic.com/hwh0ud.png" /></a>
    </div>

    <ul id="FeatureIconNamesWrapper">
      <li class="FeatureIconNames">ISO 6185-1</li>

      <li class="FeatureIconNames">ISO 6185-1</li>

      <li class="FeatureIconNames">ISO 6185-1</li>

      <li class="FeatureIconNames">ISO 6185-1</li>

      <li class="FeatureIconNames">ISO 6185-1</li>
    </ul>

    <div class="c1"></div>
  </div>

CSS: CSS:

div#FeatureIconsWrapper {
    background-color: #DEDEDE;
    border-left: 1px solid white;
    border-radius: 0 0 7px 7px;
    padding-bottom: 10px;
    width: 236px;
}

div.FeatureIconImages, div#FeatureIconNames {
    font-size: 14px;
    font-weight: bold;
    line-height: 20px;
    padding-left: 7px;
    padding-top: 17px !important;
}

div.FeatureIconImages {
    padding-left: 7px;
    padding-top: 20px;
}

div.FeatureIconImages {
    width: 60px;
}


ul#FeatureIconNamesWrapper {
    font-size: 14px;
    font-weight: bold;
    padding-right: 40px;
    position: absolute;
    top: 375px;
}


li.FeatureIconNames {
    margin-bottom: 57px;
    margin-left: 85px !important;
}

问题

这是它的外观

I guess the problem is your wrong structure of html. 我想问题是您的html结构错误。 If you can tweak your html as in my fiddle then you can easily obtain img - label pair using css float. 如果您可以像在我的小提琴中那样调整html,那么您可以使用css float轻松获取img-标签对。 Please check this fiddle - http://jsfiddle.net/ashwyn/cgj5U/ 请检查此小提琴-http: //jsfiddle.net/ashwyn/cgj5U/

OR 要么

You can even do this without changing your html structure. 您甚至可以在不更改html结构的情况下执行此操作。 used float:left on both the main sections http://jsfiddle.net/ashwyn/9dUDX/ 在两个主要部分上都使用了float:left http://jsfiddle.net/ashwyn/9dUDX/

$imgs = $('#FeatureIconsWrapper .FeatureIconImages'); // cache image wrappers for better performance
$('#FeatureIconNamesWrapper li').each(function(i,e){
    $imgs.filter(':eq(' + i + ')').after($(e).detach());
})​

Proof of concept fiddle here – disregard the CSS. 概念证明在这里摆弄–忽略CSS。 .

Note: This solution sucks for multiple reasons. 注意:此解决方案很烂,原因有很多。 If there is any way you can alter the markup: Do it! 如果有任何方法可以更改标记,请执行以下操作:

i have edited the Fiddle. 我已经编辑了小提琴。 take a look at here : Fiddle 看看这里: 小提琴

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

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