Float: center doesn't work?

怎甘沉沦 提交于 2019-12-05 20:28:47

You can only float left or right, so float is not an option here.

Add text-align: center to the parent element of the a-tag. That will center not only text, but also other inline and inline-block elements, like yours.

Another way to center element, is to give them display: block; margin 0 auto. The 'automatic' left and right margins cause the element to be centered. It's a common trick to center elements, but it works on block elements only (or elements with display: block). That also means that you have to specify a width, because if you don't, the block element will consume 100% of the parent width.

I think in your case, an explicit width isn't an option, so text-align will be the best option.

Sorry, but there is no float: center;. Use margin: 0 auto; to center block level elements and text-align: center; for inline.

Instead of using "float" to control the orientation of your text, you'd likely want to use "text-align" and apply it to the parent of your a tag. "text-align: center;" will apply to all inline elements (like a) within a parent. See text-align and float documentation/tutorials.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!