[英]container width much larger then content
I have a bunch of content that floats left in a container, and I'd like for the container to hug the content, but for some reason it's much wider then the content and I have no idea why. 我有一堆漂浮在容器中的内容,我想让容器拥抱内容,但是由于某种原因,它比内容宽得多,我不知道为什么。 I have it set up in a fiddle here http://jsfiddle.net/vG8NY/6/ the red and blue bordered containers should hug the right edge of the circle.
我在http://jsfiddle.net/vG8NY/6/的小提琴中进行了设置,红色和蓝色边框的容器应拥抱圆的右边缘。
The code is very simple and is as follows: 该代码非常简单,如下所示:
HTML: HTML:
<div class="hot_spot-container">
<div class="content-spot">
<img class="hotspot-cir" src="http://www.klossal.com/sixred/discovery/images/hotspot-left.png" />
<div class="hotspot-content"></div>
<img class="hotspot-cir" src="http://www.klossal.com/sixred/discovery/images/hotspot-right.png" />
<br class="clear-fix" />
</div>
</div>
CSS: CSS:
.hot_spot-container {border:1px solid blue;
position:absolute;
}
.content-spot {
border:1px solid red;
display:inline-block;
}
.hotspot-cir {
float:left;
height:100%;
width:auto;
}
.hotspot-content {
float:left;
background:#ec6e47;
}
.clear-fix {
clear:both;
}
JS JS
$(".content-spot").css({
height:$(window).height() * ".2"
});
try this: 尝试这个:
$(".content-spot").css({
height:$(window).height() * ".2",
width:$(window).height() * ".2"
});
when you change height of content-spot
it's width still fixed and need to get resize too. 当您更改
content-spot
高度时,其宽度仍然固定,并且也需要调整大小。
you can use this code too: 您也可以使用以下代码:
$(".hotspot-cir").css({
height:$(window).height() * ".2"
});
You must define the width for the element to which you have set the position: absolute;
您必须为设置
position: absolute;
的元素定义宽度position: absolute;
so you should use something like this: 因此,您应该使用以下内容:
.hot_spot-container {border:1px solid blue;
position:absolute;
/* any width you want or if you don't know the width then define auto.*/
width: 45px;
}
if you make 如果你做
.hot_spot-container {display:inline-block}
instead of it having position:absolute it does what you want it to. 而不是拥有position:absolute,它可以做您想要的。 if you want position absolute you need to give it a width
如果您想要绝对位置,则需要给定宽度
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.