我正在尝试在响应的图像下添加标题,所以我的代码看起来像这样
function showVideo(obj) {
$("#youtube").attr("src", $(obj).data("src"));
$('#videoModalLabel').text($(obj).data("title"));
$("#videoModal").on("hide.bs.modal", function() {
$("#youtube").removeAttr("src");
}).modal('show');
}figure {
display: inline-block;
}
figcaption {
margin: 10px 0 0 0;
font-variant: small-caps;
font-family: Arial;
font-weight: bold;
color: #bb3333;
}
figure {
padding: 5px;
}
.vid img:hover {
transform: scale(1.1);
-ms-transform: scale(1.1);
-webkit-transform: scale(1.1);
-moz-transform: scale(1.1);
-o-transform: scale(1.1);
}
.vid img {
transition: transform 0.2s;
-webkit-transition: -webkit-transform 0.2s;
-moz-transition: -moz-transform 0.2s;
-o-transition: -o-transform 0.2s;
padding: 1px;
border: 1px solid #021a40;
}<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row vid">
<figure>
<img class="img-responsive" src="resources/image/18/85/a.jpg" data-title='Want this to be same as figcaption' data-src="https://www.youtube.com/embed/path-to video?autoplay=1" onclick="showVideo(this)" />
<figcaption>
This is long text which overlaps the caption beside it I Want it to break automatically according to window size
</figcaption>
</figure>
</div>
这里我有两个问题:
我的标题很长,所以我想让我的数据标题变成<figcaption>,这样我就不必重写它了
发布于 2016-08-06 00:01:38
只需要将img宽度设置为100%:
图片和文本在所有大小上保持相同的宽度/大小,这是一个难题:
https://jsfiddle.net/h9kj04kv/
.vid img {
transition: transform 0.2s;
-webkit-transition: -webkit-transform 0.2s;
-moz-transition: -moz-transform 0.2s;
-o-transition: -o-transform 0.2s;
padding:1px;
border:1px solid #021a40;
width: 100%;
}如果你不想让它变得太大,那么只需在vid div中添加一个max-width和max-height即可。
编辑:没有看到第二部分。
要将文本注入到data-title中,只需添加以下内容:
$(function(){
$('.img-responsive').attr('data-title', $(figcaption).text())
})最后,为了使图像与文本/标题保持相同的大小:
$(function(){
figWidth = $(figcaption).width()
$('.img-responsive').css('width', figWidth)
})更新:如果你有很多连续的视频,你需要创建一个网格系统。
<div class="row vid">
<div style="width: 25%; float:left;">
<figure>
<img class="img-responsive" src="https://i.stack.imgur.com/lro0o.png?s=48&g=1" data-title='Want this to be same as figcaption' data-src="https://www.youtube.com/embed/path-to video?autoplay=1" onclick="showVideo(this)" />
<figcaption>
This is long text which overlaps the caption beside it I
</figcaption>
</figure>
</div>
<div style="width: 25%; float:left;">
<figure>
<img class="img-responsive" src="https://i.stack.imgur.com/lro0o.png?s=48&g=1" data-title='Want this to be same as figcaption' data-src="https://www.youtube.com/embed/path-to video?autoplay=1" onclick="showVideo(this)" />
<figcaption>
This is long text which overlaps the caption beside it I
</figcaption>
</figure>
</div>
<div style="width: 25%; float:left;">
<figure>
<img class="img-responsive" src="https://i.stack.imgur.com/lro0o.png?s=48&g=1" data-title='Want this to be same as figcaption' data-src="https://www.youtube.com/embed/path-to video?autoplay=1" onclick="showVideo(this)" />
<figcaption>
This is long text which overlaps the caption beside it I
</figcaption>
</figure>
</div>
<div style="width: 25%; float:left;">
<figure>
<img class="img-responsive" src="https://i.stack.imgur.com/lro0o.png?s=48&g=1" data-title='Want this to be same as figcaption' data-src="https://www.youtube.com/embed/path-to video?autoplay=1" onclick="showVideo(this)" />
<figcaption>
This is long text which overlaps the caption beside it I
</figcaption>
</figure>
</div>
</div>发布于 2016-08-06 00:02:19
这将解决第一个问题
figure {
display: table;
width:1%;
}
function showVideo(obj) {
$("#youtube").attr("src", $(obj).data("src"));
$('#videoModalLabel').text($(obj).data("title"));
$("#videoModal").on("hide.bs.modal", function() {
$("#youtube").removeAttr("src");
}).modal('show');
}figure {
display: table;
width: 1%;
}
figcaption {
margin: 10px 0 0 0;
font-variant: small-caps;
font-family: Arial;
font-weight: bold;
color: #bb3333;
}
figure {
padding: 5px;
}
.vid img:hover {
transform: scale(1.1);
-ms-transform: scale(1.1);
-webkit-transform: scale(1.1);
-moz-transform: scale(1.1);
-o-transform: scale(1.1);
}
.vid img {
transition: transform 0.2s;
-webkit-transition: -webkit-transform 0.2s;
-moz-transition: -moz-transform 0.2s;
-o-transition: -o-transform 0.2s;
padding: 1px;
border: 1px solid #021a40;
}<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row vid">
<figure>
<img class="img-responsive" src="http://www.fillmurray.com/460/300" data-title='Want this to be same as figcaption' data-src="https://www.youtube.com/embed/path-to video?autoplay=1" onclick="showVideo(this)" />
<figcaption>
This is long text which overlaps the caption beside it I Want it to break automatically according to window size
</figcaption>
</figure>
</div>
https://stackoverflow.com/questions/38793359
复制相似问题