我正尝试使用外部样式页面对页面进行样式设置。我的一些div选择了所有的样式,有些则没有。特别是,其中包含图像文件的所有样式都采用除高度和/或宽度之外的所有样式。 z位置,左侧,顶部等都工作正常。我检查了DOM浏览器,并没有显示它从body标签继承它的大小,但我无法弄清楚为什么它不会正确调整大小。外部CSS高度不起作用
HTML:
<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset = "utf-8" />
<link rel="stylesheet" type="text/css" href="race_inprogress.css">
<script type='text/JavaScript' src="race.js" language=javascript></script>
</head>
<body>
<h1 class = "amazing"> The Amazing Race For an A! </h1>
<h1 class = "fordmeis"> Professor Ford Vs Michael Meis </h1>
<div id="traffic-light">
<div id="stopLight" class="bulb"></div>
<div id="slowLight" class="bulb"></div>
<div id="goLight" class="bulb"></div>
</div>
<input type=button onClick="illuminateGreen();timer();" value='Go!' style="position: absolute; left: 545px; top:265px;">
<div class = "racer1">
<img src=images/teacher.jpg id='i1'>
</div>
<br><br><br><br>
<div class = "racer2">
<img src=images/meis.png id='i2'>
</div>
<div class = "road1">
<img src=images/road.jpg>
</div>
<div class = "road2">
<img src=images/road.jpg>
</div>
<div class = "winners">
<img src=images/winner_ford.png id='image1' onclick="reset()">
<br><br><br><br>
<img src=images/winner_meis.png id='image2' onclick="reset()">
</div>
<script>
illuminateRed()
hideImage()
</script>
<div class="vertical-line">
</div>
</body>
</html>
CSS:
html
{
height: 100%;
width: 100%;
}
body
{
font-family: sans-serif;
background: url("images/checkback.png");
background-repeat: no-repeat;
background-size: cover;
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
overflow-x: hidden;
}
div.racer1
{
width: 10px;
position:absolute;
left: 25px;
top: 325px;
z-index: 2;
}
div.racer2
{
width: 10px;
position:absolute;
left: 25px;
top: 500px;
z-index:2;
}
div.road1
{
position:absolute;
left: 30px;
top: 325px;
z-index: 1;
height: 133px;
width: 1180px:
}
div.road2
{
position: absolute;
left: 30px;
top: 500px;
z-index: 1;
height: 133px;
width: 1180px;
}
div.winners
{
position:absolute;
left: 5px;
top: 0px;
z-index: 3;
width: 100%;
height: 100%;
}
h1.amazing
{
font-size: 30px;
position: relative;
top: 150px;
left: 20px;
color: gold;
}
h1.fordmeis
{
font-size: 30px;
position: relative;
top: 90px;
left: 700px;
color: gold;
}
#traffic-light
{
height: 200px;
width: 100px;
left: 500px;
position: absolute;
background-color: #333;
border-radius: 40px;
margin: -100px 0;
padding: 20px;
}
.bulb
{
height: 50px;
width: 50px;
background-color: #111;
border-radius: 50%;
margin: 15px auto;
transition: background 500ms;
}
div.vertical-line
{
width: 0px;
height: 315px;
top: 55px;
position:relative;
left: 1200px;
color: gold;
border: 10px inset;
z-index: 1;
}
它使用内联标签很好,但这是针对学校项目和在课程开始时指定的使用外部样式表的指导员 –
试试这一个 .racer1 img {height:100%; 宽度:100%; } –
标签上的啊,width =“”不是CSS,而是实际的HTML标签属性。如果您在技术上进入页面渲染和绘画,建议图像至少有一个宽度设置,以便没有多个计算。添加类似style =“width:100px”的属性将被视为内联样式。 –