gpt4 book ai didi

html - 将图像推到页面容器上

转载 作者:太空宇宙 更新时间:2023-11-04 09:52:01 25 4
gpt4 key购买 nike

我有一个 960 像素宽的网页。在此页面内有一个部分,里面有一张图片,我想将其一直推到右侧,这样它就在页面外面的一半。下面的附图将向您展示我希望它看起来像什么的示例。

我也希望图像在背景中,这样如果浏览器窗口的宽度很小,它就会一直覆盖图像。

这里有几个网站有这个:

http://cpanel.com/products/

在 cpanel 上,当浏览器窗口小于图像时,您可以看到该页面上的 iPad 只显示了一半。

另一个具有这种效果的网站是 Doteasy.com,这是 URL:

http://www.doteasy.com/

如果您向下滚动到他们页面的中间,您将看到网站构建器部分,其中包含该软件的屏幕截图。他们的页面有 980 像素宽,您可以看到屏幕截图在页面包装器外面的一半。

图像的宽度应为 552 像素,高度应为 315 像素。

enter image description here

.container {
width: 960px;
height: auto;
margin: 0 auto;
background-color: yellow;
}

section {
width: 100%;
height: 508px;
background-color: blue;
}

.image {
width: 552px;
height: 315px;
background-color: red;
}
<!DOCTYPE html>
<html>
<head>
<title>Site Example</title>
<meta charset="UTF-8">
<meta name="description" content="">
<meta name="keywords" content="">
</head>
<body>
<section>
<h1>This is the Section</h1>
<div class="container">
<div class="image">This would be the image.</div>
</div>
</section>

</body>
</html>

希望大家帮帮忙!

谢谢。

最佳答案

你可以像这样相对于容器绝对定位:

  • 在容器中添加position: relative;
  • 给图片添加绝对定位 position: absolute;顶部:0; right: -276px;(右值是图片宽度的一半)
  • 容器上的
  • overflow-x: hidden 将阻止图像的额外一半可见。

section {
width: 100%;
height: 508px;
background-color: blue;
}

.container {
position: relative;
width: 960px;
height: 400px;
margin: 0 auto;
background-color: green;
overflow-x: hidden;
}

.image {
position: absolute;
top: 0;
right: -276px;
width: 552px;
height: 315px;
background-color: red;
}
<section>
<h1>This is the Section</h1>
<div class="container">
This is the container
<div class="image">This would be the image.</div>
</div>
</section>

关于html - 将图像推到页面容器上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39023001/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com