使用vertical-align垂直居中div中的按钮(Using vertical-align to vertically center a button within a div)
目标是将div中的按钮水平和垂直居中。 水平已经处理,但垂直对齐有问题。
从
vertical-align
的w3schools页面可以看出,使用middle
有以下结果:“该元素位于父元素的中间”
在我的问题中( 参见这里的jsFiddle )我已经将父元素中的一个按钮的CSS(据我所知)设置为垂直对齐。
HTML:
<div id='titleSection'> <div class='title-inner right quarter-width'> <form action='destroy.php' method='POST'> <button>Log Out</button> </form> </div> <div class='title-inner left quarter-width'> <!--nothing--> </div> <div class='title-inner center half-width'> <h1 class='centered-text'>Title</h1> </div> </div>
CSS:
* { font-family:'Arial', Arial, sans-serif; padding: 0; margin: 0; } h1 { padding: 2.1vh 0; font-size: 6vmin; } div#titleSection { width: 100%; height: 12vh; border: 2.5px solid #ff0fff; } div.title-inner { height: 100%; text-align: center; display:inline-block; } div.quarter-width { width: 25%; } div.third-width { width: 33.3%; } div.half-width { width: 50%; } div.left { float: left; background-color: rgba(255, 0, 0, 0.5); } div.center { float: center; background-color: rgba(0, 255, 0, 0.5); } div.right { float:right; background-color: rgba(0, 0, 255, 0.5); } .title-inner button { vertical-align: middle; }
我认为父元素是
title-inner
div我错了吗?我也尝试将CSS设置为:
.title-inner form { vertical-align: middle; }
无济于事。
回顾一下:jsFiddle中显示的所有额外的CSS和html只是为了给出我想要做的事情的最准确的想法 - 如果这是不必要的道歉,但我宁愿留下来以避免忘记我在哪里。 最终目标只是(垂直)将右侧(蓝色)div中的“ 注销”按钮居中。
Goal is to center a button within a div, both horizontally and vertically. Horizontal has been dealt with, but having trouble with vertical align.
From the w3schools page on
vertical-align
it states that usingmiddle
has the following result:"The element is placed in the middle of the parent element"
In my problem (see jsFiddle here) I have set the CSS of a button within the parent element (to the best of my knowledge) to be vertically aligned.
HTML:
<div id='titleSection'> <div class='title-inner right quarter-width'> <form action='destroy.php' method='POST'> <button>Log Out</button> </form> </div> <div class='title-inner left quarter-width'> <!--nothing--> </div> <div class='title-inner center half-width'> <h1 class='centered-text'>Title</h1> </div> </div>
CSS:
* { font-family:'Arial', Arial, sans-serif; padding: 0; margin: 0; } h1 { padding: 2.1vh 0; font-size: 6vmin; } div#titleSection { width: 100%; height: 12vh; border: 2.5px solid #ff0fff; } div.title-inner { height: 100%; text-align: center; display:inline-block; } div.quarter-width { width: 25%; } div.third-width { width: 33.3%; } div.half-width { width: 50%; } div.left { float: left; background-color: rgba(255, 0, 0, 0.5); } div.center { float: center; background-color: rgba(0, 255, 0, 0.5); } div.right { float:right; background-color: rgba(0, 0, 255, 0.5); } .title-inner button { vertical-align: middle; }
Am I wrong to think that the parent element is the
title-inner
div?I have also tried setting the CSS to:
.title-inner form { vertical-align: middle; }
to no avail.
To recap: All extra CSS and html shown in jsFiddle just to give most accurate idea of what I am trying to do - apologies if this is unnecessary but I'd rather leave it in to avoid losing track of where I am. End goal is simply to (vertically) center the Log Out button within the right-hand (blue) div.
原文:https://stackoverflow.com/questions/33631177
最新回答
魔改有结局,正常没结局。魔改只有电脑版。没有手机版。魔改的结局有4个吧,x奴(玩具)。和服装店老板娘结婚,被卖到j院,和希尔薇结婚,不建议魔改。
百度就有的
相关问答
更多-
希尔薇汉化安卓版下载[2022-12-21]
在应用宝就可以下载这个软件,用了大王卡可以免流量下载,在应用宝上搜索一下,里面有很多类似的软件,而且分类也很全面,什么类型的都有,尤其是休闲益智类的有很多,下载起来也很方便,我平时使用的软件都是在这上面下载,不用账号密码啥的很快捷,可以放心使用,希望可以帮到你! -
谁有希尔薇汉化手机版2.0[2022-04-24]
三星手机下载软件方法为您提供以下几种方法,请您参考: 1.通过手机中应用商店搜索需要的软件并下载安装。 2.通过手机浏览器搜索需要的软件下载安装(若是自带的浏览器,下载的安装包保存在我的文件-Download文件夹中)。 3.通过第三方助手类软件下载安装需要的程序。 4.通过电脑下载APK格式的安装包,然后传输到手机中安装。 -
instagram安卓版怎么注册[2022-03-25]
在国内被屏蔽了,你要在手机上面设置VPN,把IP换成香港或是国外的才可以打开 下载分享给你的51vpn ,这是软件的唯一官网:www.51vpnn.com.cn/ 装上软件后,来到主页面,点击网络加速按钮,变成加速中。 再从网络加速点击进去,选择你想x墙的APP。 这样就可以啦 -
instagram安卓版怎么才能用[2023-03-06]
有啊 有‘’添加到照片地图‘’ 选择之后就出现了 ‘’为此位置命名‘’ 就可以加位置了 -
ins下载安卓版[2022-02-28]
其实我觉得注册INS是众多社交软件中最简单的了, 手机下载ins客户端,安卓:豌豆夹 打开 安装后一打开就有注册选项。 然后就输入一个不跟人撞名的ID 需要一个电子邮箱 输密码就行 【还有个点就是 如果你用移动的手机卡请在有wifi的情况下登陆 电信联通是无大碍的 不然玩网页版也行】 -
求希尔薇1.92安卓汉化版谢谢[2023-06-17]
这游戏还没做完。。没结局,无限摸头,话说有1.50了咩? 避免死亡必须给她换连衣裙,开始别啪啪啪,要到她主动要求 好感度也要加上,别选不利选项 -
求希尔薇1.31安卓版要简体中文版[2022-05-03]
移植作者几个月前已经宣布放弃1.20版及后续版本在安卓平台上的更新 安卓版将不会再继续开发 1.安卓版导致游戏扩散过快,影响十分不好 2.安卓的安全程度过低,导致某些无良网站和软件市场对安装包内私自添加商业广告或者病毒木马,(例如G*助手…)偷跑用户流量,窃取用户隐私,严重危害用户手机安全 3.各种平台公然提供18x游戏的下载,可能引发法律问题,并导致原作者受到牵连 转自百度贴吧 -
求希尔薇1.5安卓版,汉化[2022-03-22]
你说的这个游戏在应用宝里可以下载,我的手机在这个软件里下载,这个游戏我玩的很开心。 这个游戏是很好玩的,汉化版的也可以找到的,你就在搜索栏输入这个游戏的名字就找到了,然后下载到手机里。我的手机玩这些游戏都是没有出现问题的,希望你可以玩的开心。 -
希尔薇安卓手机版,不要压缩包[2024-03-20]
三星手机下载软件方法有很多,提供以下几种方式,请参考: 1.使用手机功能表中自带的浏览器上网,直接搜索需要的软件进行下载安装 。(下载的安装包保存在我的文件-Download文件夹中。) 2.部分手机自带三星应用商店,可以通过此软件搜索喜欢的软件下载安装。(通过三星应用商店下载的程序,安装后自动删除安装包) 3.使用电脑下载APK格式的安装包,连接数据线传输至手机,操作手机在应用程序-我的文件中找到安装包。 4.先下载一个市场类软件,常见的有安卓市场,机锋市场等,之后使用此款软件下载其他程序 。 5.使用手 ... -
希尔薇1.50安卓版下载[2022-07-17]
安卓的可以直接在百度上面搜索或者在应用商店(应用宝,各种手机助手)搜索 希尔薇 就可以下载了