如何在React-Bootstrap组件中添加类名/ID? [英] How to add a classname/id to React-Bootstrap Component?

查看:382
本文介绍了如何在React-Bootstrap组件中添加类名/ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们正在使用React-Bootstrap中的Row ...如何在不使用包装器或内部元素的情况下为其设置样式:

Suppose we are using Row from React-Bootstrap... How do we style it without using a wrapper or inner element:

<Row>
  <div className='some-style'>
   ...
</Row>

理想情况下,我们可以这样做:

Ideally we could just do:

<Row className='some-style> 
  ...
</Row>

但是这不起作用,我认为这是因为React-Bootstrap不知道className在Row组件中的位置(它应该只是对具有我认为的行样式的div进行样式设置)

But this doesn't work and I'd presume it's because React-Bootstrap does not know where the className goes within the Row component (it should just style the div that has the row's styles I think)

推荐答案

如果您查看),它将实际上设置元素的id属性.

If you look at the code for the component you can see that it uses the className prop passed to it to combine with the row class to get the resulting set of classes (<Row className="aaa bbb"... works).Also, if you provide the id prop like <Row id="444" ... it will actually set the id attribute for the element.

这篇关于如何在React-Bootstrap组件中添加类名/ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆