2015-05-08 63 views
2

我遇到了一些問題。 我把div放在一個沒有mastrerpage的html中,它完美的工作--css工作,但是當我把它放在一個帶masterpage的html中時,它並沒有。 的CSS:主頁面CSS文件與HTML等效鏈接不正確

@import url(http://fonts.googleapis.com/css?family=Roboto:500,100,300,700,400); 

.cont { 
width: 93%; 
max-width: 350px; 
text-align: center; 
margin: 4% auto; 
padding: 30px 0; 
background: #111; 
color: #EEE; 
border-radius: 5px; 
border: thin solid #444; 
overflow: hidden; 
} 

hr { 
margin: 20px; 
border: none; 
border-bottom: thin solid rgba(255,255,255,.1); 
} 

div.title { font-size: 2em; } 

h1 span { 
font-weight: 300; 
color: #Fd4; 
} 

div.stars { 
width: 270px; 
display: inline-block; 
} 

input.star { display: none; } 

label.star { 
float: right; 
padding: 10px; 
font-size: 36px; 
color: #444; 
transition: all .2s; 
} 

input.star:checked ~ label.star:before { 
content: '\f005'; 
color: #FD4; 
transition: all .25s; 
} 

input.star-5:checked ~ label.star:before { 
color: #FE7; 
text-shadow: 0 0 20px #952; 
} 

input.star-1:checked ~ label.star:before { color: #F62; } 

label.star:hover { transform: rotate(-15deg) scale(1.3); } 

label.star:before { 
content: '\f006'; 
font-family: FontAwesome; 
} 

沒有母版的HTML:

<head runat="server"> 
<link rel="Stylesheet" href="StyleSheetStars.css" type="text/css" /> 
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/fontawesome/4.2.0/css/font-awesome.min.css"> 
<title></title> 
</head> 
<body> 
<form id="form1" runat="server"> 
<div class="stars" > 
    <input class="star star-5" id="star5" type="radio" name="star" runat="server"/> 
    <label class="star star-5" for="star5"></label> 
    <input class="star star-4" id="star4" type="radio" name="star" runat="server"/> 
    <label class="star star-4" for="star4"></label> 
    <input class="star star-3" id="star3" type="radio" name="star" runat="server"/> 
    <label class="star star-3" for="star3"></label> 
    <input class="star star-2" id="star2" type="radio" name="star" runat="server"/> 
    <label class="star star-2" for="star2"></label> 
    <input class="star star-1" id="star1" type="radio" name="star" runat="server"/> 
    <label class="star star-1" for="star1"></label> 
    </div> 

</form> 
</body> 
</html> 

與母版的HTML:

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> 
<link rel="Stylesheet" href="StyleSheetStars.css" type="text/css" /> 
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css"> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> 
<div class="stars" > 
    <input class="star star-5" id="star5" type="radio" name="star" runat="server"/> 
    <label class="star star-5" for="star5"></label> 
    <input class="star star-4" id="star4" type="radio" name="star" runat="server"/> 
    <label class="star star-4" for="star4"></label> 
    <input class="star star-3" id="star3" type="radio" name="star" runat="server"/> 
    <label class="star star-3" for="star3"></label> 
    <input class="star star-2" id="star2" type="radio" name="star" runat="server"/> 
    <label class="star star-2" for="star2"></label> 
    <input class="star star-1" id="star1" type="radio" name="star" runat="server"/> 
    <label class="star star-1" for="star1"></label> 
</div> 

</asp:Content> 

Than't猜想看起來像: whene I choose nothing

whene I choose someting

五言代碼(與母版頁):

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head><title> 

</title> 
<link rel="Stylesheet" href="StyleSheetStars.css" type="text/css" /> 
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css"> 
</head> 
<body> 
<form method="post" action="Default2.aspx" id="form1"> 
<div class="aspNetHidden"> 
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTk3NjIwNTUxMGQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgUFH2N0bDAwJENvbnRlbnRQbGFjZUhvbGRlcjEkc3RhcjUFH2N0bDAwJENvbnRlbnRQbGFjZUhvbGRlcjEkc3RhcjQFH2N0bDAwJENvbnRlbnRQbGFjZUhvbGRlcjEkc3RhcjMFH2N0bDAwJENvbnRlbnRQbGFjZUhvbGRlcjEkc3RhcjIFH2N0bDAwJENvbnRlbnRQbGFjZUhvbGRlcjEkc3RhcjFwT8uSu9sOfORC1N0/HVYkxqPn1CouicTkSUkSxVv1uA==" /> 
</div> 

<div class="aspNetHidden"> 

<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="9397DC0D" /> 
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEdAAcCx8QyBKNwgVY6o3mkNcKvfQCB0pUsOJpy4fnv8J365PqbTooLxpm6rqKM1qnpL0WKM6j7xyqFjsDqMxeM+3DfnbRT9DeSeStRy6aSOUv9JHI5MYLCO3LtU7cAJVvEBlyMO7fmjkJSfq6Zbgk2kTWnqiOGYOCf0K23WNfp2M1RTaC01aLKYB4/+EAAYp0t4jA=" /> 
</div> 
<div> 

<div class="stars" > 
    <input value="star5" name="ctl00$ContentPlaceHolder1$star" type="radio" id="ContentPlaceHolder1_star5" class="star star-5" /> 
    <label class="star star-5" for="star5"></label> 
    <input value="star4" name="ctl00$ContentPlaceHolder1$star" type="radio" id="ContentPlaceHolder1_star4" class="star star-4" /> 
    <label class="star star-4" for="star4"></label> 
    <input value="star3" name="ctl00$ContentPlaceHolder1$star" type="radio" id="ContentPlaceHolder1_star3" class="star star-3" /> 
    <label class="star star-3" for="star3"></label> 
    <input value="star2" name="ctl00$ContentPlaceHolder1$star" type="radio" id="ContentPlaceHolder1_star2" class="star star-2" /> 
    <label class="star star-2" for="star2"></label> 
    <input value="star1" name="ctl00$ContentPlaceHolder1$star" type="radio" id="ContentPlaceHolder1_star1" class="star star-1" /> 
    <label class="star star-1" for="star1"></label> 
</div> 
<br /> 
<input type="submit" name="ctl00$ContentPlaceHolder1$Button1" value="Button" id="ContentPlaceHolder1_Button1" /> 
<span id="ContentPlaceHolder1_Label1">Label</span> 
<br /> 

</div> 
</form> 
</body> 
</html> 

與母版不這樣做的黃色部分。什麼我可以做的HTML?

謝謝:)

+0

這就是母版頁的ASP。你可以展示實際的HTML,它可以讓瀏覽器停下來嗎? –

+0

對不起,我真的不明白..你想讓我拍一張照片嗎? :) –

+0

號查看來源。發佈而不是或除了ASP之外。 –

回答

1

在我看來,該路徑你的CSS文件不是從母版正確。

您的母版頁或CSS文件或ASPX在一個單獨的文件夾?如果是的話,你應該在CSS文件鏈接爲使在母版文件:

<link rel="Stylesheet" href="~/StyleSheetStars.css" type="text/css" runat="server" /> 

~/進入到應用程序的根。再次,這取決於你的目錄結構,但我有一個預感,這是你的問題的根源。您還需要runat="server"屬性。

請注意,~/在傳統HTML中不起作用,但在aspx文件中使用時是有效的路徑。

請參閱類似SO問題here

+0

非常感謝你的答案,但它仍然無法正常工作。 :( 一些CSS屬性正在工作,例如:懸停正在工作(星星移動),但填充不是(他們不塗黃色)。這就像主頁決定忽略一些CSS代碼.. 。 –

+1

在你的瀏覽器中點擊F12(包括IE,Chrome),你可以在資源標籤或類似文件中找到正確鏈接的css文件,如果它被加載,那麼你的css可能會有其他問題。例如,如果你的黃色星星是一個圖像,那麼圖像的路徑可能不正確。對於CSS,img路徑相對於CSS文件而不是實際頁面。 (即'../圖像/ sample.png',而不是'圖像/ sample.png'或類似) – chadiusvt

+0

我可以看到的CSS工作exept一部分: input.star-5:checked ~ label.star:before { color: #FE7; text-shadow: 0 0 20px #952; } input.star-1:checked ~ label.star:before { color: #F62; } 你有想法,爲什麼一切正常excpet那些線? –