0

First question, so be forgiving if you can:

Using PHP I've created a site where users enter info and it is saved to database. Users then style each entry (font, size, color, and location). A string is saved into the database for each parameter, and then I use PHP to echo out a DIV with the custom styling:

echo "<div id=\"customized\"";
        if(isset($backtype)){if($backtype == "image") {echo "style=\"background-image:url('".$backurl."');          
            background-repeat: no-repeat; background-size: 400px 200px\"";}}    
        if(isset($backtype)){if($backtype == "color"){echo "style=\"background-color:".$backcolor."\"";}}echo ">";

if($namepos !== ""){echo "<div id=\"".$namepos."\" style=\"font-family:".$namefont."; font-size:".$namesize."; color:".$namecolor.";\">".$name."</div>";}

After getting strings from database this becomes:

<div id="customized" style="background-image:url('raptor.gif'); background-repeat: no-repeat; background-size: 400px 200px ">
<div id="3_1" style="font-family:Courier New; font-size:20pt; color:#f80a8c;">Text here</div></div>

When this DIV is created all the inline styling works, but the location it display is supposed to be dictated by the $namepos, which echoes out "3_1".

I have an external CSS as follows

#customized {
    border: 1px solid grey;
    margin: 3px;
    position: absolute;
    top: 7%;
    left: 1%;
    width: 400px;
    height: 200px;
}

#3_1{
    position: absolute;
    white-space: nowrap;
    top:10%;
    left:5%;
 }

The final output completely ignores this CSS for the div that is produced by doing echo $namepos, but works perfectly fine for the containing div id=" customized". I fear that I already know the answer and that it just doesn't work for the dynamically named DIV, but I'm an amateur and if this is true then it's a serious setback, so I come here hoping for a savior.

Any help would be greatly appreciated.

ric d
  • 1
  • 1
  • 1
    I dont believe div IDs can start with a number... Actually, it depends: http://stackoverflow.com/questions/5672903/can-i-have-a-div-with-id-as-number – markdwhite Dec 14 '15 at 04:59
  • 1
    @markdwhite depends on the doctype. See http://stackoverflow.com/questions/70579/what-are-valid-values-for-the-id-attribute-in-html – Phil Dec 14 '15 at 05:00
  • 1
    If your doctype says its HTML 4.01 your ID is invalid. Check this link http://www.w3schools.com/tags/att_global_id.asp – Aatman Dec 14 '15 at 05:00
  • @Phil - dead right - just edited. I should have found a source before jumping in with an answer :) – markdwhite Dec 14 '15 at 05:01

1 Answers1

0

It was the DIV starting with a number, wouldve never figured that out. much thanks for speedy reply. will now sleep without debugging nightmares.

ric d
  • 1
  • 1