为什么我的导航按钮或按钮文本不会移动到中心
Why won't my nav button or button text move to the center?
所以我正在尝试为我的一家公司制作一个网站,这个想法是我的主页将有一个巨大的图像,中心(水平和垂直)有一个按钮,上面写着"更多!"但按钮不会居中,按钮内部的文本也不会居中,下面我将放置我的HTML代码以及我的CSS代码。
这是我的网页
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Biostone Interactive | Main</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="header-image">
<div id="header-button">
<a href="#" id="header-button-text">More!</a>
</div>
</div>
<div id="nav">
</div>
<div id="container">
</div>
</body>
</html>
这是我的 CSS:
* {
padding: 0;
margin: 0;
font-family: Lucida Sans Unicode, Tahoma, Arial;
}
#header-image {
width: 100%;
height: 600px;
background-color: black;
}
#header-button {
width: 100px;
height: 50px;
background-color: red;
border-radius: 4px;
margin: 0 auto;
}
#header-button-text {
text-align: right;
text-decoration: none;
color: white;
}
(请注意,此代码不完整,因为我删除了其中一些以尝试修复它)请帮助我,告诉我我做错了什么!谢谢:D
若要使文本在容器内居中,请使用text-align:center;
若要使容器居中,请使用margin-left:auto;margin-right:auto;
#header-button {
width: 100px;
height: 50px;
background-color: red;
border-radius: 4px;
margin: 0 auto;
text-align: center;
margin-left: auto;margin-right:auto;
}
#header-button-text {
text-decoration: none;
color: white;
}
将
标题按钮 CSS 更改为:
#header-button {
position:absolute;
top:50%;
left:50%;
margin-top: -25px;
margin-left: -50px;
width: 100px;
height: 50px;
background-color: red;
border-radius: 4px;
}
边距值需要是维度属性的一半,因此如果更改宽度和高度,则必须更新边距。
相关文章:
- jquery移动对齐按钮取决于内容大小
- 简单的垂直上一个和下一个按钮代码点击上下移动jQuery
- 在带有Partial视图的MVC 5中,将提交按钮移动到表单外部
- 如何使用 JavaScript 函数在 JSP 中使用按钮移动到数据库的最后一条记录
- Onclick 无法正常工作,并且将按钮移动到下一行不起作用
- 如何在使用angularjs选项卡时单击按钮移动到下一个选项卡
- 根据选中的单选按钮移动到不同的页面
- 使用后退按钮移动单页应用程序 AngularJS
- 将BxSlider按钮移动到位
- 可滑动的内联按钮移动
- 当我按住鼠标按钮移动鼠标时,Fabric.js–元素是未定义的
- 邮件黑猩猩的形式在引导-按钮移动
- 点击离子导航条上的按钮移动到新页面的所有3种方式都不起作用
- 如何将选中的单选按钮移动到左侧
- 在openart 2.0中,搜索按钮移动到顶部栏
- 如何将我的+按钮移动到网页右侧
- 检测用户是否点击了“后退”按钮——移动浏览器
- 如何在单击时将按钮移动(设置动画)到特定位置,并在单击其他位置时返回到原始位置
- Facebook“分享”按钮;移动web的html/javascript
- 根据我悬停在上面的按钮移动相同的图像