Add new line/blank div/padding in VueJS h (hyperscript) functions

107 Views Asked by At

I'm working on a project using VueJS's h() functions and all the content I need to include needs to be inside one of these. I'm trying to add content to a div by appending additional h('divs') to it, but need a way to space them (and the text inside them) out.

I've tried using '\n' and '< / br>', both with and without quotes, to add new lines, but this doesn't work - with quotes it gets included as text, and without it says there's an unexpected '<'. I've also tried to add padding inside style tags, following the example in the documentation:

h('div', {style: { margin: 100, padding:100 } })

but this doesn't do anything. How can I space out the h() function divs and the text inside?

1

There are 1 best solutions below

0
On

You can add CSS styles to the style property of the h() function to control the spacing of the divs and the text inside them. To add padding, you can use the padding property with a CSS length value in pixels, ems, or any other valid CSS unit.

Here's an example:

h('div', {
  style: {
    padding: '20px'
  }
}, [
  h('div', 'This is the first div'),
  h('div', 'This is the second div'),
  h('div', 'This is the third div')
])

This will add 20 pixels of padding to each of the divs inside the main div, spacing them out vertically. You can adjust the padding value as needed to control the amount of space between the divs.

Hope this is helpful.