如何移动我的图像's的位置
How do I move my image's position?
我在网站主页上放置了一张图片,但我想移动图片的位置,而不是操纵图片的像素。我确信这与填充或边距有关,但我不确定如何在我的程序中实现它。这是我的代码:
<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="stylesheetMain.css">
<title> Main Page </title>
</head>
<body>
<!-- This is the image I want to move around! -->
<img src="blake.jpg" alt="Mountain View" style="width:141px;height:114px;">
<div class="link1" onclick="location.href='';" style="cursor: pointer;">
</div>
<div class="link2" onclick="location.href='ImagePage.html';" style="cursor: pointer;">
</div>
<div class="link3" onclick="location.href='gamequiz.html';" style="cursor: pointer;">
</div>
<div class="link4" onclick="location.href='orderform.html';" style="cursor: pointer;">
</div>
<div class="link5" onclick="location.href='comments.html';" style="cursor: pointer;">
</div>
<div class="link6" onclick="location.href='';" style="cursor: pointer;"><br><br><br>
Author: Michael Cattermole
</div>
</body>
</html>
只有当组件的位置是相对的、固定的或绝对的时,才能设置组件的位置。如果执行了此操作,则可以将样式中的"左"answers"上"设置为某个值。例如:
<img src="blake.jpg" alt="Mountain View" style="width:141px;height:114px; position:absolute; left:200; top:500;">
我想您只想在较小的容器中看到图像的一部分。因此,代码中的图像将是141 x 114 px,但您希望在100x100px的框架内以原始大小显示部分图像。这是你想要的吗?
如果是,可以使用负的margin
-值来实现这一点。但是,您还需要一个容器,其中包含(遮罩)图像的裁剪部分,并使其余部分不可见。所以你会有这样的东西:
<div style="style="position: relative;width:100px;height:100px;overflow: hidden;">
<img src="blake.jpg" alt="Mountain View" style="position: relative;width:141px;height:114px;margin-top:-20px;margin-left:-7px;">
</div>
尽管如此,如果你使用类来处理它会容易得多,比如:
<style type="text/css">
.x {
position: relative;
width:100px;
height:100px;
overflow: hidden;
}
.x img {
position: relative;
width:141px;
height:114px;
margin-top:-20px;
margin-left:-7px;
}
</style>
<div class="x">
<img src="blake.jpg" alt="Mountain View">
</div>
这里有一种方法。。。将img包装在div中,如so…
<div class="relP">
<img src="blake.jpg" alt="Mountain View">
</div>
那么在你的css中包括这个。。。
.relP{
position: relative;
}
.relP img{
position: absolute;
left: 50px;
top: 50px;
height: 114px;
width: 141px;
}
你的形象现在已经完全定位了。通过调整"顶部"answers"左侧"数字,您可以更改图像在页面上的位置。你也可以通过设置.relP-img使图像水平居中…
.relP img{
position: absolute;
left: 0;
right: 0;
margin:0 auto;
height: 114px;
width: 141px;
}
希望这能有所帮助!
相关文章:
- 在固定位置显示随机图像
- 如何将图像准确地放置在菜单位置
- javascript背景图像位置循环
- 如何在调整浏览器大小时将图像保持在适当位置
- 100%的父图像.父级是固定位置的
- 有人知道有没有jquery插件可以在图像上写文本,并让用户将其放置在图像内的任何位置
- 使用Planetary.js将图像放置在适当位置
- Google Places API显示雷达搜索中的位置图标/图像
- 使用JavaScript功能切换图像位置
- 根据客户的地理位置、邮政编码和位置切换图像
- 通过传递的参数位置获取jQuery中图像的宽度
- 使用javascript获取多个图像的位置
- Photoshop脚本:将图像移动到位置x,y
- 如何使某个框等于图像HTML的位置
- JavaScript 动态更改图像 src 的位置 - NO JQuery
- 我想滚动放大和缩小一个图像,但也有针在该图像上保持正确的位置.jQuery
- 固定图像滚动移动位置
- 需要帮助修复图像JS的动态位置
- 使用javascript和php,在单击图像时将其移动到另一个位置
- 处理溢出的负位置图像:自动