【发布时间】:2011-06-27 05:55:26
【问题描述】:
更具体地说,给定一组定义名为“content_title”的类选择器的样式表,有没有一种方法可以将该样式应用于所有<h1>标签,而无需将每个标签更改为<h1 class="content_title">,即有效地应用该样式类到给定元素的所有实例?
上下文是我正在尝试将来自图形设计师的 HTML 和 CSS 应用到现有的 Web 应用程序中,并且某些选择器的匹配度不是很好。
我有一个使用母版页和主题的 ASP.NET Web 表单应用程序。我收到了一个包含多个样式表的 HTML 示例/模板。
所以我更新了我的母版页以使用新设计,现在它看起来像这样:
<%@ Master Language="VB" AutoEventWireup="false" CodeBehind="MyMaster.master.vb" Inherits="MyApp.MyMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<!-- these are the new style sheet from the graphic designer -->
<link rel="stylesheet" href="../layout.css" media="screen" />
<link rel="stylesheet" href="../cssmenus.css" type="text/css" />
<link rel="stylesheet" href="../dropdown.css" media="screen" />
<link rel="stylesheet" href="../print.css" media="print" />
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body class="twocolumn">
<div id="container">
<!-- etc. etc. -->
<div id="mainContent_app">
<span class="content_title"></span> <!-- this is intended to be a page header/title -->
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="MainForm" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</div>
<!-- end #mainContent -->
<!-- etc. etc. -->
</div>
</body>
</html>
我的问题是,在设计者使用<span class="content_title"></span> 表示页眉的地方,我在所有内容页面中都使用了<h1>。例如:
<%@ Page Title="Simple single serving form" Language="vb" AutoEventWireup="false" MasterPageFile="~/MyMaster.Master" CodeBehind="MyPage.aspx.vb" Inherits="MyApp.MyPage" Theme="MyTheme" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<meta name="keywords" content="keyword1 keyword2 keyword3" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainForm" runat="server">
<h1>This is the page header.</h1>
<p>Here's some text that tells you what to do with this form.</p>
</asp:Content>
我的目标是使用设计师的风格,而无需编辑包含<h1> 的每个内容页面。
我可以将设计师 CSS 中的样式复制到我的应用程序主题中的样式表(当然,用类选择器替换标签),但是我不会真正使用源 CSS,我必须下次外部 CSS 更改时再次执行此操作。
我也不太可能更改外部 CSS 以适应我的应用程序。
那么关于样式的应用,我可以做些什么聪明的事情来使<h1> == class="content_title",还是我必须硬着头皮更新我的每一个内容页面?
【问题讨论】:
-
咬紧牙关。对
<h1>到<h1 class="content_title">运行全局查找和替换到底有多难? -
为什么不把css从
.content_title {properties}改成.content_title, h1 {properties}呢?如果我理解正确您的要求。 -
@Sotiris “我也不太可能更改外部 CSS 以适应我的应用程序。” - 他实际上无法编辑 css
-
@thirtydot - 没那么难,真的。 :) 我可能只是想多了,因为感觉类选择器真的应该是一个标签选择器,考虑到它的使用方式,而且我的 CSS 很简陋,让我想知道什么我不知道。感谢您的实际检查。
-
@Matt:写
<span class="content_title"></span>的人应该是.. 受过教育标题应该几乎总是<h[1..6]>标签。
标签: asp.net css master-pages css-selectors