0

I am new to coding with React and having trouble displaying my form. I am especially having problems displaying the label and input in the browser, only the topbar and logo displays. There are also no errors in the console. I would really appreciate any advice on how to fix this problem.

Form.js:

   import React, { Component } from 'react';
import classes from './Form.module.css';

class Form extends Component {
  constructor(props) {
    super(props);
    this.state = {
      username: ''
    };
  }

  handleUsernameChange = (event) => {
    this.setState({
      username: event.target.value
    });
  };

  render() {
    return (
      <div className={classes.Form}>
        <label>Username</label>
        <input
          type="text"
          value={this.state.username}
          onChange={this.handleUsernameChange}
        ></input>
      </div>
    );
  }
}

export default Form;

Form.module.js:

.input{
    outline: none;
    padding: 16px 22px;
    border: 1px solid #dadce0;
    font-size:18px;
    border-radius:5px;
    }
    .input:focus{
        border: 2px solid royalblue;
        }
  .label{
    color: #8d8d8d;
    position: absolute;
    top: 27px;
    left: 55px;
    background: #ffffff;
    transition: 300ms;
    transform: translate(-50%, -50%)}

App.js

import React from 'react';
import './App.css';
import Topbar from './Topbar';
import Form from './Form';

function App() {
  return (
    <div className="App">
      <Topbar />
      <Form />
    </div>
  );
}

export default App;

Thanks in advance!

2
  • Could you share the Form.js code? As of now Form.js and App.js contents are identical. Commented Jun 23, 2022 at 11:47
  • Hi thank you, I just managed to solve my problem Commented Jun 23, 2022 at 11:52

1 Answer 1

1

I changed the contents in Form.module.js to

.Form > input{
.Form > label{

and now both the label and input displays in the browser.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.