0

I have a div with a label next to it, like this: enter image description here

This is how my html in Vue.js looks like:

    <div style="margin-bottom: 15px;">
      <input
        id="newsletterRegister"
        type="checkbox"
        name="newsletterRegister"
        style="width: 30px"
      />
      <label for="newsletterRegister">
        Do you want to receive email promotions?
      </label>
    </div>

I have no idea how to center the label next to the checkbox. I have tried a lot of things, but it doesn't seem to be working. Thanks for answers!

StevenSiebert
  • 1,306
  • 4
  • 15
  • 26
dokichan
  • 857
  • 2
  • 11
  • 44

5 Answers5

3

Try using flexbox

.center {
  display: flex;
  align-items: center;
}
<div style="margin-bottom: 15px" class="center">
  <input id="newsletterRegister" type="checkbox" name="newsletterRegister" style="width: 30px" />
  <label for="newsletterRegister">
        Do you want to receive email promotions?
      </label>
</div>
Charles Lavalard
  • 2,061
  • 6
  • 26
1

just put the display: flex; align-items: center; in the div style, it'll do the job

  <div style="margin-bottom: 15px; display: flex; align-items: center;">
      <input
        id="newsletterRegister"
        type="checkbox"
        name="newsletterRegister"
        style="width: 30px"
      />
      <label for="newsletterRegister">
        Do you want to receive email promotions?
      </label>
    </div>
Vijay Kumawat
  • 873
  • 5
  • 9
0

You can use 'vertical-align' like this:

<div style="margin-bottom: 15px;">
      <input
        id="newsletterRegister"
        type="checkbox"
        name="newsletterRegister"
        style="width: 30px; vertical-align:bottom;"
      />
      <label for="newsletterRegister">
        Do you want to receive email promotions?
      </label>
    </div>

Or alternatively You could set labels (.newsletterRegister) line-height style to the same as checkbox height is.

Flash Thunder
  • 11,672
  • 8
  • 47
  • 91
0

You can use display: flex; and justify-content:center; to align the items horizontally and align-items: center to align items vertically. Try running the snippet if this works for you.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <link href="style.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
   <div style="margin-bottom: 15px; display: flex; justify-content: center; align-items: center;">
    <input
     id="newsletterRegister"
     type="checkbox"
     name="newsletterRegister"
     style="width: 30px"
    />
    <label for="newsletterRegister">
     Do you want to receive email promotions?
    </label>
   </div>
  </body>
</html>
Yong
  • 1,622
  • 1
  • 4
  • 29
-1

You can use the center tag

It is very old-fashioned but it works.

Goggi
  • 32
  • 8