4

I'm using wkhtmltopdf to convert a HTML to PDF. I know wkhtmltopdf uses an old version of webkit, which makes things a little more complicated.

I have a contact image and I want to display the contact name right next to it:

Image: How it's supposed to look

This is my HTML:

<div class="contact">
    <img src="C:/mypath/picture.jpg">
    <span>Contact Name</span>
</div>

CSS:

div.contact {
    display: -webkit-flex;
    flex-direction: row;
    justify-content: left;
}

div.contact>img {
    width: 70px;
    border-radius: 50%;
    margin-right: 20px;
}

div.contact>span {
    display: inline-block;
    width: 110px;
}

Doesn't work so far. Applying align-items: center; to div.contact doesn't work either.

Ginny
  • 53
  • 1
  • 6
  • hi. look it, pls - https://stackoverflow.com/questions/33784813/flexbox-wkhtmltopdf-rendering-issue – s.kuznetsov Jan 24 '21 at 23:25
  • Thanks for the tip, @s.kuznetsov! I've already checked it though and it didn't help because it does not explain how to center elements vertically. The original Flexbox spec didn't get me further either ... – Ginny Jan 26 '21 at 10:46

2 Answers2

1

I think I found your solution. Actually align-self is working but .contact height is not big enough to cover viewport. So I wrote this; I hope it's enough for you.

For HTML

<div class="contact">
    <div class="contact-box">
        <img src="C:/mypath/picture.jpg">
        <span>Contact Name</span>
    </div>
</div>

And for CSS

body {
  padding: 0;
  margin: 0;
  width: 100%;
  height: 100%;
  background-color: #000000;
}

.contact {
  display: flex;
  display: -webkit-flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  width: 100%;
  min-height: 100vh;
  margin: auto;
}

.contact-box {
  background-color: white;
  padding: 10px;
}

.contact img {
  align-self: center;
  justify-self: center;
  width: 70px;
  border-radius: 50%;
  margin-right: 20px;
}

.contact span {
  align-self: center;
  justify-self: center;
  width: 110px;
}
BinaryButterfly
  • 18,137
  • 13
  • 50
  • 91
ates_irem
  • 286
  • 1
  • 8
0

align-items doesn't work with wkhtmltopdf, but -webkit-box-align: center do work, use it with display: -webkit-box

div.contact {
display: -webkit-box;
-webkit-box-align: center;
}