本文主要为大家分享三种css截图的方法 ,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧,希望能帮助到大家。
css截图图片的几种方式原图:
div 使用background-position:xpx ypx (图片左上角坐标) 配合width和height
<p class="p_bg"></p>
<style type="text/css">
.p_bg
{
width: 550px;
height: 113px;
background-image: url(img/bk_title_all.jpg);
background-repeat: no-repeat;
background-position: 0px -599px;
}</style>
效果图:
img 使用clip: rect(左上y 右下x 右下y 左上x) 配合width和margin-top
<img class="img1" src="img/bk_title_all.jpg" />
<style type="text/css">
.img1
{
width: 550px;
background-image: url(img/bk_title_all.jpg);
clip: rect(599px 550px 712px 0px);
position: absolute;
margin-top: -599px; }
</style
效果图:
div+img 使用margin属性和overflow属性控制
<p class="p_img">
<img class="img2" src="img/bk_title_all.jpg" />
</p>
<style type="text/css">
.p_img
{ width: 550px;
height: 113px;
overflow: hidden;
}.img2
{ margin: -599px 0 0 0; }
</style>
效果图:
完整版html如下:
<!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>
<title>untitled page</title>
<style type="text/css">
.p_bg
{ width: 550px; height: 113px; background-image: url(img/bk_title_all.jpg); background-repeat: no-repeat; background-position: 0px -599px; }
.img1
{ width: 550px; background-image: url(img/bk_title_all.jpg); clip: rect(599px 550px 712px 0px); position: absolute; margin-top: -599px; }
.p_img
{ width: 550px; height: 113px; overflow: hidden; }
.img2
{ margin: -599px 0 0 0; }
</style></head><body>
<h1>
原图</h1>
<p style="width: 550px; height: 831px; background: url(img/bk_title_all.jpg);
background-repeat: no-repeat;">
</p>
<hr />
<h1>
p <br />
<span style="color: red;">使用background-position:xpx ypx (图片左上角坐标) 配合width和height</span>
</h1>
<h2>
background: url(img/bk_title_all.jpg); width: 550px;<br />
width: 550px;<br />
height: 113px;<br />
background-repeat: no-repeat;<br />
background-position: 0px -599px; </h2>
<p class="p_bg">
</p>
<hr />
<h1>
img <br />
<span style="color: red;">使用clip: rect(左上y 右下x 右下y 左上x) 配合width和margin-top</span>
</h1>
<h2>
img src="img/bk_title_all.jpg" <br />
clip: rect(599px 550px 712px 0px);<br />
position: absolute;<br />
width: 550px;<br />
margin-top: -599px; </h2>
<img class="img1" src="img/bk_title_all.jpg" />
<br />
<br />
<h1 style="margin-top:100px;">
p+img <br />
<span style="color: red;">使用margin属性和overflow属性控制</span>
</h1>
<h2>
<h3>p</h3>
width: 550px;<br />
height: 113px;<br />
overflow: hidden;<br />
<h3>img</h3>
margin: -599px 0 0 0;<br />
</h2>
<p class="p_img">
<img class="img2" src="img/bk_title_all.jpg" />
</p></body></html>
以上就是三种css截图的方法 的详细内容。
