怎么才能让 图片隐藏两边,DIV+CSS+JS怎么实现?

JavaScript049

怎么才能让 图片隐藏两边,DIV+CSS+JS怎么实现?,第1张

图片隐藏两边最常见的有网页banner同屏效果,一般制作方法有两种

第一种:

设置外层div或者标签宽度百分百按照比例设置,图片设置在标签行内样式中的背景图片,使用背景定位,居中或者固定某个值,当我们改变窗口也就是改变外层div的时候会看到div宽度改变,背景图片一直保持我们设置的值,两边多余会隐藏掉。

第二种:

外层div定位,css设置溢出隐藏,图片使用绝对定位法,定位到我们想要的位置,同时可以设置margin属性来辅助,例如: img{ position:absoluteleft:50%margin-left:500px}

目前,当某个IP段在短时间内向百度发出大量连接请求,即会受到百度局域网异常访问屏蔽策略的限制。

有两个方法可以解决:

1.PHP抓取页面受限的破解方法

在使用PHP抓取百度知道问题页时,由于PHP程序抓取速度过快,导致被屏蔽,采用以下的方式解决

抓取页面需采用fsockopen方式,使用file_get_contents无法设置请求头

fsockopen函数的使用方法请自行查阅,例子中的geturlcont函数为自定义函数,核心即为fsockopen,geturlcont函数的原型

geturlcont($url, $referer = "" ,$cookie),$url为待抓取的页面的url,$referer为传递的referer参数(主要用于防止抓到的是百度首页),$cookie为重要的一个参数,用于破解局域网异常访问屏蔽功能

2.Chrome扩展直接跳转方案

在另一个程序中,不需要抓取页面内容,但会同时打开数十页的百度页面,同样可能会造成短时间内请求过多导致的屏蔽,解决方法是通过Chrome扩展的js注入功能实现

附(百度屏蔽页的代码):

<html>

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312" />

<title>百度--您的访问出错了</title>

<style>

body{text-align:centermargin-top:3px}

#wrap{width:650pxtext-align:leftmargin:auto}

#logo{float:leftmargin:0 3px 0 0}

#logo img{border:0}

#title{float:leftwidth:510px}

#intitle{margin:20px 0 0 0background-color:#e5ecf9width:100%font-weight:boldfont-size:14pxpadding:3px 0 4px 10px}

#content{clear:leftpadding-top:60pxline-height:200%}

#vf{margin-top:10px}

#vf img{float:leftborder:1px solid #000}

#kw{font:16px Verdanaheight:1.78empadding-top:2px}

#vf form{float:leftmargin:12px 0 0 5pxpadding:0}

#ft{text-align:center}

#ft,#ft a{color:#666font-size:14px}

</style>

</head>

<body>

<div id="wrap">

<div id="logo"><a href="http://www.baidu.com"><img alt="到百度首页" title="到百度首页" src="http://www.baidu.com/img/logo-yy.gif" width="137" height="46"></a></div>

<div id="title"><div id="intitle">您的访问出错了</div></div>

<div id="content">很抱歉,您的电脑或所在的局域网络有异常的访问,此刻我们无法响应您的请求。 <br>请输入以下验证码,即可恢复使用。</div>

<div id="vf">

<img src="http://verify.baidu.com/cgi-bin/genimg?9D5771ED69F27050263223420F7043C211B95E2D3616825774FF64E3FEF61920E3089D79E454888755B8F3AFDF124C9C74A34C4DDFAFD27827B3512B437BE76043" width="120" height="40">

<form action="http://verify.baidu.com/verify">

<input type="hidden" name="url" value="http://zhidao.baidu.com/question/519848902?oldq=1&vf_tf=1">

<input type="hidden" name="vcode" value="9D5771ED69F27050263223420F7043C211B95E2D3616825774FF64E3FEF61920E3089D79E454888755B8F3AFDF124C9C74A34C4DDFAFD27827B3512B437BE76043">

<input type="hidden" name="id" value="1359359285">

<input type="hidden" name="di" value="530e060fe3c68f3d">

<input type="text" size="6" maxlength="10" name="verifycode" id="kw">

<input type="submit" value="提交">

</form>

</div>

<div style="clear:leftheight:90px"></div>

<div id="ft">© 2012 Baidu <a href="http://www.baidu.com/duty/index.html">免责声明</a></div>

</div>

<script>

(function(){

var rfr = window.document.location.href,

p = encodeURIComponent(rfr),

img = new Image(),

imgzd = new Image(),

re = /\/vcode\?http:\/\/(\S+)\.baidu/ig,r=""

img.src = "http://nsclick.baidu.com/v.gif?pid=201&pj=vcode&path="+p+"&t="+new Date().getTime()

r = re.exec(rfr)

if(r&&r[1]){imgzd.src = "http://"+r[1]+".baidu.com/v.gif?fr=vcode&url="+p+"&t="+new Date().getTime()}

})()

</script>

</body>

</html>