0

我知道这听起来像是一个很常见的问题,但我搜索了整个堆栈溢出并找不到任何东西。我现在遇到的问题是顶部的 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;
}
4

1 回答 1

0

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

Student { display: block }

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

一个元素不会因为其子元素是块元素而在渲染中成为块元素。

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

于 2013-09-10T20:12:31.963 回答