I Have a React div tag below which actually holds json tree. The problem is overflow-x for horizontal scroll is not working. I am posting the code and error below.Is there any way for horizontal scroll using css in react.Vertical scroll is automatically working if mere overflow: 'scroll' is given.
const divStyle={
overflow-y: 'scroll',
border:'1px solid red',
width:'500px',
float: 'left',
height:'500px',
position:'relative'
};
<div style={divStyle}>
<Droppable
types={['yolo']}
style={droppableStyle}
onDrop={this.onDrop.bind(this)}
onDragEnter={this.onDragEnter.bind(this)}
onDragLeave={this.onDragLeave.bind(this)}>
<div style={{textAlign:'left', lineHeight:'100px' ,overflow:'scroll'}}>{this.state.dropped}</div>
</Droppable>
</div>
strong text tag(parent) overflow-x if given it gives error as below.
./src/Drag.js Syntax error: Unexpected token, expected , (38:16)
36 | render() { 37 | const divStyle={
38 | overflow-y: 'scroll', | ^ 39 | border:'1px solid red', 40 | width:'500px', 41 | float: 'left',
Scroll Methodsvar Scroll = require('react-scroll'); var Element = Scroll. Element; var scroller = Scroll. scroller; <Element name="myScrollToElement"></Element> // Somewhere else, even another file scroller.
Scroll to an Element With the React Refs (References): The most simple way is to use ref to store the reference of the element that you want to scroll to. And call myRef. current. scrollIntoView() to scroll it into the view.
Create components folder in the src. Write below code, const Scroll = () => { return null; } export default Scroll; Import scrollbar from smooth-scrollbar.
U need to set window. scrollTo(0, 0) when u click on link so it would start on top of page.
Try this:
style={{overflowX : 'auto',fontSize: '14px'}}
for inline css in reactjs.
It works fine.
All styles with a dash is converted to camel case in reactjs and remove dash.
Remember that divStyle
is an object and object keys, just like other identifier names, such as function names, etc, cannot have dashes/hyphens unless the key is written as a string literal.
However, react recognizes only the CamelCase version, so use that instead:
const divStyle={
overflowY: 'scroll',
border:'1px solid red',
width:'500px',
float: 'left',
height:'500px',
position:'relative'
};
Here's a snippet from the official Reactjs docs:
The
style
attribute accepts a JavaScript object with camelCased properties rather than a CSS string. This is consistent with the DOMstyle
JavaScript property, is more efficient, and prevents XSS security holes. For example:const divStyle = { color: 'blue', backgroundImage: 'url(' + imgUrl + ')', }; function HelloWorldComponent() { return <div style={divStyle}>Hello World!</div>; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With