html中图片以中心放大的代码

html-css014

html中图片以中心放大的代码,第1张

html中图片以中心放大的代码如下:

<div style=" width:300px height:300pxmargin-left:auto

margin-right:auto overflow:hidden margin-top:100px">

<img id="img" onmouseover="bigger()" onmouseout="smaller()"

src="http://mat1.gtimg.com/www/images/qq2012/guanjia2.png"

style="cursor:pointerwidth:300pxheight:300px

transition:all 1s ease-out 0s perspective-origin:bottom"/>

<script type="text/javascript">

var img = document.getElementById('img')

function bigger(){

img.style.width = '400px'

img.style.height = '400px'

img.style.marginTop = "-50px"

img.style.marginLeft = "-50px"

}

function smaller(){

img.style.width = '300px'

img.style.height = '300px'

img.style.marginTop = "0px"

img.style.marginLeft = "0px"

}

</script>

扩展资料:

在html中用js实现鼠标指向图片时图片放大的效果的代码如下:

<img id="img" onmouseover="bigger()" onmouseout="smaller()"

src="你的图片路径" style="width:100pxheight:100px" />

<script type="text/javascript">

var img = document.getElementById('img')

function bigger(){  img.style.width = '400px'  img.style.height = '400px' }

function smaller(){  img.style.width = '100px'  img.style.height = '100px' }

</script>

text-align:center表示排列到中心

text-align还有其他的值,如下

值描述

left    把文本排列到左边。默认值:由浏览器决定。    

right    把文本排列到右边。    

center    把文本排列到中间。    

justify    实现两端对齐文本效果。    

inherit    规定应该从父元素继承 text-align 属性的值。

应用在CSS里设置把h1标题居中

<style>

h1 {text-align:center}

</style>