0

I am doing a front end challenge using HTML and CSS, In the website I have this text:

enter image description here

The above image Is a screenshot from a web view, I need to keep the text centered horizontally when you open the website on a mobile device.

Current output:

enter image description here


As you can see in the images, the smaller the screen will get the more the text will go to the left of the screen

Things that I have done so far:

I have seen here and here that I can do it like this:

  width:100%;
  display: flex;
  justify-content: center;

SO I have tried to do so:

<p class="top-paragprph colorWhite bold">All your files in one secure location,<br> accessible anywhere.</p>
.top-paragprph{
  font-size: 32px;
  width: 100%;
  display: flex;
  justify-content: center;
}

But it did not work for me.

From what I have been reading it seems like flex is the modern and easy way to do so, why on my example the text is not centered on a smaller screen size?

Tamir Abutbul
  • 7,301
  • 7
  • 25
  • 53

5 Answers5

2

Try adding text-align: center; or maybe if you are using bootstrap, add the class text-center your <p></p> tag

Eugene
  • 47
  • 6
2

https://codepen.io/critingz/pen/PomJRov

.holder {
  display: flex;
  justify-content: center;
}

have a holder div that contains the text. The holder div can be display: flex;, justify-content: center;

CritingZ
  • 388
  • 2
  • 16
2

The display: flex; should go on a parent element, like so:

.container{
  width: 100%;
  display: flex;
  justify-content: center;
}
<div class="container">
<p class="top-paragprph colorWhite bold">All your files in one secure location,<br> accessible anywhere.</p>
</div>

Let me know if this works how you want it to.

Rolv Apneseth
  • 2,078
  • 2
  • 7
  • 19
2

Assuming that you want to center the paragraph and also that your navbar is also 100% I would guess that the image is going outside of your body element and making it looks like this is not centered. You can fix this by giving the image max-width: 100%;

Saar Davidson
  • 1,312
  • 1
  • 7
  • 16
1
p {
  width: max-content;
  margin: auto
}

Set width to p element and then set margin auto.

Redberry57
  • 36
  • 4