我认为这是一个相当简单的问题,但我只是不能将自己的头包裹起来,而且我对jQuery并不太满意。我在里面有一个div。文章的高度根据内容而变化(它是一篇博文,所以有些文章很短,有些很长)。我希望我的DIV相匹配的文章被嵌套在高度Jquery将嵌套元素的高度设置为其包含元素的高度
HTML:
<article class="PostHome">
<div class="ColorBarLeft"></div>
<header>
<h3>@Html.DisplayFor(modelItem => item.Title)</h3>
<small>@Html.DisplayFor(modelItem => item.DateCreated)</small>
</header>
<section id="PostContent">
@Html.DisplayFor(modelItem => item.Content)
</section>
<section id ="PostTags">
@Html.Label("Tags:")
@Html.DisplayFor(modelItem => item.Tags)
</section>
@Html.ActionLink("View Full Post", "Post", new { blogTitle = item.Title.Replace(" ", "-"), id = item.Id}, null)
</article>
然后,我尝试了一些jQuery的,像这样:
$(document).ready(function() {
$(".ColorBarLeft").height(function() {
var height = $(this).height()
$('.PostHome').height(height);
})
});
我认为代码正确,但它可能会关闭,再次,不是很擅长jQuery。
我不知道这是否重要,但一次会在页面上出现多个posthomes和ColorBarlefts。
***编辑,更改ID = PostHome类= PostHome
我想去的地方的红色波浪框是吧。
好像你正在做它周围posthome'的'高度匹配'colorbarleft' – elclanrs
其他方式这里有2个独立的问题:高度和彩色条的位置。你是否已经有了解决方案?酒吧如何定位可能会决定哪些选项可用于高度。 –
对于这个职位,我所做的只是将div的CSS设置为:position:absolute;左:0 ;.对于高度我不能让它匹配,这就是为什么我通过jQuery可以做到这一点。如果我使用像你所说的图像,它可以正常工作,但只有当我将它放在文章元素 – ledgeJumper