首页 \ 问答 \ 使用vertical-align垂直居中div中的按钮(Using vertical-align to vertically center a button within a div)

使用vertical-align垂直居中div中的按钮(Using vertical-align to vertically center a button within a div)

目标是将div中的按钮水平和垂直居中。 水平已经处理,但垂直对齐有问题。

vertical-alignw3schools页面可以看出,使用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我错了吗?

我也尝试将CS​​S设置为:

.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 using middle 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
更新时间:2022-07-27 17:07

最新回答

魔改有结局,正常没结局。魔改只有电脑版。没有手机版。魔改的结局有4个吧,x奴(玩具)。和服装店老板娘结婚,被卖到j院,和希尔薇结婚,不建议魔改。
百度就有的

相关问答

更多
  • 在应用宝就可以下载这个软件,用了大王卡可以免流量下载,在应用宝上搜索一下,里面有很多类似的软件,而且分类也很全面,什么类型的都有,尤其是休闲益智类的有很多,下载起来也很方便,我平时使用的软件都是在这上面下载,不用账号密码啥的很快捷,可以放心使用,希望可以帮到你!
  • 三星手机下载软件方法为您提供以下几种方法,请您参考: 1.通过手机中应用商店搜索需要的软件并下载安装。 2.通过手机浏览器搜索需要的软件下载安装(若是自带的浏览器,下载的安装包保存在我的文件-Download文件夹中)。 3.通过第三方助手类软件下载安装需要的程序。 4.通过电脑下载APK格式的安装包,然后传输到手机中安装。
  • 在国内被屏蔽了,你要在手机上面设置VPN,把IP换成香港或是国外的才可以打开 下载分享给你的51vpn ,这是软件的唯一官网:www.51vpnn.com.cn/ 装上软件后,来到主页面,点击网络加速按钮,变成加速中。 再从网络加速点击进去,选择你想x墙的APP。 这样就可以啦
  • 有啊 有‘’添加到照片地图‘’ 选择之后就出现了 ‘’为此位置命名‘’ 就可以加位置了
  • ins下载安卓版[2022-02-28]

    其实我觉得注册INS是众多社交软件中最简单的了, 手机下载ins客户端,安卓:豌豆夹 打开 安装后一打开就有注册选项。 然后就输入一个不跟人撞名的ID 需要一个电子邮箱 输密码就行 【还有个点就是 如果你用移动的手机卡请在有wifi的情况下登陆 电信联通是无大碍的 不然玩网页版也行】
  • 这游戏还没做完。。没结局,无限摸头,话说有1.50了咩? 避免死亡必须给她换连衣裙,开始别啪啪啪,要到她主动要求 好感度也要加上,别选不利选项
  • 移植作者几个月前已经宣布放弃1.20版及后续版本在安卓平台上的更新 安卓版将不会再继续开发 1.安卓版导致游戏扩散过快,影响十分不好 2.安卓的安全程度过低,导致某些无良网站和软件市场对安装包内私自添加商业广告或者病毒木马,(例如G*助手…)偷跑用户流量,窃取用户隐私,严重危害用户手机安全 3.各种平台公然提供18x游戏的下载,可能引发法律问题,并导致原作者受到牵连 转自百度贴吧
  • 你说的这个游戏在应用宝里可以下载,我的手机在这个软件里下载,这个游戏我玩的很开心。 这个游戏是很好玩的,汉化版的也可以找到的,你就在搜索栏输入这个游戏的名字就找到了,然后下载到手机里。我的手机玩这些游戏都是没有出现问题的,希望你可以玩的开心。
  • 三星手机下载软件方法有很多,提供以下几种方式,请参考: 1.使用手机功能表中自带的浏览器上网,直接搜索需要的软件进行下载安装 。(下载的安装包保存在我的文件-Download文件夹中。) 2.部分手机自带三星应用商店,可以通过此软件搜索喜欢的软件下载安装。(通过三星应用商店下载的程序,安装后自动删除安装包) 3.使用电脑下载APK格式的安装包,连接数据线传输至手机,操作手机在应用程序-我的文件中找到安装包。 4.先下载一个市场类软件,常见的有安卓市场,机锋市场等,之后使用此款软件下载其他程序 。 5.使用手 ...
  • 安卓的可以直接在百度上面搜索或者在应用商店(应用宝,各种手机助手)搜索 希尔薇 就可以下载了

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)