How to style, with CSS, a SELECT that is inside PHP?

0
<?php

    include "conexao.php";

    $sql = "select * from categorias";
    $dados = pg_query($sql);
    $resposta = "";

    while($linha = pg_fetch_array($dados)){
        $nome_categoria = $linha["nome_categoria"];
        $resposta .= "<option>".$nome_categoria."</option>";
    }

    $categoria = "<select>". $resposta."</select>";
    pg_free_result($dados);

?>

HTML

<tr><td><a class="itens">Categoria:</td>
<td><?php echo $categoria;?></a></td></tr>
    
asked by anonymous 22.10.2014 / 01:57

1 answer

10

The fact that select is generated by PHP does not make any difference as to its stylization. Remember, your PHP script is returning HTML, which is rendered in the browser.

As for stylization, note that the select element can be stylized more freely than option elements, which has many of its properties limited by the browser used.

To stylize, you can use a class, an id, or the actual select tag (note that the latter will style all select , which may or may not be what you want).

select {
    font-family: 'Verdana', sans-serif;
    font-size: 14px;
}

If you want to use a class, put it in your PHP:

$categoria = "<select class='minha-classe'>". $resposta."</select>";

Then in CSS:

select.minha-classe {
    font-family: 'Verdana', sans-serif;
    font-size: 14px;
}
    
22.10.2014 / 02:23