Javascript 如何使标题随图像移动?
当页面调整大小时,如何让标题与图像一起移动,就像用户使页面变长/变宽时一样?我怎样才能使标题与图像一起移动而不停留在原地 请不要删除我的问题,如果你觉得这不是一个适当的问题,或如果它没有正确地陈述 CSS:Javascript 如何使标题随图像移动?,javascript,arrays,Javascript,Arrays,当页面调整大小时,如何让标题与图像一起移动,就像用户使页面变长/变宽时一样?我怎样才能使标题与图像一起移动而不停留在原地 请不要删除我的问题,如果你觉得这不是一个适当的问题,或如果它没有正确地陈述 CSS: #caption { position: absolute; padding: 10px; box-sizing: border-box; color: white; font-size: 14pt; font-family: sans-ser
#caption {
position: absolute;
padding: 10px;
box-sizing: border-box;
color: white;
font-size: 14pt;
font-family: sans-serif;
background-color: #008800;
opacity: 0.5;
text-align: left;
bottom:0px;
}
<div style="text-align: Center;" id="photoSection">
<img id='photo' src='memchu.jpg' alt='photo' />
<div id="caption">
Stanford Memorial Church - the church used to have an 80' bell tower, which fell in the 1906 earthquake.
</div>
<div id="forwardOverlay"></div>
<div id="backwardOverlay"></div>
</div>
"use strict";
var photoArray = [
{filename: "memchu.jpg",
caption: "Stanford Memorial Church - the church used to have an 80 bell tower, which fell in the 1906 earthquake."},
{filename: "quad.jpg",
caption: "The Stanford Quad"},
{filename: "hoop.jpg",
caption: "The <i>Red Hoop Fountain</i> with Green Library in the background."},
{filename: "memorial-court.jpg",
caption: "Memorial Court (in the front of the Quad) with Rodin's <i>Burghers of Calais</i> statues."},
{filename: "gates.jpg",
caption: "The Gates Building - home of Stanford Computer Science."},
{filename: "stone-river.jpg",
caption: "The Stone River statue near the Cantor Arts Center (Stanford's own art museum)."},
];
HTML:
#caption {
position: absolute;
padding: 10px;
box-sizing: border-box;
color: white;
font-size: 14pt;
font-family: sans-serif;
background-color: #008800;
opacity: 0.5;
text-align: left;
bottom:0px;
}
<div style="text-align: Center;" id="photoSection">
<img id='photo' src='memchu.jpg' alt='photo' />
<div id="caption">
Stanford Memorial Church - the church used to have an 80' bell tower, which fell in the 1906 earthquake.
</div>
<div id="forwardOverlay"></div>
<div id="backwardOverlay"></div>
</div>
"use strict";
var photoArray = [
{filename: "memchu.jpg",
caption: "Stanford Memorial Church - the church used to have an 80 bell tower, which fell in the 1906 earthquake."},
{filename: "quad.jpg",
caption: "The Stanford Quad"},
{filename: "hoop.jpg",
caption: "The <i>Red Hoop Fountain</i> with Green Library in the background."},
{filename: "memorial-court.jpg",
caption: "Memorial Court (in the front of the Quad) with Rodin's <i>Burghers of Calais</i> statues."},
{filename: "gates.jpg",
caption: "The Gates Building - home of Stanford Computer Science."},
{filename: "stone-river.jpg",
caption: "The Stone River statue near the Cantor Arts Center (Stanford's own art museum)."},
];
但是,当页面重新调整大小时,我的标题似乎没有保留在图像中。我想这是您需要的,关键是在父页面上显示:表
#photoSection{display:table;margin:0 auto;position:relative;}
#photoSection img{max-width:100%;}
#caption {
position:absolute;
padding: 10px;
color: white;
font-size: 14pt;
font-family: sans-serif;
background-color: #008800;
opacity: 0.5;
text-align: left;
bottom:0;
}
我认为这是您的后一步,关键是显示:家长上的表格
#photoSection{display:table;margin:0 auto;position:relative;}
#photoSection img{max-width:100%;}
#caption {
position:absolute;
padding: 10px;
color: white;
font-size: 14pt;
font-family: sans-serif;
background-color: #008800;
opacity: 0.5;
text-align: left;
bottom:0;
}
你能提供一个JSFIDLE/JSBin吗?试试
位置:相对代码>请参见。@sjm是的,我可以,但如果我这样做,图像会可见吗?@ZakariaAcharki我试过了,但我需要标题位于图像底部的上方,但它会移动到底部,因此我需要标题与图像保持在一起,但也位于图像上方。之前已多次询问带有图像的响应性标题,尝试将图像包装到与标题相同的位置,然后进行这些编辑-您能提供一个JSFIDLE/JSBin吗?尝试position:relative代码>请参见。@sjm是的,我可以,但如果我这样做,图像会可见吗?@ZakariaAcharki我试过了,但我需要标题位于图像底部的上方,但它会移动到底部,因此我需要标题与图像保持在一起,但也位于图像上方。之前已多次询问带有图像的响应性标题,尝试将图像包装在与标题相同的位置,然后进行编辑-是的,谢谢,但问题是显示什么:表格;做什么?据我所知,它会将父块约束到子块元素的宽度,display:inline也会这样做,但不允许左边距/右边距:autoyess谢谢,但问题是display:table;做什么?据我所知,它会将父块约束到子块元素的宽度,display:inline也会这样做,但不允许左边距/右边距:自动