Home>Article>Web Front-end> How to set the image to center in javascript

How to set the image to center in javascript

青灯夜游
青灯夜游 Original
2022-01-19 11:47:32 6532browse

Method: 1. Wrap the image with div and span; 2. Use setAttribute() to add "display:table;text-align:center" and "display:table-cell;vertical-align:middle" ;"style.

How to set the image to center in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

How to center the image using javascript:

Build an HTML framework

     
How to set the image to center in javascript

How to set the image to center in javascript

Use the setAttribute() method to add an image centering style

var div=document.getElementById("app"); var img=document.getElementById("img"); div.setAttribute("style","display:table;text-align: center;"); img.setAttribute("style","display:table-cell;vertical-align: middle;");

How to set the image to center in javascript

[Related recommendations:javascript learning tutorial]

The above is the detailed content of How to set the image to center in javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Can javascript add tags? Next article:Can javascript add tags?