Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align Jcrop images

I've this code:

<div class='mini'>
    <div id='wrap_jcrop' class='td_wrap'>
        <img id='img2crop' src=''>
    </div>
</div>

With this CSS:

div.mini {
    width: 300px;
    height: 200px;
    display: table;
}

div.td_wrap {
    display: table-cell;
    vertical-align: middle;
    text-align: center;
}

The image source for img2crop is loaded dynamically and handled with a Jcrop api. But Jcrop aligns the image on the left.

How can I align the image in the center of the div?

like image 816
Medical physicist Avatar asked Sep 01 '13 11:09

Medical physicist


2 Answers

Rather than modify the jcrop css file (not recommended, as per the plugin author) you can add a class to the jcrop-holder element as an option when you initialise Jcrop:

jQuery(function($) {
    $('#jcrop_target').Jcrop({
        addClass: 'jcrop-centered'
    });
});

Add a wrapper around the img tag in your HTML, e.g.

<div class="crop-image-wrapper">
    <img id="jcrop_target" src="...." alt="" />
</div>

Then add a css style, e.g.

.jcrop-centered
{
    display: inline-block;
}
.crop-image-wrapper
{
    text-align: center;
}

Tested in Chrome 31.0.1650.63 m - let me know if it doesn't work in other browsers? (except < IE8) :-)

like image 172
Chris Avatar answered Oct 01 '22 14:10

Chris


Set

.jcrop-holder
{
    margin: 0 auto;
}
like image 29
vpascoal Avatar answered Oct 01 '22 15:10

vpascoal