Html 设置其背景图像的div大小
使用CSS/HTML是否可以调整某些框的大小,使其与背景图像大小完全匹配?不使用javascript 例如,假设我有一个最简单的div:Html 设置其背景图像的div大小,html,css,Html,Css,使用CSS/HTML是否可以调整某些框的大小,使其与背景图像大小完全匹配?不使用javascript 例如,假设我有一个最简单的div: <div class="image">TEST</div> .image { background-image: url(http://placehold.it/350x150); width: 350px; height: 150px; } 这样,我的表单将提交所有数据,并且我将知道用户单击了哪个按钮。而
<div class="image">TEST</div>
.image {
background-image: url(http://placehold.it/350x150);
width: 350px;
height: 150px;
}
这样,我的表单将提交所有数据,并且我将知道用户单击了哪个按钮。而且按钮看起来很好,就像它应该看起来一样。我想知道是否有可能使它更便携一点-我的按钮都有不同的功能不同的宽度。有人能在这里提出另一种方法吗?我建议你另一种解决问题的方法。如果使用引导,则可以使用div来生成可调整大小的图像
<div class="img-responsive">
<img src="test.jpg" width='xxx' height='yyy' alt='test'>
</div>
我建议您另一种解决问题的方法。如果使用引导,则可以使用div来生成可调整大小的图像
<div class="img-responsive">
<img src="test.jpg" width='xxx' height='yyy' alt='test'>
</div>
我建议您另一种解决问题的方法。如果使用引导,则可以使用div来生成可调整大小的图像
<div class="img-responsive">
<img src="test.jpg" width='xxx' height='yyy' alt='test'>
</div>
我建议您另一种解决问题的方法。如果使用引导,则可以使用div来生成可调整大小的图像
<div class="img-responsive">
<img src="test.jpg" width='xxx' height='yyy' alt='test'>
</div>
不,你不能。CSS不知道图像的大小。使用JQuery可以轻松地完成这项工作
不,你不能。CSS不知道图像的大小。使用JQuery可以轻松地完成这项工作
不,你不能。CSS不知道图像的大小。使用JQuery可以轻松地完成这项工作
不,你不能。CSS不知道图像的大小。使用JQuery可以轻松地完成这项工作
仅仅使用HTML是无法做到这一点的。但是你可以用HTML来做这件事 你应该试试这个:
background-size: values;
这样,您将根据容器的大小调整背景图像的大小 仅使用HTML无法做到这一点。但是你可以用HTML来做这件事 你应该试试这个:
background-size: values;
这样,您将根据容器的大小调整背景图像的大小 仅使用HTML无法做到这一点。但是你可以用HTML来做这件事 你应该试试这个:
background-size: values;
这样,您将根据容器的大小调整背景图像的大小 仅使用HTML无法做到这一点。但是你可以用HTML来做这件事 你应该试试这个:
background-size: values;
这样,您将根据容器的大小调整背景图像的大小 这是一个黑客攻击,没有使用
背景图像(而是使用img
标记),但这是我能想到的不使用JS的唯一方法
HTML
<div class="container">
<div class="image">
<img src="http://www.pandafix.com/pandafix/images/untitled_1.jpg"/>
</div>
<div class="content">
some text
<br/>
some more text
<br/><br/><br/><br/>
text text text
</div>
</div>
基本上,您可以使用img
标记来确定容器的高度和宽度。然后,将您想要的任何内容覆盖在图像顶部(我假设您想要在顶部放置一些内容)
这是一个黑客攻击,不使用背景图像(而是使用img
标记),但这是我能想到的不使用JS的唯一方法
HTML
<div class="container">
<div class="image">
<img src="http://www.pandafix.com/pandafix/images/untitled_1.jpg"/>
</div>
<div class="content">
some text
<br/>
some more text
<br/><br/><br/><br/>
text text text
</div>
</div>
基本上,您可以使用img
标记来确定容器的高度和宽度。然后,将您想要的任何内容覆盖在图像顶部(我假设您想要在顶部放置一些内容)
这是一个黑客攻击,不使用背景图像(而是使用img
标记),但这是我能想到的不使用JS的唯一方法
HTML
<div class="container">
<div class="image">
<img src="http://www.pandafix.com/pandafix/images/untitled_1.jpg"/>
</div>
<div class="content">
some text
<br/>
some more text
<br/><br/><br/><br/>
text text text
</div>
</div>
基本上,您可以使用img
标记来确定容器的高度和宽度。然后,将您想要的任何内容覆盖在图像顶部(我假设您想要在顶部放置一些内容)
这是一个黑客攻击,不使用背景图像(而是使用img
标记),但这是我能想到的不使用JS的唯一方法
HTML
<div class="container">
<div class="image">
<img src="http://www.pandafix.com/pandafix/images/untitled_1.jpg"/>
</div>
<div class="content">
some text
<br/>
some more text
<br/><br/><br/><br/>
text text text
</div>
</div>
基本上,您可以使用img
标记来确定容器的高度和宽度。然后,将您想要的任何内容覆盖在图像顶部(我假设您想要在顶部放置一些内容)
你不能直接做
唯一的解决方案是获取DIV元素的BG并将新的DOM img元素附加到DOM节点,然后可以使用图像的信息添加适当的with和height
如果您愿意使用jquery,您可以这样做
$(function(){
$('.image').each(function(index,element){
var _t = $(this);
_t.data("LinkedImg","LinkedImage"+index);
$('body').append(
$('<img />',{
id:"LinkedImage"+index,
src:_t.css('background-image')
}).hide());
});
$('document').on('load',function(){
$('.image').each(function(index,element){
var _t = $(this);
var _tmp_img = $('#'+ _t.data("LinkedImg"));
_t.css({
width:_tmp_img.width(),
height: _tmp_img.height()
});
});
});
})
$(函数(){
$('.image')。每个(函数(索引,元素){
var _t=$(本);
_t、 数据(“LinkedImg”、“LinkedImage”+索引);
$('body')。追加(
$('您不能直接这样做
唯一的解决方案是获取DIV元素的BG并将新的DOM img元素附加到DOM节点,然后可以使用图像的信息添加适当的with和height
如果您愿意使用jquery,您可以这样做
$(function(){
$('.image').each(function(index,element){
var _t = $(this);
_t.data("LinkedImg","LinkedImage"+index);
$('body').append(
$('<img />',{
id:"LinkedImage"+index,
src:_t.css('background-image')
}).hide());
});
$('document').on('load',function(){
$('.image').each(function(index,element){
var _t = $(this);
var _tmp_img = $('#'+ _t.data("LinkedImg"));
_t.css({
width:_tmp_img.width(),
height: _tmp_img.height()
});
});
});
})
$(函数(){
$('.image')。每个(函数(索引,元素){
var _t=$(本);
_t、 数据(“LinkedImg”、“LinkedImage”+索引);
$('body')。追加(
$('您不能直接这样做
唯一的解决方案是获取DIV元素的BG并将新的DOM img元素附加到DOM节点,然后可以使用图像的信息添加适当的with和height
如果您愿意使用jquery,您可以这样做
$(function(){
$('.image').each(function(index,element){
var _t = $(this);
_t.data("LinkedImg","LinkedImage"+index);
$('body').append(
$('<img />',{
id:"LinkedImage"+index,
src:_t.css('background-image')
}).hide());
});
$('document').on('load',function(){
$('.image').each(function(index,element){
var _t = $(this);
var _tmp_img = $('#'+ _t.data("LinkedImg"));
_t.css({
width:_tmp_img.width(),
height: _tmp_img.height()
});
});
});
})
$(函数(){
$('.image')。每个(函数(索引,元素){
var _t=$(本);
_t、 数据(“LinkedImg”、“LinkedImage”+索引);
$('body')。追加(
$('您不能直接这样做
唯一的解决方案是获取DIV元素的BG并将新的DOM img元素附加到DOM节点,然后可以使用图像的信息添加适当的with和height
如果您愿意使用jquery,您可以这样做
$(function(){
$('.image').each(function(index,element){
var _t = $(this);
_t.data("LinkedImg","LinkedImage"+index);
$('body').append(
$('<img />',{
id:"LinkedImage"+index,
src:_t.css('background-image')
}).hide());
});
$('document').on('load',function(){
$('.image').each(function(index,element){
var _t = $(this);
var _tmp_img = $('#'+ _t.data("LinkedImg"));
_t.css({
width:_tmp_img.width(),
height: _tmp_img.height()
});
});
});
})
$(函数(){
$('.image')。每个(函数(索引,元素){
var _t=$(本);
_t、 数据(“LinkedImg”、“LinkedImage”+索引);