Home >Web Front-end >HTML Tutorial >How to center the img in the div_html/css_WEB-ITnose

How to center the img in the div_html/css_WEB-ITnose

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-24 12:11:481186browse


asdfasfasfasfdasdfdfasfsdf
How to center the img in the div_html/css_WEB-ITnose


The text is not centered, only the image is centered (not vertical)


Reply to discussion (solution)

<!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"><head id="Head1" runat="server">    <title>xxxxxxx</title>    <style type="text/css">	<!--	div {	     text-align:center;		 width:500px; 		 height:500px; 		 border:1px solid #666666;	 	 }	 div span{	  margin:0px;	  padding:0px;	  display:block;	  margin-left:-290px;	  }	       	--></style></head><body><div> <span>asdfasfasfasfdasdfdfasfsdf</span> <img  src="/static/imghwm/default1.png"  data-src="11.jpg"  class="lazy"   alt="How to center the img in the div_html/css_WEB-ITnose" > </di  </body></html>

Keep moving forward...

Is it possible to fix the size of the div first
and use margin: auto to solve it?
I don’t know if it’s possible

See if it’s what you want. If not, look again. This mainly puts the image in one layer, and then centers the layer. It’s better to use different parameters. Change it.

<!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"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><style>#container{width:780px}#image{width:200px;margin:0 auto}</style></head><body><div id="container">123456789101112131415161718192021222324252627282930下面的图是一个200X150PX的图<div id="image"><img  src="/static/imghwm/default1.png"  data-src="images/myphoto.jpg"  class="lazy"      style="max-width:90%"  style="max-width:90%" / alt="How to center the img in the div_html/css_WEB-ITnose" ></div></div></body></html>

It’s probably like this, I haven’t tested it yet, you can adjust it again.


asdfasfasfasfdasdfdfasfsdf

How to center the img in the div_html/css_WEB-ITnose



This sentence is enough
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