简体   繁体   English

为什么我的JSX元素尺寸没有减小?

[英]Why is my JSX element not reducing in size?

I have two JSX elements: one is an image and the other is a form. 我有两个JSX元素:一个是图像,另一个是表单。 I'm putting them in a span because I want them next to each other, but for some reason, the div container with the form fills up the entire width of the window and renders below the image. 我将它们放在一个跨度中是因为我希望它们彼此相邻,但是由于某种原因,具有表单的div容器会填满窗口的整个宽度并在图像下方进行渲染。 When I use inline styling, it reduces the size of the form, but the entire container remains too large. 当我使用内联样式时,它会减小表单的大小,但是整个容器仍然太大。 This is what I have: 这就是我所拥有的:

<span>
 <Logo />
 <SearchComponent
  style={{ width: "500px" }}
 />
</span>

The code for the form in the component is: 组件中表单的代码为:

<form onSubmit={this.handleSubmit}>
 {this.getForm()}
 <input
  type="submit"
  value={this.getValue()}
 />
</form>

And this is what my output looks like (container highlighted for clarity): 这就是我的输出结果(为清楚起见,容器高亮显示):

在此输入图像描述

As 2pha says, divs normally displays as block element. 正如2pha所说,div通常显示为块元素。 Even you put both component inside the span, it seams you wrapped the SearchComponent using <div> element. 即使将两个组件都放在跨度内,它SearchComponent使用<div>元素来包装SearchComponent

You can try to add style display:inline-block to your wrapper div as 2pha mentioned in the comment. 您可以尝试将样式display:inline-block添加到包装div中,如注释中提到的2pha Otherwise you can try to wrap your component using <span> tag instead of <div> . 否则,您可以尝试使用<span>标记而不是<div>来包装组件。

PS: If you you are using bootstrap or some kind of CSS framework you can try to use the grid system to easily put it in the same row and also make it more responsive. PS:如果您使用的是引导程序或某种CSS框架,则可以尝试使用网格系统轻松地将其放在同一行中,并使其响应速度更快。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM