How to center pictures in div in JSP

Time:2020-10-17

How to center pictures in div in JSP 

JSP, let the image in the div center display, as shown in the above figure

example:

Copy codeThe code is as follows:
//CSS file
<style type=”text/css”>

#bj{

width:200px;

height:200px;

border:3px solid red;

text-align:center;

vertical-align:middle;

display:table-cell; //Display objects as table cells

background:pink;

}

img{

width:150px;

height:150px;

margin:0 auto;

vertical-align:middle;

border:2px solid green;

}

</style>

</head>

//Body file

<body>

<div>

<img src=”11.jpg”/>

</div>

</body>

If it is in HTML, it will have the effect as shown in the figure. The image is centered, but in JSP, the image is only horizontally centered. In this case, we need the

Copy codeThe code is as follows:
Add W3C standard statement in <! DOCTYPE >, such as:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>

Add in the JSP, the picture will be in the middle as you wish!