HTML 到 CSS 链接不起作用

标签 html css hyperlink

我的 html 文件中的链接无效。不过,我不确定是不是其他原因。当我运行该文件时,屏幕上没有任何显示。应该有五个不同颜色的矩形(你可能会想出来)。这可能是一个非常简单的修复,但我是初学者,需要一些快速帮助。这是我的 html:

<!DOCTYPE html>
<html>
    <head>
         <link rel="stylesheet" type="text/css" href="stylesheet.css">
    </head>
    <body>
        <div id="play"></div>
        <div id="create"></div>
        <div id="yellow"></div>
        <div id="green"></div>
        <div id="purple"></div>
    </body>
</html>

这是我的 CSS:

#play {
    background-color:#FF0000;
    height: 70%;
    width: 60%;
}

#create {
    background-color:#0000FF;
    position: relative;
    height: 28%;
    width: 60%;
    top:2%;
}

#yellow {
    background-color:#E2BE22;
    height: 28%;
    width: 39%;
    position: relative;
    left: 61%;
    bottom: 26%;
}

#green {
    background-color:#008800;
    position: relative;
    height: 34%;
    width: 39%;
    left: 61%;
    bottom: 90%;
}

#purple {
    background-color:purple;
    position:relative;
    height: 34%;
    width: 39%;
    left: 61%;
    bottom: 160%;
}

最佳答案

没有显示任何内容,因为您的 body 零尺寸:

只需将此添加到您的 CSS 中:

body {
  width: 100vw;
  height: 100vh;
}

JsFiddle

html, body {
    width: 100vw;
    height: 100vh;
}

#play {
    background-color:#FF0000;
    height: 70%;
    width: 60%;
}

#create {
    background-color:#0000FF;
    position: relative;
    height: 28%;
    width: 60%;
    top:2%;
}

#yellow {
    background-color:#E2BE22;
    height: 28%;
    width: 39%;
    position: relative;
    left: 61%;
    bottom: 26%;
}

#green {
    background-color:#008800;
    position: relative;
    height: 34%;
    width: 39%;
    left: 61%;
    bottom: 90%;
}

#purple {
    background-color:purple;
    position:relative;
    height: 34%;
    width: 39%;
    left: 61%;
    bottom: 160%;
}
        
<div id="play"></div>
<div id="create"></div>
<div id="yellow"></div>
<div id="green"></div>
<div id="purple"></div>

关于HTML 到 CSS 链接不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38761766/

相关文章:

javascript - 如何通过 Javascript 从 HTML 文件连接到 Sqlite 数据库

javascript - 干净且跨浏览器友好的方式加载大型背景视频

css - 将 3 个 div 对齐到父级的左侧,并有一些重叠

CSS 选择器 : first paragraph's first letter inside a div

google-chrome - Chrome 浏览器可以打开本地链接吗?

javascript - 使用 JavaScript - 循环遍历每个 <li> 并添加带有链接的图片以转到每个 li 中的新页面

javascript - 检索单击元素的父级

javascript - AngularJS:向 Angular-rating-icons 添加工具提示?

javascript - Div 显示隐藏选择

javascript - 使用JS更改链接