试图调整HTML按钮我的网页的中心 [英] trying to align html button at the center of the my page

查看:169
本文介绍了试图调整HTML按钮我的网页的中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

进出口试图对准的HTML按钮恰好在中心页面不论使用的浏览器。它要么浮动到左,同时仍然在垂直中心或能在别处的页面上像在页面的顶部等。我希望它是水平和垂直方向的中心。以下是我已经写了现在:

Im trying to align a HTML button exactly at the center of the page irrespective of the browser used. It is either floating to left while still being at the vertical center or being somewhere on the page like at the top of the page etc.. I want it to be both vertically and horizontally be centered. Here is what i have written right now:

<button type="button"
style="background-color:yellow;margin-left:auto;margin-right:auto;display:block;margin-top:22%;margin-bottom:0%">
mybuttonname</button> 

请帮忙, 谢谢

推荐答案

这是你的解决方案: http://jsfiddle.net/7Laf8/

基本上,将您的按钮变成一个div与居中的文本:

Basically, place your button into a div with centred text:

<div class="wrapper">
    <button class="button">Button</button>
</div>

通过以​​下方式:

.wrapper {
    text-align: center;
}

.button {
    position: absolute;
    top: 50%;
}

有很多方法对皮肤一只猫,而这只是其中的一个。

There are many ways to skin a cat, and this is just one.

这篇关于试图调整HTML按钮我的网页的中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆