开发者

How to align image as center in tinymce?

I am using jquery tinymce. once i insert an image it is aligned left as default. How can i align it as center as default.

if (tinyMCE.activeEditor != null && tinyMCE.activeEditor.isHidden() == false)
{
    var content=tinyMCE.get('faq_answer').getContent()+"<img id='"+faq_media_id+"' src='"+path+"' title='"title"' align='"middle"' alt='"alternate"' width='"150"' height='"150"' >";
    tinyMCE.get('faq_answer').setContent(content);
    //alert('tiny: '+content);
开发者_开发技巧}

In my above code i am adding image into tinymce. If i give align="midde" not working for me.


I guess you remember your question on howto predefine the editors default font size. This one is similar. You will have to set the css according to your need in the css file you reference useing the content_css setting.

it should look like

img {
  align: middle;
}

EDIT: Even though the easiest and most waterproof method to set the css style is to use the css file content_css reffers to, you may use:

$(ed.getBody()).find('img').css('align','middle');

EDIT2: You need to set your qoutes right:

var content=tinyMCE.get('faq_answer').getContent()+"<img id='"+faq_media_id+"' src='"+path+"' title='title' align='middle' alt='alternate' width='150' height='150' >";

EDIT3: This will work:

$(ed.getBody()).find('img').css('display','block');
$(ed.getBody()).find('img').css('margin','0px auto');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜