我正嘗試使用外部樣式頁面對頁面進行樣式設置。我的一些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」的屬性將被視爲內聯樣式。 –