html - 使用母版页时更改内容占位符的样式

标签 html css

我有一个网站(VS2010、asp.net、VB)并且我正在使用母版页。我还有其他几个页面,在其中一个页面上我想将背景颜色设置为内容占位符。我正在使用样式表,并且 .aspx 页面上有以下代码。 (这只是测试代码)

<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Dashboard2.aspx.vb" Inherits="Dashboard2" %>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div id="body_color">
<table id="mainDisplay">
<tr>
<td>a</td>
<td>a</td>
<td>a</td>
</tr>
<tr>
<td>a</td>
<td>a</td>
<td>a</td>
</tr>
<tr>
<td>a</td>
<td>a</td>
<td>a</td>
</tr>
</table>
</div>
</asp:Content>

我尝试引用内容占位符的 ID,但不起作用。

以下是表格水平和垂直居中时的 CSS。

#mainDisplay
{
    margin-left:auto;
    margin-right:auto;
    margin-top:100px;
    width:900px;
    height:450px;
}

更新了代码以在 aspx 页面上显示所有内容

最佳答案

ContentPlaceHolder 元素不会在客户端代码上呈现。查看生成的源代码并检查。您需要将样式应用到 ContentPlaceHolder 内的 div。

示例:

<style>
    #placeHolderDiv {
        width: 1000px;
        height: 650px;
        background-color: #AAA;
    }
    #mainDisplay {
        margin-left: auto;
        margin-right: auto;
        margin-top: 100px;
        width: 900px;
        height: 450px;
        background-color: #DDD;
    }
</style>


<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div id="placeHolderDiv">
        <table id="mainDisplay">
...

关于html - 使用母版页时更改内容占位符的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19182533/

相关文章:

html - 从 PDF 中的 HTML 背景色创建 PDF

html - 如何用图片替换我的提交按钮?

css - FontAwesome 不能用作字体系列?

css - 网站在除 IE7 以外的所有方面都运行良好,

html - 输入文本中的图像

html - 行内 block 换行后删除人工边距

php - 安装没有数据库的Magento

html - 下面的代码在 CSS 中做了什么?

javascript - 从 Document.Ready 调用 onchange 函数,并使用更新中预选的项目

html - 引用标签不会在 Chrome 中使文本变为斜体