1

I have been trying to get the stars from the Raty plugin to vertically align inside a bootstrap table, but I can't get it to work. I have tried:

<table class="table table-striped">
  <tbody>
    <tr>
     <td id="stars" style=" text-align: center; vertical-align: middle; border:1px solid black;" id="mycell">TEXT</td>
  </tr>
  </tbody>
</table>

My js is:

$(function() {
    $('#stars').raty();
})

The stars don't seem to be aligned the same way "TEXT" is.

Here is a jsfiddle.

Dramal
  • 167
  • 2
  • 10

2 Answers2

0

How about wrapping your text in a <span> and applying following CSS?

span{
    vertical-align:middle;
}
img{
    vertical-align:middle;
}

Here is a snippet

/*!
 * jQuery Raty - A Star Rating Plugin
 *
 * The MIT License
 *
 * @author  : Washington Botelho
 * @doc     : http://wbotelhos.com/raty
 * @version : 2.7.0
 *
 */

;
(function($) {
  'use strict';


  $.fn.raty.defaults = {
    cancel: false,
    cancelClass: 'raty-cancel',
    cancelHint: 'Cancel this rating!',
    cancelOff: 'cancel-off.png',
    cancelOn: 'cancel-on.png',
    cancelPlace: 'left',
    click: undefined,
    half: false,
    halfShow: true,
    hints: ['bad', 'poor', 'regular', 'good', 'gorgeous'],
    iconRange: undefined,
    mouseout: undefined,
    mouseover: undefined,
    noRatedMsg: 'Not rated yet!',
    number: 5,
    numberMax: 20,
    path: undefined,
    precision: false,
    readOnly: false,
    round: {
      down: 0.25,
      full: 0.6,
      up: 0.76
    },
    score: undefined,
    scoreName: 'score',
    single: false,
    space: true,
    starHalf: 'http://www.wbotelhos.com/raty/lib/images/star-half.png',
    starOff: 'http://www.wbotelhos.com/raty/lib/images/star-off.png',
    starOn: 'http://www.wbotelhos.com/raty/lib/images/star-on.png',
    starType: 'img',
    target: undefined,
    targetFormat: '{score}',
    targetKeep: false,
    targetScore: undefined,
    targetText: '',
    targetType: 'hint'
  };

})(jQuery);
$(function() {
  $('#stars').raty();
})
@import url('http://getbootstrap.com/dist/css/bootstrap.css');
 span {
  vertical-align: middle;
}
img {
  vertical-align: middle;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://www.wbotelhos.com/raty/lib/jquery.raty.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.1.0/bootstrap.min.js"></script>
<table class="table table-striped">
  <tbody>
    <tr>
      <td id="stars" style=" text-align: center; vertical-align: middle; border:1px solid black;" id="mycell"><span>TEXT</span>
      </td>
    </tr>
  </tbody>
</table>
Ramiz Wachtler
  • 5,623
  • 2
  • 28
  • 33
  • This looks like it aligns the text and the stars together, but I think they are still not centered. Compare it to the text in another `` with no spans [here](http://jsfiddle.net/jsehlpa/0v37fkuf/) – Dramal Feb 08 '15 at 01:34
0

I had the same problem with when I am using raty. In my case, the text is slighyly higher than the row of stars. Try adding css style to your text:-

<td id="stars" style=" text-align: center; vertical-align: middle; border:1px solid black;" id="mycell"><span style:vertical-align:text-top;>TEXT</span></td>

I tested with your fiddle. It looks better with text-top.

Or you can try out other option for vertical-align. Refer to http://www.w3schools.com/cssref/pr_pos_vertical-align.asp

SimonK
  • 73
  • 1
  • 5