具有单独样式表的HTML更改网页外观

时间:2018-03-01 19:03:49

标签: html css

当样式位于同一HTML文件中时,页面按预期显示。当样式被拆分为单独的CSS文件和HTML文件中的链接时,页面格式会发生变化。

请您检查分割文件中应更改的内容以获得相同的外观。 (不包括图像)

HTML code:



<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Split Check</title>
    <link rel="stylesheet" href="link.css">
</head>
<body>
    <header class="container1">
        <figure><img class="logo" src="image.jpg" alt="Alt"></figure>
        <div class="hdr_txt">FULL NAME
            <div class="c1_font">DESIGNATION</div>
        </div>
    </header>
    <hr class="line">
</body>
&#13;
&#13;
&#13;

这是CSS:

&#13;
&#13;
<style>

* {
    box-sizing: border-box;
    max-width: 100%;
    max-height: 100%;
    margin: 10px auto;
}

.container1 {
    position: relative;
    max-width: 80%;
}

.logo {
    float: left;
    max-width: 20%;
    max-height: 5%;
}

.hdr_txt {
    float: right;
    margin-top: 5%;
    width: 60%;
    font-size: 3vw;
    font-family: "Helvetica Neue";
    direction: rtl;
}

.c1_font {
    font-size: 2vw;
    font-family: Times;
    direction: rtl;
}

.line {
    width: 80%;
    height: 10%;
    border-bottom: 3px solid #7d97ad;
}

</style>
&#13;
&#13;
&#13;

一站式代码

&#13;
&#13;
<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Split Check</title>
    <style>

* {
    box-sizing: border-box;
    max-width: 100%;
    max-height: 100%;
    margin: 10px auto;
}

.container1 {
    position: relative;
    max-width: 80%;
}

.logo {
    float: left;
    max-width: 20%;
    max-height: 5%;
}

.hdr_txt {
    float: right;
    margin-top: 5%;
    width: 60%;
    font-size: 3vw;
    font-family: "Helvetica Neue";
    direction: rtl;
}

.c1_font {
    font-size: 2vw;
    font-family: Times;
    direction: rtl;
}

.line {
    width: 80%;
    height: 10%;
    border-bottom: 3px solid #7d97ad;
}

</style>

</head>
<body>
    <header class="container1">
        <figure><img class="logo" src="image.jpg" alt="Alt"></figure>
        <div class="hdr_txt">FULL NAME
            <div class="c1_font">DESIGNATION</div>
        </div>
    </header>
    <hr class="line">
</body>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

从外部CSS文件中删除<style> </style>标记:

段:

* {
  box-sizing: border-box;
  max-width: 100%;
  max-height: 100%;
  margin: 10px auto;
}

.container1 {
  position: relative;
  max-width: 80%;
}

.logo {
  float: left;
  max-width: 20%;
  max-height: 5%;
}

.hdr_txt {
  float: right;
  margin-top: 5%;
  width: 60%;
  font-size: 3vw;
  font-family: "Helvetica Neue";
  direction: rtl;
}

.c1_font {
  font-size: 2vw;
  font-family: Times;
  direction: rtl;
}

.line {
  width: 80%;
  height: 10%;
  border-bottom: 3px solid #7d97ad;
}
<!doctype html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Split Check</title>
</head>

<body>
  <header class="container1">
    <figure><img class="logo" src="image.jpg" alt="Alt"></figure>
    <div class="hdr_txt">FULL NAME
      <div class="c1_font">DESIGNATION</div>
    </div>
  </header>
  <hr class="line">
</body>