2014-08-30 164 views
-1

Wordpress未加載我的CSS文件。樣式表上有一個以標題圖片爲中心的項目,但它不會。它甚至不會將它保留爲100px。我究竟做錯了什麼?我可以嘗試什麼?樣式表不要在WordPress中出現

<head> 
    <title><?php echo $title; ?></title> 
<link rel="stylesheet" href="/style.css" type="text/css" media="screen" /> 
</head> 
<body> 
     <center><img id="image" src="http://www.passionatemedia.ca/wp-content/uploads/2014/08/cropped-top-banner.jpg" width="950"/></center> 
     <center><img id="image" src="http://www.passionatemedia.ca/wp-content/uploads/2014/08/navigation.jpg" width="950" /></center> 
<!-- end header --> 

EDIT增加的CSS

#image { 
     margin-left:500px; 
     display:block; 
} 
#headerImg { 
      margin-left:auto; 
      margin-right:auto; 
} 

仍無法正常工作:NEW CODE

HTML/PHP

<head> 
    <title><?php echo $title; ?></title> 
<link href="<?php bloginfo('template_directory'); ?>/style.css" rel="stylesheet"> 
</head> 
<body> 
<div id="headerImg"> 
     <img src="<?php bloginfo('template_directory'); ?>/images/top-banner.jpg" width="950"/> 
</div> 
<!-- end header --> 

CSS

div.headerImg { 
    margin:0px; 
    margin-left:auto; 
    margin-right:auto; 
    width:950px; 
} 

幫助任何人?

+0

那些中心標籤不在FTP中的代碼中。我只是錯誤地添加了它們。 – SereneTheif 2014-08-30 02:25:07

回答

0

需要調用WordPress的樣式表是這樣的:

<link href="<?php bloginfo('template_directory'); ?>/style.css" rel="stylesheet"> 

也適用於你的主題圖片和腳本,以及,你需要使用

<a href="<?php bloginfo('template_directory'); ?>/....... 

<img src="<?php bloginfo('template_directory'); ?>/images/....... 

或其他

EDIT顯示代碼:

替換此:

<center><img id="image" src="http://www.passionatemedia.ca/wp-content/uploads/2014/08/cropped-top-banner.jpg" width="950"/></center> 

與此:

<div class="centerbox"><img src="http://www.passionatemedia.ca/wp-content/uploads/2014/08/cropped-top-banner.jpg" alt="" /> 
<img src="http://www.passionatemedia.ca/wp-content/uploads/2014/08/navigation.jpg" alt="" /></div> 

現在,在CSS:

.centerbox{text-align:center} 
.centerbox img{width:950px; margin:0 /* <----adjust this to your liking */ auto} 

當然你需要刪除/* <----adjust this to your liking */部分,我評論說,所以你可以第一眼看到它。另外,除非絕對必要,否則不要使用ID。改用類。在你的原代碼,兩個圖像具有相同的ID,這不僅是錯誤的,但具有不可預知的結果

+0

它的工作,但現在它消失了,並推動了太多。我可以添加一個右邊距:500px;解決這個問題? – SereneTheif 2014-08-30 02:33:20

+0

你需要添加你的CSS,我們不知道你有什麼它 – Devin 2014-08-30 02:35:29

+0

css已被添加在 – SereneTheif 2014-08-30 03:21:13

0

<img>元素直列,所以他們基本上是放在像文本的HTML文檔。要正確格式化它們,您可能需要將它們放入元素,例如<div>。這樣,您可以通過將<div><div>的左右頁邊距設置爲auto來設置它們的格式。

根據https://developer.mozilla.org/en-US/docs/Web/HTML/Element/center,通常,儘量避免使用<center>元素,因爲它是一個不推薦的元素。