php - Absolute positioned span not resizing accordingly


I'm developing a homepage using PHP, it has a menubar with dynamically loaded menu's. below the menubar is a div which i used to construct dynamic submenu which gets displayed on hover of menu on menubar.

Submenu is constructed in table and placed in span which is positioned absolutely with defined width and necessary left positioning. the problem is the width and position of span doesn't appears properly with change in screen resolution, it actually shrinks and appears some where else.

dynamically created submenu

$menu_num = 1;
$left_pos = 316;
for ($i = 0; $i < count($menu_arr); $i++) {
    $desc   = "<table width = '100%' id = 'submenu_table' cellspacing = '7' > ";
    $result = mysql_query("select s.SUB_MENU_URL, s.SUB_MENU_DESC from $table_user_menu m, $table_sub_menu s where m.EMP_ID = '".$_SESSION['EMP_ID']."' and m.SUB_MENU_ID = s.SUB_MENU_ID and m.MENU_ID = $menu_arr[$i] order by s.DISPLAY_ORDER");
    while ($row = mysql_fetch_assoc($result)) {
        $temp = " < tr><td style = 'text-align:center;' ><a href =.".$row['SUB_MENU_URL']." style = 'text decoration:none;' > ".$row['SUB_MENU_DESC']."</a ></td ></tr > ";
        $desc = $desc.$temp;
    $desc = $desc."</table > ";
    draw_submenu($desc, $menu_num, $left_pos);
    $left_pos += 141;

function draw_submenu($desc, $menu_num, $left_pos)
    $left = $left_pos."px";
    echo " < span id = 'submenu".$menu_num."' class='drop_down_menu' style = 'left:$left' > ".$desc."</span > ";

Submenu section must appear properly under Menu even when the screen resolution changes. Thanks for help.




span is an inline tag, that cannot have a width. If you like to set one, you need to set it to a block element as well:

display: block


display: inline-block

You could of course just use a div instead of a span, for that purpose.

People are also looking for solutions to the problem: php - Merge deep groups of rows by their numeric key and sum column values while grouping


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.