[英]Can't figure out how to center this button & header on desktop or this image on mobile
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.我的网站上有一个自定义块的代码,但我一直在尝试弄清楚如何在块中垂直居中我的按钮和 header。
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; } }
Use flexbox and center.使用 flexbox 和中心。 You can use grid too but flexbox is easier.
您也可以使用网格,但 flexbox 更容易。
I would suggest using Flexbox since it will make everything easier for you.我建议使用 Flexbox,因为它会让您的一切变得更轻松。 With Flexbox you can center elements both vertically and horizontally.
使用 Flexbox,您可以将元素垂直和水平居中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.