Adding an additional image on the right of listview element in Jquery Mobile

空扰寡人 提交于 2019-12-11 16:30:34

问题


I've been struggling with the code below. What I basically need to do is to show an image on the right AND left side of the element. Both images should be the same size. I also need the text to be centered at all times in any view. It would be nice to have some options of being able to change the font and color.

<html>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css">

<style>
    .ui-li-thumb, .ui-li-icon {
    max-height: 40px;
    max-width: 40px;
    height:35px; !important
    width:37px; !important
    position: absolute;
    padding-top:3px;
    padding-left:5px;    
    }

    li a { 
    min-height:20px !important; 
    height: 20px;
    padding-bottom: 10px;
    padding-top: 5px;
    }


    .ui-page .ui-content .ui-listview p {
    margin-top: -0.10em;
    margin-bottom: 0em;
    line-height    : 15px;
    vertical-align : top;
    font-size: 0.90em;
    font-weight: 600;
    padding-top: 20px;
    }
</style>

<ul data-role="listview" data-divider-theme="b" data-inset="true" >
    <li data-role="list-divider" role="heading"><center>ID</center></li>

    <li  data-icon = "false">
       <a href="#" > <img class="ui-li-thumb" src="http://lorempixel.com/80/80/technics/1/">                 
          <p>ID NAME <br>number</p>  
       </a>
    </li>


   <li  data-icon = "false">
      <a href="#" > <img class="ui-li-thumb" src="http://lorempixel.com/80/80/technics/1/">  
          <center><p>ID NAME</p><p><br>number</p></center>
      </a>
   </li>
</ul>
</html>

回答1:


Here is one way to do it.

<ul data-role="listview" data-inset="true" class="has-right-radio">
    <li data-icon="false"> 
         <a href="#">
            <img src="http://lorempixel.com/80/40/technics/1/" />  
            <p class="green bigfont">ID1</p>
            <p class="green bigfont">First set of description text.</p>            
            <div class="right-radio"> 
                <img src="http://lorempixel.com/80/40/technics/6/" />
            </div>
         </a>
    </li>
</ul>

.has-right-radio {
    min-width: 240px;
}
.has-right-radio img {
    width: 80px;
    height: 50px;
}
.has-right-radio a {
    padding-right: 100px !important;
    min-height: 41px !important;
    padding-top: 4px;
    padding-bottom: 4px;
}
.has-right-radio a p {
    white-space: normal !important;
    text-align: center;
    margin: 0;
}
.right-radio {
    position: absolute;
    top: 0px; bottom: 0px; right: 0px;
    width: 80px;
    border: 0;
    background-color: rgb(246, 246, 246) !important;
}
.green {
    color: green;
}
.orange {
    color: orange;
}
.bigfont {
    font-size: 14px !important;
}

Let's walk through the CSS:

The first rule just imposes a minimum width on the whole list so that images don't run into eachother at small screen widths.

The second one sizes you images regardless of their original size. In this example they are 80px wide and 50px high. THis is where you can change the height of the images.

The third one adds padding to the right so text won't go over the right image. Additionally it sets the top and bottom padding and imposes a minimum height so that the image will be displayed. If you change the image height, you will need to set the min-height here to desired image height minus padding-top minus padding-bottom minus 1 (border).

The .right-radio rule absolutely positions the right image and the rest of the rules basically format and position text.

Here is a DEMO of the above



来源:https://stackoverflow.com/questions/25903951/adding-an-additional-image-on-the-right-of-listview-element-in-jquery-mobile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!