<head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
 </head>
 <style type="text/css">
    div{
        height:200px;
        background:#eee;
        vertical-align:middle;
    }
    img{
        height:40px;
        vertical-align:middle;
    }
    /* span{
        height:100%;
        display:inline-block;
        vertical-align:middle;
    }     */
 </style>
 <body>
  <div>
    <!-- <span></span> -->
    <img src="https://www.baidu.com/img/bd_logo1.png" alt="" />
  </div>
 </body>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 

<head> 

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 

<title>div里面图片垂直居中的几个例子</title> 

<style type="text/css"> 

<!-- 

body { 

 margin:0;padding:0 

} 

div { 

 width:500px; 

 height:500px; 

 line-height:500px; 

 border:1px solid #666; 

 overflow:hidden; 

 position:relative; 

 text-align:center; 

} 

div p { 

 position:static; 

 +position:absolute; 

 top:50% 

} 

img { 

 position:static; 

 +position:relative; 

 top:-50%;left:-50%; 

 vertical-align:middle 

} 

p:after { 

 content:".";font-size:1px; 

 visibility:hidden 

} 

--> 

</style> 

</head> 

<body> 

<div><p><img src="http://www.google.com/intl/en/images/logo.gif" /></p></div> 

</body> 

</html> 



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 

<head> 

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 

<title>div里面图片垂直居中的几个例子</title> 

<style type="text/css"> 

<!-- 

* {margin:0;padding:0;} 

div { 

 width:500px;border:1px solid #666; 

 height:500px; 

 background:url("http://www.google.com/intl/en/images/logo.gif") center no-repeat 

} 

--> 

</style> 

</head> 

<body> 

<div></div> 

</body> 

</html> 



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %> 


<!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 runat="server"> 

 <title>未命名頁面</title> 


 <script type="text/javascript"> 

 function setCenter(Xelement) 

 { 

 var parent=Xelement.parentNode; 

 parent.style.position="relative"; 

 Xelement.style.position="absolute"; 

 var left=(parent.clientWidth-Xelement.clientWidth)/2; 

 var top=(parent.clientHeight-Xelement.clientHeight)/2; 

 Xelement.style.left=left+"px"; 

 Xelement.style.top=top+"px"; 

 } 

 </script> 


</head> 

<body> 

 <form id="form1" runat="server"> 

 <div id="picbox" > 

 <img id="img1" src="images/c7.jpg" alt="" οnlοad="setCenter(this)" /> 

 </div> 

 </form> 

</body> 

</html>
#img_menu {
content: url(../assets/menu.png);
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
width: 30px;
height: 30px;
border-width: 0;
border: none;
vertical-align: middle;
}
/*将最外层元素都撑开到100%屏幕*/
html,body{
width:100%;
height:100%;
}
body{
text-align:center;
}
body:after{
content:"";
display:inline-block;
height:100%;
vertical-align:middle;
}
/*选中的图片元素*/
img{
vertical-align:middle;
}
display: inline-block;
vertical-align: middle;
/*将最外层元素都撑开到100%屏幕*/
html,body{
	width:100%;
	height:100%;
}
body{
	text-align:center;
}
body:after{
	content:"";
	display:inline-block;
	height:100%;
	vertical-align:middle;
}
/*选中的图片元素*/
img{
	vertical-align:middle;
}
<div >
    <img alt="" src="https://www.baidu.com/img/baidu_jgylogo3.gif"  />
</div>
        .three {
        	width: 1000px;
        	height: 60px;
        	border-top: 1px solid #d6d6d6;
        	margin:0 auto; /*居中*/       	
        }
<div class="flexbox">
    <img src="1.jpg" alt="">
</div>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>CSS基础学习-图片</title>  
<style>
div.img {
    margin: 5px;
    border: 1px solid #ccc;
    float: left;
    width: 180px;
}

div.img:hover {
    border: 1px solid #777;
}

div.img img {
    width: 100%;
    height: auto;
}

div.desc {
    padding: 15px;
    text-align: center;
}
</style>
</head>
<body>

<div class="responsive">
  <div class="img">
    <a target="_blank" href="http://static.runoob.com/images/demo/demo1.jpg">
      <img src="http://static.runoob.com/images/demo/demo1.jpg" alt="图片文本描述" width="300" height="200">
    </a>
    <div class="desc">这里添加图片文本描述</div>
  </div>
</div>
 
<div class="responsive">
  <div class="img">
    <a target="_blank" href="http://static.runoob.com/images/demo/demo2.jpg">
      <img src="http://static.runoob.com/images/demo/demo2.jpg" alt="图片文本描述" width="300" height="200">
    </a>
    <div class="desc">这里添加图片文本描述</div>
  </div>
</div>
 
<div class="responsive">
  <div class="img">
    <a target="_blank" href="http://static.runoob.com/images/demo/demo3.jpg">
      <img src="http://static.runoob.com/images/demo/demo3.jpg" alt="图片文本描述" width="300" height="200">
    </a>
    <div class="desc">这里添加图片文本描述</div>
  </div>
</div>
 
<div class="responsive">
  <div class="img">
    <a target="_blank" href="http://static.runoob.com/images/demo/demo4.jpg">
      <img src="http://static.runoob.com/images/demo/demo4.jpg" alt="图片文本描述" width="300" height="200">
    </a>
    <div class="desc">这里添加图片文本描述</div>
  </div>
</div>

</body>
</html>
<ul class="imgWrap clearfix">
                <li><a href="#" class="imgBox"><span></span><img src="images/img1.jpg" alt="" /></a></li>
                <li><a href="#" class="imgBox"><span></span><img src="images/img2.jpg" alt="" /></a></li>
                <li><a href="#" class="imgBox"><span></span><img src="images/img3.jpg" alt="" /></a></li>
                <li><a href="#" class="imgBox"><span></span><img src="images/img4.jpg" alt="" /></a></li>
            </ul>
1 <div data-options="region:'north',border:false" >
2 <div id="navicatorbar" >
3 <i></i> <img src="../img/ep-logo.png"
4 />
5 </div>
6 </div>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        .wrap{
            width:500px;
            height:500px;
            border:1px solid #000;
            text-align:center;
        }
        span{
            height:100%;
            width:1px;
            vertical-align:middle;
            display:inline-block;
        }
        img{
            vertical-align:middle;
        }
    </style>
</head>
<body>
    <div class="wrap">
        <img src="p_w_picpaths/con3.png" alt="" /><span></span>
    </div>
</body>
</html>
<div style="text-align: center;">
  <img src="image.jpg" alt="图片">
</div>
<body>
    <div class="box">
        <ul>
            <li>
                <img data-src="img1.jpg" alt="">
            </li>
            <li>
                <img data-src="img2.jpg" alt="">
            </li>
            <li>
                <img data-src="img3.jpg" alt="">
            </li>
            <li>
                <img data-src="img1.jpg" alt="">
            </li>
            <li>
                <img data-src="img2.jpg" alt="">
            </li>
            <li>
                <img data-src="img3.jpg" alt="">
            </li>
            <li>
                <img data-src="img1.jpg" alt="">
            </li>
        </ul>
    </div>
</body>
</html>
<script>
    function imgonload() {
        let img = document.querySelectorAll("img");
        for (let i = 0; i < img.length; i++) {
            if (img[i].getBoundingClientRect().top < window.innerHeight) {
                //图片一旦有src就会加载出来,所以图片的路径不会放在src中,而是一个自定义的属性data-src中
                img[i].src = img[i].dataset.src;
            }
        }
    }

    function scollImg(fn) {
        let timer = null;
        let context = this;
        return function () {
            clearTimeout(timer);
            timer = setTimeout(() => {
                fn.apply(context);
            }, 500)
        }
    }
    window.onload = imgonload;     //html加载完毕后立即执行
    window.onscroll = scollImg(imgonload);     //每次滚轮滑动时都要触发
</script>
/*css*/
div{
    border:1px solid red;
    text-align: center;
    width: 200px;
}
div span{
    width: 100px;
    background: #ddd;
}

<!--HTML-->
<div>
    <span>我是span元素</span>
</div>
img {
width: 100%;
object-fit: cover;
}
<div class="btn_blue" οnclick="">

<img src="img/facebook_login.png" ><span>Login with Facebook</span>

</div>
  • 1
  • 2
  • 3
  • 4
  • 5