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

问题描述 投票:1回答:1

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

你能否检查一下在分割文件中应该改变什么来获得相同的外观。 (没有包含图片)

HTML代码:

<!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>

这是CSS:

<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>

所有在一个代码中

<!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>
html css
1个回答
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>
© www.soinside.com 2019 - 2024. All rights reserved.