Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add space between two elements on the same line

I am adding two element on the row

  render() {
    return (
      <View style={{ flexDirection: 'row', justifyContent: 'center' }}>
        <Icon
         name='person' 
         color='#98999c'
         onPress={this.handleClick.bind(this)} /> 
         <Text style={ styles.header }>
          { 'User Name' }
        </Text>
          
      </View>
          )
  }

How can I add a space between them?

EDIT:

I also have the same problem here:

const AppNavigator = StackNavigator({
  Home: {
    screen: AppDrawer,
    navigationOptions: ({navigation}) => ({
      headerLeft:
       <View style={{ flexDirection: 'row', justifyContent: 'space-between' }}>
      <Icon name="menu" size={35} margin={30} padding={30} onPress={ () => navigation.navigate('DrawerOpen') } />
      <ChangeLanguage style={{ margin: 30 , padding: 30}} />
      </View>,
      headerRight: 
      <HeaderUserInformation />,
    })
  }
like image 603
j.doe Avatar asked Oct 18 '17 12:10

j.doe


People also ask

How do you add a space between two elements?

Creating extra spaces before or after text To create extra spaces before, after, or in-between your text, use the &nbsp; (non-breaking space) extended HTML character. For example, with the phrasing "extra space" using a double space, we have the following code in our HTML.

How do you make a space on the same line in HTML?

character. The &nbsp; character creates a space that does not break into a new line. Two words that are separated by a non-breaking space always appear on the same line. The &#9; and &Tab; characters create tab spaces in HTML.

How do I add a space between elements in CSS?

The CSS padding properties are used to generate space around an element's content, inside of any defined borders. With CSS, you have full control over the padding. There are properties for setting the padding for each side of an element (top, right, bottom, and left).


3 Answers

You can use curly braces like an expression with both double quotes and single quotes for space i.e.,

{" "} or {' '} 

You can also use ES6 template literals i.e.,

`   <li></li>` or `  ${value}` 

You can also use &nbsp like below

<span>sample text &nbsp; <span> 

You can also use &nbsp in dangerouslySetInnerHTML when printing html content

<div dangerouslySetInnerHTML={{__html: 'sample html text: &nbsp;'}} /> 
like image 175
Hemadri Dasari Avatar answered Sep 27 '22 21:09

Hemadri Dasari


Option 1:

  • add: justifyContent: 'space-between' to the View

Option 2:

  • add padding / margin to either your Icon or your Text components
like image 38
linasmnew Avatar answered Sep 27 '22 19:09

linasmnew


I quite like using the short syntax for fragments:

<><strong>Foo</strong> </>
like image 44
rybo111 Avatar answered Sep 27 '22 21:09

rybo111