[英]How to Mimic Android / iOS square buttons with plain HTML and CSS2?
This seems almost impossible. 这似乎几乎是不可能的。
I am trying to create HTML/CSS-only square link buttons with text centered inside and without using CSS3. 我正在尝试创建仅HTML / CSS的方形链接按钮,文本内部居中,并且不使用CSS3。
I have tried variations of every answer I could find about vertically-centering text in an inline-block
, but nothing that I try fulfills the following constraints: 我已经尝试过找到所有关于
inline-block
垂直居中文本的答案的变inline-block
,但是我尝试满足的所有条件都没有:
display:flex
). display:flex
)。 Think something like the side-by-side square buttons on the iOS and Android home screens but using simple and pure HTML/CSS. 想想像iOS和Android主屏幕上的并排方形按钮之类的东西,但要使用简单纯净的HTML / CSS。 The shadowing, gradients, reflections aren't necessary, just the button structures.
不需要阴影,渐变,反射,只需按钮结构即可。
I've tried nested divs using :before
as a trick to vertically-align the text within an inline-block
, I've tried using display:table
with rows and cells, and I've even tried display:flex
but that uses CSS3. 我已经尝试使用嵌套的div
:before
作为特技垂直对齐的中的文本inline-block
,我已经尝试使用display:table
的行和细胞,并且甚至我已经试过display:flex
,但其使用CSS3 。 No solution I tried fits all the criteria above. 我尝试过的解决方案都不符合上述所有条件。
So I'm wondering, is this even possible without CSS3? 所以我想知道,如果没有CSS3,这是否有可能? If so, what's the trick as I would have thought something like this would have been very straightforward to accomplish?
如果是这样,那么我会以为这样的事情将非常容易实现,那是什么窍门?
Yes, I believe this is possible, but it uses a lot of nested spans! 是的,我相信这是可能的,但是它使用了大量的嵌套跨度!
The craziest CSS used here is display: table
and display: inline-block
, so I think you should be pretty safe. 这里使用的最疯狂的CSS是
display: table
和display: inline-block
,所以我认为您应该很安全。
body { font-family: sans-serif; } .special-button { display: inline-block; height: 100px; width: 100px; overflow: hidden; position: relative; background: #eee; color: #333; text-decoration: none; } .special-button:hover { background: #333; color: #fff; } .special-button-table { display: table; width: 100%; height: 100%; } .special-button-cell { display: table-cell; vertical-align: middle; text-align: center; padding: 10px; }
<a href="#" class="special-button"> <span class="special-button-table"> <span class="special-button-cell">Text Here</span> </span> </a> <a href="#" class="special-button"> <span class="special-button-table"> <span class="special-button-cell">Longer Text Item Here</span> </span> </a> <a href="#" class="special-button"> <span class="special-button-table"> <span class="special-button-cell">Text Here</span> </span> </a> <a href="#" class="special-button"> <span class="special-button-table"> <span class="special-button-cell">Really Really Long Text Item That Overflows Here</span> </span> </a>
Ive possibly missed some details due to a very quick skim read - let me know how far off this is. Ive可能由于快速阅读了一下而错过了一些细节-让我知道这有多远。
<style>
.ios li {
display: inline-block;
background: #eee;
padding: 5% 10px 20px 10px;
width: 100px;
max-width: 100px;
height: 50px;
max-height: 100px;
vertical-align: top;
text-align: center;
}
</style>
<ul class="ios">
<a href="test.com"><li>short text</li></a>
<a href="test2.com"><li>much longer lot of text</li></a>
</ul>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.