gpt4 book ai didi

html - 在 950 像素宽的 div 中居中 1250 像素宽的图像 - CSS 问题

转载 作者:可可西里 更新时间:2023-11-01 13:16:23 25 4
gpt4 key购买 nike

我的网页上有一张 1250 像素宽的图片。示例:http://img694.imageshack.us/img694/6171/unledvla.jpg

我在这张 950 像素宽的图片下方有一个 div。

我希望当我将窗口大小减小到 950 像素宽时,图像“居中”并且 150 像素的绿色区域(在 1250 像素图像的左侧和右侧)不可见。

这可能吗?

这是我当前的代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>CSS Layout</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
html,body{margin:0;padding:0}
div#container{background:green;width:950px;margin:0 auto}
</style>

</head>

<body>

<div style="width:1250px;background:url('image-1250px.jpg') 0 0 no-repeat;height:360px;margin:0 auto">&nbsp;</div>

<div id="container">

<div id="header"><h1>Header</h1></div>

<div id="wrapper">

<div id="content">
<p><strong>1) Content here.</strong> column long long column very long fill fill fill long text text column text silly very make long very fill silly make make long make text fill very long text column silly silly very column long very column filler fill long make filler long silly very long silly silly silly long filler make column filler make silly long long fill very.</p>
<p>very make make fill silly long long filler column long make silly silly column filler fill fill very filler text fill filler column make fill make text very make make very fill fill long make very filler column very long very filler silly very make filler silly make make column column </p>
<p>fill long make long text very make long fill column make text very silly column filler silly text fill text filler filler filler make make make make text filler fill column filler make silly make text text fill make very filler column very </p>

<p>column text long column make silly long text filler silly very very very long filler fill very fill silly very make make filler text filler text make silly text text long fill fill make text fill long text very silly long long filler filler fill silly long make column make silly long column long make very </p>
</div>

</div>

</div>

</body>
</html>

非常感谢您对此的任何指点。

最佳答案

(1) 将背景图片的位置样式由“0 0 no-repeat”改为“top center no-repeat”。(2) 删除“width:1250px;”,因为这会在窗口尺寸减小时导致水平滚动。

要实现我认为您所描述的内容,您希望背景图片本身的宽度为 1250 像素。

关于html - 在 950 像素宽的 div 中居中 1250 像素宽的图像 - CSS 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8054192/

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