Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

update style with javascript react components

import { useState } from 'react';

const App = () => {

  const [ color, setColor ] = useState('#fff');
  const [ backgroundColor, setBackgroundColor ] = useState('#f44');

  return (
    <p style={{ 'color': color, 'backgroundColor': backgroundColor }} >
      Hello world
    </p>
  );
};

export default App;
Comment

inline style react

// You are actuallty better off using style props
// But you can do it, you have to double brace
// and camel-case the css properties
render() {
	return (
    	<div style={{paddingTop: '2em'}}>
      		<p>Eh up, me duck!</p>
      	</div>
    )
}
Comment

inline styling react

//double brackets, quotations around both key and value in css
<span style={{"font-weight": "750"}}>React Inline Styling </span>
Comment

use style in react

// use inline style in react
const myFunction = () => {
	return (
     <p style={{ fontSize: 24, margin: '0 auto', textAlign: 'center'}}>
       Hello world
    </p>
    );
}
Comment

inline styling in react

render() {
    return (
         <p style={{color: 'red'}}>
            Example Text
        </p>
    );
}
Comment

using inline styling in React

function MyComponent(){
2
3return <div style={{ color: 'blue', lineHeight : 10, padding: 20 }}> Inline Styled Component</div>
4
5}
Comment

jsx style styling

style={{color: "white",
        backgroundColor: '#f1356d',
        borderRadius: '8px'
       }}
Comment

jsx inline style

<div style={{ width: '200px', backgroundColor: 'red' }}>Something</div>
Comment

react div style

return <div style={{display: 'inline-block'}}>
Comment

Styling React Using CSS

//Use backgroundColor instead of background-color:
const Header = () => {
  return (
    <>
      <h1 style={{backgroundColor: "lightblue"}}>Hello Style!</h1>
      <p>Add a little style!</p>
    </>
  );
}
Comment

inline styling in react

style={ someCondition ? { textAlign:'center', paddingTop: '50%'} : {}}
Comment

react style

marginHorizontal
alignContent
alignSelf
aspectRatio
borderBottomWidth
borderEndWidth
borderLeftWidth
borderRightWidth
borderStartWidth
borderTopWidth
borderWidth
bottom
display
end
flex
flexBasis
flexDirection
flexGrow
flexShrink
flexWrap
height
justifyContent
left
margin
marginBottom
marginEnd
alignItems
marginLeft
marginRight
marginStart
marginTop
marginVertical
maxHeight
maxWidth
minHeight
minWidth
overflow
padding
paddingBottom
paddingEnd
paddingHorizontal
paddingLeft
paddingRight
paddingStart
paddingTop
paddingVertical
position
right
start
top
width
zIndex
direction
Comment

inline styling react

// Change the background color to red
document.body.style.backgroundColor = "red"; 
Comment

css in reactjs

Assuming you have 2 separate files: Example.css and Example.js

Use the '.' to reference a className that you'll use later 

.primary{
	color: red;
}

<h1 className="primary"> Hello, World </h1>

In this case "primary" in the className is referencing .primary in the CSS file
Comment

inline style react

// Typical component with state-classes
<ul className="todo-list">
  {this.state.items.map((item,i)=>({
<li 
 className={classnames({ 'todo-list__item': true, 'is-complete': item.complete })}>
            {item.name}
</li>
 })}
</ul>

// Using inline-styles for state
<li className='todo-list__item'
 style={(item.complete) ? styles.complete : {}} />
Comment

PREVIOUS NEXT
Code Example
Javascript :: gesture handling with react native expo 
Javascript :: usereducer react js 
Javascript :: arraylist to json array 
Javascript :: javascript redirect with extra url arguments 
Javascript :: nodejs base64 
Javascript :: how to add items in an array in js 
Javascript :: equivalent method load jquery with javascript 
Javascript :: how to call function from parent component in child component vue 
Javascript :: get element by xpath 
Javascript :: at in js 
Javascript :: reactjs dynamic route 
Javascript :: .on click jquery 
Javascript :: jquery selector parent on hover 
Javascript :: mongoose delete 
Javascript :: http request javascript 
Javascript :: faker random from array 
Javascript :: timeout 
Javascript :: javascript classes and how to import them 
Javascript :: get the whole value of a number javascript 
Javascript :: generate random color 
Javascript :: nodejs call api 
Javascript :: promise.race polyfill 
Javascript :: how to destroy cookie in javascript 
Javascript :: Conflicting peer dependency: react@18.0.0 npm WARN node_modules/react 
Javascript :: my loader is continously loading js 
Javascript :: unix to date in javascript 
Javascript :: how to seperate words seperated by commas using javascript 
Javascript :: convert an object to an array 
Javascript :: jest listen EADDRINUSE: address already in use :::5000 jest 
Javascript :: javascript round off 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =