css3 - Using box model to contain items within its parent div -


using following html , css3 rules, i'm trying make sure following criteria adhered to:

i have of criteria working except item 1 children exceeding parent's width. question: how keep children within parent?

  1. li items cannot exceed parent width i.e. 400px
  2. img, label, , currency content must centred vertically within span
  3. currency should not wrap , should displayed in full
  4. currency should displayed close possible label span.
  5. the label text should clamped @ 2 lines ellipsis displayed exceeds 2 lines.

note: needs work in chrome , safari webkit-based browsers.

it should like:

enter image description here

however, looks @ moment:

enter image description here

any ideas?

********************* js fiddle example ************************

<ul>     <li>         <span class="img"></span>         <span class="label">acclaim</span>         <span class="currency">(usd 50)</span>     </li>      <li>         <span class="img"></span>         <span class="label">acclaim 1 11 111 1111 11111</span>         <span class="currency">(usd 50)</span>     </li>      <li>         <span class="img"></span>         <span class="label">acclaim 1 11 111 1111 11111 2 22222 2222 22222 3 33 333 3333 33333 4 44 444 4444 44444 5 55 555 5555 55555 6 66 666 6666 66666</span>         <span class="currency">(usd 50)</span>    </li> </ul>   ul {     width: 400px;      background-color: yellow;     padding: 0;     margin: 0; }  li {     display: -webkit-box;      padding-right: 50px; }  .label {     display: -webkit-box;     -webkit-box-orient: vertical;     -webkit-box-pack: center;      -webkit-line-clamp: 2;     text-overflow: ellipsis;     overflow: hidden;     white-space: normal;     word-wrap: break-word;     line-height: 1.3em;     margin-right: 0.2em;          background-color: pink;     }  .currency {     display: -webkit-box;     -webkit-box-orient: vertical;     -webkit-box-pack: center;      white-space: nowrap;      background-color: lightgreen;     }  .img {     display: block;     width: 40px;     height: 40px;     margin-right: 0.1em;      background-image:url('data:image/png;base64,ivbor...); } 

the following work, providing price doesn't wider:

http://jsfiddle.net/wdjz3/4/

i converted margin-right pixels knew space taken content other label, added max-width remainder:

.label {        margin-right: 3px;       max-width: 294px; } 

if price or image variable width, need js read widths, remove 400px , add value max-width.

here example using javascript dynamically set max-width: http://jsfiddle.net/wdjz3/7/

i haven't checked dimensions, should added make accurate, otherwise margins make price no longer fit.

i checked width of other elements:

function getwidth(el) {        return parseint(window.getcomputedstyle(el,null).getpropertyvalue("width")); } 

i removed width 400px, , set maxwidth:

for (var i=0; i<imgs.length; i++) {     var width = 400 - (getwidth(imgs[i]) + getwidth(currencies[i])) + "px";      labels[i].style.maxwidth = width; } 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -