顶部 xml 元素"Student"不会着色



我知道这听起来像是一个很常见的问题,但我搜索了整个堆栈溢出,找不到任何东西。我现在遇到的问题是顶部 xml 元素"学生"不会从 css 中获得背景颜色。我正确地嵌套了xml和所有内容,并且我已经在我的css文件中正确拼写了XML元素。我尝试了一个 xml 验证器,文档似乎格式良好。那么可能出了什么问题呢?

这是 XML

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="stylexml.css"?>
<Registration>
    <Student>
        <Id>0001234567</Id>
        <University>Indiana University Purdue University Indianapolis</University>
        <Education>Undergraduate</Education>
        <Category>Technology Undergraduate</Category>
        <Degree>Computer Tech BS</Degree>
    </Student>
    <Semester>
        <Season>Spring Semester</Season>
        <Year>2004-2005</Year>
        <Bterm>Senior</Bterm>
        <Eterm>Senior</Eterm>
    </Semester>     
    <Class id="0">
        <Course>CIT 412</Course>
        <Number>12981</Number>
        <Section>0100</Section>
        <Description>XML-BASED WEB APPLICATIONS</Description>
        <Component>Lecture</Component>
        <Grading>Graded</Grading>
        <Grade> </Grade>
        <Units>3.00</Units>
        <Status>Enrolled</Status>
        <!--New instance of schedule only created if time or location differs on weekdays-->
        <Schedule id="0">
            <Start>1:00PM</Start>
            <End>2:15PM</End>
            <Weekday>Mon,Wed</Weekday> 
            <Location>SL SL223</Location>
        </Schedule>
        <Instructor>Fernandez, Eugenia</Instructor>
        </Class>
    <Class id="1">
        <Course>CIT 479</Course>
        <Number>12988</Number>
        <Section>0100</Section>
        <Description>DATABASE IMPLEMENTATN &amp; ADMIN</Description>
        <Component>Lecture</Component>
        <Grading>Graded</Grading>
        <Grade> </Grade>
        <Units>3.00</Units>
        <Status>Enrolled</Status>
        <Schedule id="0">
            <Start>7:15PM</Start>
            <End>8:30PM</End>
            <Weekday>Mon</Weekday> 
            <Location>SL SL223</Location>
        </Schedule>
        <Schedule id="1">
            <Start>7:15PM</Start>
            <End>8:30PM</End>
            <Weekday>Wed</Weekday> 
            <Location>SL SL216</Location>
        </Schedule>
        <Instructor> </Instructor>
    </Class>
    <Class id="2">
        <Course>MATH M-119</Course>
        <Number>15304</Number>
        <Section>0400</Section>
        <Description>BRIEF SURVEY OF CALCULUS 1</Description>
        <Component>Lecture</Component>
        <Grading>Graded</Grading>
        <Grade> </Grade>
        <Units>3.00</Units>
        <Status>Enrolled</Status>
        <Schedule id="0">
            <Start>5:45PM</Start>
            <End>7:15PM</End>
            <Weekday>Mon,Wed</Weekday> 
            <Location>LE 104</Location>
        </Schedule>
        <Instructor>Tam,Richard Yiu-Hang</Instructor>
    </Class>
</Registration>

这是 CSS:

@charset "utf-8";
/* CSS Document */
Registration
{
    font-family:"MS Serif", "New York", serif;
    font-size:16px;
    font-style:normal;
    top:0px;
    bottom:0px;
}
Student
{
    background-color:red;
}
Id,University,Education,Category,Degree
{
    display:block;
    //background-color:blue;
}
Semester
{
    background-color:yellow;
    border-bottom-style:ridge;
}
Class 
{
    margin-top:20px;
    border-style:solid;
    display:block;
    background-color:cyan;  
}
Course
{
   font-weight:bolder;
}
Description, Component
{
    display:block;
}
Schedule
{
    display:block;
}

您需要在渲染中将 Student 元素声明为 block 元素:

Student { display: block }

默认情况下,它是一个内联元素,因为在XML中,当没有样式表为属性分配值并且该属性未被继承(display不是)时,将使用初始值(inline表示display)。因此,Student将是一个可怜的孤独的内联元素,它的所有孩子都占据了他们的街区,没有留下任何背景。如果你只在Student元素中添加纯文本,你可以看到这一点:它将采用红色背景。

元素在呈现中不会仅仅因为它的子元素是块元素而成为块元素。

请注意,您的代码具有格式错误的行//background-color:blue; 。根据 CSS 错误处理规则,它将被忽略,但它仍然是一个错误;你不能在 CSS 中使用 JavaScript 注释;相反,CSS 中的注释的形式是 /* comment text */ .

最新更新