-1

So recently I learned that you can import php files within html. So it means that if I want to make a navbar, I need to write it in php and "include" it in my html later on. So my question is:

  1. How do I write the html code in php?

  2. How can I use css to style my navbar?

To clarify the second question, I mean does the css still work after I include the php file into html

davejal
  • 6,009
  • 10
  • 39
  • 82
  • Possible duplicate of [How to write html code inside ](http://stackoverflow.com/questions/18140270/how-to-write-html-code-inside-php) – codefreaK May 14 '16 at 15:40

2 Answers2

1

As for outputting HTML in php:

<?php
    echo "<p class='myTest' id='myTag'>This is some text within HTML-tags</p>";
    // Notice the use of "" and '', you do not wanna close the echo adding a class or such
?>

and as for the CSS, start by including a stylesheet in your HTML-file (in the <head> tag):

<link rel="stylesheet" type="text/css" href="myStyle.css">

and in myStyle.css, to style your HTML:

p.myTest {
    color: red;
    /* All <p> tags content with the class myTest will be written in red */
}

If you wish for your styling to be tag-specific:

p {
    color: red;
    /* All <p> tags content will be written in red */
}

Or maybe you'd like for it to be applied to a unique id instead:

#myTag {
    color: red;
    /* The content of the tag with the id "myTag" will be colored red, 
       given that color is a valid property for that specific tag */
}

There are loads of basic styling tutorials and guides out there to help getting you started styling that navbar.

Algernop K.
  • 477
  • 2
  • 19
0

If you mean how to writing HTML into php file which will be including later so you can write HTML as usual as you know without any problems inside the php file.

But if you want to write HTML into php code you will do it like that:

<?php
    echo "<div> Some content here </div>";
?>

You also can use your styles ( css ) like you was do in the basic HTML and it will affect the your included file without any problem .

Ahmed Salama
  • 2,795
  • 1
  • 11
  • 15