-1

.brandingWrapper {
  cursor: pointer;
  display: flex;
  height: 42px;
}

.apptitle {
  margin-left: 5px;
  font-size: 28px;
  font-family: 'apptitle';
  vertical-align: center;
  color: black;
}

a {
  color: #FFFFFF;
  text-decoration: none;
}
<div>
  <a class="brandingWrapper" href="/">
    <img class="applogo" src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/5a/Wikipedia%27s_W.svg/128px-Wikipedia%27s_W.svg.png?20220824035851" width="42" height="42" />
    <p class="apptitle">Appname</p>
  </a>
</div>

But this is what it looks like:

img

How can I center the text?

Edit:

Sorry for the confusion. I want it vertically centered, so it is on the same height as the logo.

mathematics-and-caffeine
  • 1,664
  • 2
  • 15
  • 19

5 Answers5

1

Paragraphs have, by default, a significant margin-top. You need to reduce it.

.brandingWrapper {
  cursor: pointer;
  display: flex;
  height: 42px;
}

.apptitle {
  margin: 5px 0 0 5px;
  font-size: 28px;
  font-family: 'apptitle';
  vertical-align: center;
  color: black;
}

a {
  color: #FFFFFF;
  text-decoration: none;
}
<div>
  <a class="brandingWrapper" href="/">
    <img class="applogo" src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/5a/Wikipedia%27s_W.svg/128px-Wikipedia%27s_W.svg.png?20220824035851" width="42" height="42" />
    <p class="apptitle">Appname</p>
  </a>
</div>
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

In the parent div you have to add the following css code:

div{
   display: flex;
   justify-content: center;
   align-items: center;
}

if you don't want to center horizontal just delete:

justify-content: center;
Erikwski
  • 39
  • 6
0

well there is so many ways to center elements in your code you can center it by changing margin property for apptitle to this

.apptitle {
          font-size: 28px; 
          font-family: 'apptitle'; 
          vertical-align: center;
          color: black;
          margin-right:auto; 
          margin-left:auto; 
 }
-1

We can enter the button by using text-align:center.

By setting the value of text-align property of parent div tag to the center. margin:auto- By setting the value of margin property to auto.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
-1

You need two additional css properties in your apptitle class:

...

.apptitle {
  ...
  display: flex;
  align-self: center;
}

And you can remove vertical-align: center; because this will do nothing. Its invalid.

DerHerrGammler
  • 324
  • 2
  • 9