Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

HTML & CSS CSS forms help

Thinas

New Coder
I'm newbie in CSS and need to "copy" a model as exercise. I'm having trouble "setting up" the <forms>, because I want <label> above <input>. Thanks in advance.

Expected:
on-image-dados-formulario.jpg

my output:
2022-03-30 17_35_05-.png

my HTML code:
HTML:
<form method="post">
        <label for="nome">Nome do Paciente</label>
        <input type="text" name="nome" id="nome" placeholder="ex: Thiago Martins Prado">
        <label for="data">Data da Consulta</label>
        <input type="date" name="data" id="data">
        <label for="peso">Peso (kg)</label>
        <input type="number" name="peso" id="peso" step="0.1" placeholder="ex: 70.6">
        <label for="altura">Altura (m)</label>
        <input type="number" name="altura" id="altura" step="0.1" placeholder="ex: 1.83">
        <button type="submit">Confirmar</button>
        <button type="reset">Limpar</button>
    </form>

my CSS code:
Code:
form {
    margin: 0 40px;
}

label {
    font: 18px 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;

}

input {
    border-radius: 4px;
    padding: 10px;
    margin-bottom: 20px;
}

input#nome{
    width: 100%;
}

::placeholder {
    color: #ADB5B8;
}
 

Attachments

  • on-image-dados-formulario.jpg
    on-image-dados-formulario.jpg
    102 KB · Views: 1
In your CSS, under the label add: display: block;

Also, I would highly suggest wrapping each label / input pair in a <div> element and then using something like flexbox to update the positioning of elements. Having each pair wrapped in a container tends to make working with them easier than having them all one right after the other.
 
HTML:
HTML:
<form method="post">
        <div class="form-nome">
            <label for="nome">Nome do Paciente</label>
            <input type="text" name="nome" id="nome" placeholder="ex: Thiago Martins Prado">
        
        <div class="form-data">
            <label for="data">Data da Consulta</label>
            <input type="date" name="data" id="data">
        </div>
        <div class="form-peso">
            <label for="peso">Peso (kg)</label>
            <input type="number" name="peso" id="peso" step="0.1" placeholder="ex: 70.6">
        </div>
        <div class="form-altura">
            <label for="altura">Altura (m)</label>
            <input type="number" name="altura" id="altura" step="0.1" placeholder="ex: 1.83">
        </div>
        <div class="form-botao">
            <button type="submit" class="submit">Confirmar</button>
            <button type="reset" class="reset">Limpar</button>
        </div>
    </form>


CSS:
CSS:
input {
    border-radius: 4px;
    padding: 10px;
    margin-bottom: 20px;
}

input#nome{
    width: 100%;
}

.form-nome  {
    display: flexbox;
}

.form-data {
    display: flexbox;
}

.form-peso {
    display: flexbox;
}

.form-altura {
    display: flexbox;
}

.form-botao {
    display: flexbox;
}

2022-03-30 21_50_22-.png
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom