3

I have this code for a custom block on my website but I'm stuck trying to figure out how to vertically center my button and header in the block.

I also have a centering problem with the image on the tablet and mobile versions.

Anytime I have tried to adjust the desktop and get it vertically centered the mobile version messes up.

Here is the code I have set up:

.custom-html-block {
  padding: 20px;
  border: 5px solid #388697;
  border-radius: 0px;
  margin: 30px 0 40px;
  overflow: hidden;
}

.btn-buy-links {
  float: right;
  width: 55%;
  overflow: hidden;
}

a.box-title {
  display: block;
  font-size: 22px;
  text-decoration: none;
  font-weight: bold;
  text-align: center;
  margin-bottom: 20px;
}

a.btn-amazon,
a.btn-chewy {
  display: block;
  padding: 20px;
  background: #5080C9;
  text-align: center;
  margin: 5px 5px 0;
  color: #fff;
  text-transform: uppercase;
  text-decoration: none;
  font-weight: bold;
  border-radius: 40px;
}

@media only screen and (max-width: 800px) {
  .btn-buy-links {
    float: none;
    width: 100%;
  }
  .custom-html-block img {
    text-align: center;
  }
}

Desktop View - Tablet/Mobile View

2 Answers2

1

Use flexbox and center. You can use grid too but flexbox is easier.

0

I would suggest using Flexbox since it will make everything easier for you. With Flexbox you can center elements both vertically and horizontally.

Angel Hadzhiev
  • 664
  • 2
  • 6
  • 20
  • I'm pretty newbie when it comes to coding. How would I go about changing the code to make it flex box? – Alec Littlejohn Apr 24 '22 at 16:28
  • Here is a link to a good source: https://css-tricks.com/snippets/css/a-guide-to-flexbox/ But in short, you just need to have `display: flex;` and then you can use other flex commands which you can see in the link to adjust the styling. Hope it helps. – Angel Hadzhiev Apr 25 '22 at 07:33