简体   繁体   English

我正在尝试在 React 中创建一个盒子,但它不起作用

[英]I am trying to create a box in React, and it is not working

Here is my code:这是我的代码:

   class Landing extends Component {
  state = {
    box: " width: 300px , height: 100px, border: 1px solid blue; ",
  };


  render() {
    return <div className={this.state.box}>Hello</div>;
  }
}

The idea is that "Hello" should be inside a box.这个想法是“你好”应该在一个盒子里。

Instead, what I am getting is a web page with no box, just a hello.相反,我得到的是一个没有框的 web 页面,只有一个你好。

Please help.请帮忙。

Change className to style and turn box in to a real object.className更改为style ,并将box in 变为真实的 object。

class Landing extends Component {
  state = {
    box: {width: '300px', height: '100px', border: '1px solid blue'},
  };


  render() {
    return <div style={this.state.box}>Hello</div>;
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试创建一个反应网站并在其中添加挂钩,但面临这个错误 - I am trying to create a react website and add hooks in it but face this erros 我正在尝试创建反应应用程序但失败了。 它显示错误 - I am trying to create react app but failed. It show error 我正在尝试使用反应钩子 useContext() 但它不起作用 - I am trying to use the react hook useContext() but its not working 我正在尝试使用用户通过JavaScript警报框输入的信息在HTML页面上创建链接 - I am trying to create a link on an HTML page using information that a user inputs via JavaScript alert box 我试图使用jquery获取特定隐藏输入文本框的值它不起作用 - i am trying to get value of particular hidden input text box using jquery it's not working 我正在尝试使用 Fluent UI 在 React JS 中创建一个表单,但我注意到在日期选择器中我丢失了所有图标 - I am trying to create a form in React JS using Fluent UI but the thing I noticed is that in the date picker I am missing all the icons 我是 React 新手,之前我创建了 React 应用程序但没有尝试创建 React 应用程序但是花了很长时间后出现错误 - I am new to react, previously I created react apps but not trying to create a react app but after taking a long time it is giving an error 我正在尝试创建一个动态表。 我想得到的行数等于用户在框中输入的数量 - I am trying to create a dynamic table. i want to get the number of rows equal to the number that user enters in the box 我正在尝试使用“npx/npm create-react-app hello”命令创建一个反应应用程序并得到了整个消息 - I am trying to create a react app using the “npx/npm create-react-app hello” command and got this whole message 我正在尝试使用包react-moves创建的动画无法正确渲染背景色 - The background color is not rendering correctly on an animation I am trying to create on with the package react-moves
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM