2014-02-19 33 views
0

我爲我的網站創建了一個header.php。 對於我的菜單,我創建了5個按鈕。 當我按下按鈕時,它會將頁面重定向到與之關聯的頁面上。 直到現在一切都很好。標題菜單中的按鈕php

我想要的是,在當前頁面上,與其關聯的頁面的按鈕更改爲其他顏色或背景圖像。

我不知道我們是否可以做到這一點,如果我自我解釋。

這裏我的header.php

<div id="main_menu"> 
    <div id="menu_blog"><button onclick="location.href='blog.html'"><h1>Trucs/Astuces</h1></button></div> 
    <div id="menu_contact"><button onclick="location.href='/contact.php'"><h1>Contact</h1></button></div> 
    <div id="menu_soumission"><button onclick="location.href='/soumission.php'"><h1>Soumission</h1></button></div> 
    <div id="menu_realisation"><button onclick="location.href='/realisations.php'"> 
    <h1>Réalisations</h1></button></div> 
    <div id="menu_service"><button onclick="location.href='/services.php'"> 
    <h1>Services</h1></button></div> 
    <div id="menu_a_propos"><button onclick="location.href='/a_propos.php'"><h1>L'entreprise</h1></button></div> 
</div> 
+0

? - 另外,你是否使用任何類似WordPress的東西 - 或只是直接的PHP? – sheriffderek

回答

0

簡單的方法是使用CSS

#yourbutton:hover{ 
background-color: red; 
} 

#yourbutton:active{ 
    background-color: red; 
} 
+1

我認爲OP想要知道他們在哪個頁面上,並在「當前」頁面的鏈接中添加一個類。 – sheriffderek

0

傳遞一個GET值與每個環節

<div id="menu_contact"><button onclick="location.href='/contact.php?active=1'"><h1>Contact</h1></button></div> 

檢查的活躍值的按鈕

< button <?php if ($_GET['active']==1) echo 'class="active"'; ?> ..../> 

然後做一個CSS樣式爲活動類

.active{ 

    /*your style here*/ 
} 
0

你的PHP頁面:

​​

你的CSS:

button.currentPage{ 
    background-color: red; 
} 
0

短版:它之後

加$ CURRENT_LOCATION到每一個網頁,並將它命名

<?php 
$current_location = "a_propos" ; 
?> 

檢查位置是正確的,那麼你爲什麼要使用按鈕,而不是鏈接改變背景顏色

<div id="main_menu"> 
    <div id="menu_a_propos"><button <?php if ($current_location == "a_propos");?> style=" background-color: red;"<?php };?> onclick="location.href='/a_propos.php'"><h1>L'entreprise</h1></button></div> 
</div>