【问题标题】:expand a div if the other doesn't exist如果另一个不存在,则展开一个 div
【发布时间】:2013-03-15 12:48:16
【问题描述】:

我有两个如下所示的 div。一个固定宽度,另一个应扩展到可用的其余部分。

    <style type="text/css">
    #ads
    {
        float: right;
        width: 200px;
    }
    #content-panel
    {
        float: left;
        width: 100%;
    }
</style>
<div style="width: 100%; overflow: hidden; clear: both;">
    @if (Resources.Ads.ClassA == "true")
    {
        <div id="ads">
            <div>
                <img src="../../Content/img/Ads/xlpar.gif" />
            </div>
        </div>
    }
    <div id="content-panel">
        @Html.Action("Elanat", "Home")
        @Html.Action("Latest", "AdsCatalog")
        <div class="article-wrapper">
            <div class="article-titlebar">
                <h4>
                    @Resources.CommonRes.WellcomeTitle</h4>
            </div>
            <div class="article-content">
                @Html.Raw(Resources.CommonRes.welcome)
            </div>
        </div>
        @Html.Action("Latest", "News")
        @Html.Partial("VisitCounterDisplay")
    </div>
</div>

我想检查一个值,如果 (true) 应该显示广告 div,并且 content-div 应该像其他可用的一样。当 if(false) 不应该显示 ad-div 时。并且内容 div 的宽度必须为 100%。但它不起作用。

【问题讨论】:

    标签: html css asp.net-mvc-3 razor


    【解决方案1】:

    为什么不根据是否有广告在内容面板中添加一个类:

    <div id="content-panel" class="@Html.Raw(Resources.Ads.ClassA == "true" ? "withAdd" : "withoutAdd")>
    

    那么您可以将相关样式应用到相关类

    如果Resources.Ads.ClassA 是一个布尔值,你也可以使用if (Resources.Ads.ClassA) {}

    【讨论】:

    • 嘿,您在 HTML 中使用的这种编程语言是什么?只是想知道。 (对我来说看起来像旧 asp)
    • 它是带有 Razor 的 html 微软似乎将代码放回 html 页面
    • 谢谢。我觉得自己像个白痴。为什么我没有想到它!!!!谢谢兄弟。这很有帮助
    猜你喜欢
    • 2014-02-21
    • 2018-04-10
    • 2012-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-10
    • 2023-03-03
    相关资源
    最近更新 更多