我有一个网站(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/