Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Nov 2011
    Location
    Morley, UK
    Posts
    41
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Style PHP in a DIV that has been called by include()

    Hi Guys

    1st question is the above possible?

    PHP Code:
    <?php ?>
    <div class =\"menulinks\">
    <?php include 'php/menu.php'?>
    </div>
    <? ?>

    I have a menu that is saved in a seperate php file
    I can successfully "call" the menu.php file

    But I cannot seem to style it with css


    PHP Code:
    echo '<a href="/index.php">Home</a>
    <a href="/Leagues.php">Leagues</a>
    <a href="/Clubs.php">Clubs</a>
    <a href="/News.php">News</a> 
    <a href="/Fixtures.php">Fixtures Us</a> 
    <a href="/Results.php">Results</a>
    <a href="/Results.php">Docs</a>
    <a href="/Results.php">Admin</a>'

    Code:
    #menulinks
    {
    color:white; 
    }

    Any help much appreciated
    Last edited by stuckupvacant; 03-20-2013 at 12:26 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    That's fine, except that the class would be invalid in HTML. There's no escape for the quotations required here.
    That would create the output
    Code:
    <div class =\"menulinks\">
    <a href="/index.php">Home</a>
    <a href="/Leagues.php">Leagues</a>
    <a href="/Clubs.php">Clubs</a>
    <a href="/News.php">News</a> 
    <a href="/Fixtures.php">Fixtures Us</a> 
    <a href="/Results.php">Results</a>
    <a href="/Results.php">Docs</a>
    <a href="/Results.php">Admin</a>
    </div>
    Which can be styled in CSS.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Nov 2011
    Location
    Morley, UK
    Posts
    41
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Hi Fou-Lu

    so what you have written, should that be applied to the seperate menu.php file?

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,292
    Thanks
    4
    Thanked 202 Times in 199 Posts
    Remove the slashes from the <div>

    PHP Code:
    <div class ="menulinks">
    <?php include 'php/menu.php'?>
    </div>
    Dave .... HostMonster for all of your hosting needs

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by stuckupvacant View Post
    Hi Fou-Lu

    so what you have written, should that be applied to the seperate menu.php file?
    Nope, you just have to correct the class value assignment. Nothing else will need to change, that's just what it will look like when its printed as output.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #6
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    nothings happening becasue class its a dot .
    # is for id

    Code:
    .menulinks
    {
    color:white; 
    }
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #7
    New Coder
    Join Date
    Nov 2011
    Location
    Morley, UK
    Posts
    41
    Thanks
    7
    Thanked 0 Times in 0 Posts
    EDIT: Does it have anything to do with them being hyperlinks?
    Does my Css have to reflect that to apply the styling?



    Clearly I'm still not understanding this

    I've tried all of these

    None have worked

    I've tried to cover all ways of writing it to see if it was just my "spelling" but still can't seem to get it to work



    PHP Code:
    <?php ?>
            <div class ="menulinks">
            <?php include 'php/menu.php'?>
            </div>
            <? ?>
            

        <?php ?>
            <div id ="menulinks">
            <?php include 'php/menu.php'?>
            </div>
        <? ?>
        
        <?php ?>
            <div id =\"menulinks\">
            <?php include 'php/menu.php'?>
            </div>
        <? ?>
        
        <?php ?>
            <div class =\"menulinks\">
            <?php include 'php/menu.php'?>
            </div>
        <? ?>
        
            <?php ?>
            <div id ="menulinks\">
            <?php include 'php/menu.php'?>
            </div>
        <? ?>
        
        <?php ?>
            <div class ="menulinks\">
            <?php include 'php/menu.php'?>
            </div>
        <? ?>
        
        <?php ?>
            <div class ="\menulinks\">
            <?php include 'php/menu.php'?>
            </div>
        <? ?>
        
        <?php ?>
            <div id ="\menulinks\">
            <?php include 'php/menu.php'?>
            </div>
        <? ?>

    Code:
    .menulinks
    {  
    color: Red; 
    font: arial;
    size: 20px; 
     }
     
    #menulinks
    {  
    color: Red; 
    font: arial;
    size: 20px; 
     }
    Last edited by stuckupvacant; 03-20-2013 at 12:26 PM.

  • #8
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    this one:
    PHP Code:
    <div class ="menulinks">
            <?php include 'php/menu.php'?>
            </div>
    for styling a link you need to declare a for <a href

    PHP Code:
    .menulinks a
    {  
    colorRed
    fontarial;
    size20px

    you can also specify colours for visited and hover

    PHP Code:

    .menulinks a
    {  
    colorRed
    fontarial;
    size20px
     }
    .
    menulinks a:visited {
        
    colorWhite;

    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • Users who have thanked Arcticwarrio for this post:

    stuckupvacant (03-20-2013)

  • #9
    New Coder
    Join Date
    Nov 2011
    Location
    Morley, UK
    Posts
    41
    Thanks
    7
    Thanked 0 Times in 0 Posts
    I managed to figure it out

    It required me to define the menu within the exeternal menu.php

    so "orignally" I had this:

    PHP Code:
    <?php ?>
            <div class ="menulinks">
            <?php include 'php/menu.php'?>
            </div>
            <? ?>
    CSS
    Code:
    .menulinks
    {  
    color: Green; 
    font: arial;
    size: 30px; 
     }
    and the php for the menu was this:

    PHP Code:
    <?php
    echo '<a href="/Fixtures.php">Fixtures Us</a> 
    <a href="/Results.php">Results</a>
    <a href="/Docs.php">Docs</a>
    <a href="/Admin.php">Admin</a>'
    ;
    ?>
    But the CSS wasn't styling the Menu

    This is the correct way (it's only a little different)

    PHP Code:
    <?php
    echo '<a href="/index.php" class="menulinks">Home</a>
    <a href="/Leagues.php" class="menulinks">Leagues</a>
    <a href="/Clubs.php" class="menulinks">Clubs</a>
    <a href="/News.php" class="menulinks">News</a> '
    ;
    ?>
    Just to make that a little clearer

    The bit in blue has been added

    <a href="/index.php" class="menulinks" >Home</a>

    That then means the CSS file (with .menulinks) will now style it

    Thanks to the other Members for their guidance
    Last edited by stuckupvacant; 03-20-2013 at 12:28 PM.

  • #10
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    see my previous post
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •