dropdown issue on navbar

I got the code from w3school and put them under my php website but the dropdown menu doesn't work. I don't know why it doesn't work on php. w3school website links is the following. https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_responsive_navbar_dropdown I deleted most of the code because it is too long to submit. Any help would be appreciated!

<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

.navbar a:hover, .dropdown:hover .dropbtn {
  background-color: red;

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f9f9f9;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;

.dropdown-content a {
  float: none;
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  text-align: left;

.dropdown-content a:hover {
  background-color: #ddd;

.dropdown:hover .dropdown-content {
  display: block;

<div class="navbar">
  <a href="#home">Home</a>
  <a href="#news">News</a>
  <div class="dropdown">
    <button class="dropbtn">Dropdown 
      <i class="fa fa-caret-down"></i>
    <div class="dropdown-content">
      <a href="#">Link 1</a>
      <a href="#">Link 2</a>
      <a href="#">Link 3</a>

1 answer

  • answered 2019-12-15 03:12 Adeeb Mark

    You Sholde Start The File That Is .php With :-

    ; ?>
     Your Code HTML Hear !

    So It Is Will Be Like This :-

    ; ?>
    <!DOCTYPE html>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font- 
     body {margin:0;font-family:Arial}
      .topnav {
      overflow: hidden;
       background-color: #333;
       ...... Till The End

    And To Make The .php File Working You Sholde Use A PHP Server Like XAMP Using LocalHost