使用 CSS 定位按钮
我有以下标准标记:
<body>
<header><div class="wrapper">Header</div></header>
<div id="create">create something</div>
<div class="wrapper">Content</div>
<footer><div class="wrapper">footer</div></footer>
</body>
和样式:
.wrapper {
width: 920px;
margin: 0 auto;
padding: 0 20px;
text-align: left;
}
我遇到的困难是定位“创建某些内容”按钮,我希望它的位置如下所示...
需要注意的要点是,按钮向右延伸至无穷大,并且无论怎样,它始终占据中心区域“4 个正方形”的宽度浏览器宽度是多少。
任何建议将不胜感激,谢谢。
I have the following standard markup:
<body>
<header><div class="wrapper">Header</div></header>
<div id="create">create something</div>
<div class="wrapper">Content</div>
<footer><div class="wrapper">footer</div></footer>
</body>
and style:
.wrapper {
width: 920px;
margin: 0 auto;
padding: 0 20px;
text-align: left;
}
The thing I am having difficulty with is positioning the "create something" button, I would like it positioned as shown below...
The important points to note are that the button extends to the right into infinity, and it always takes up a width of "4 squares" of the centralised area, no matter what the browser width.
Any advice would be appreciated, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一个元素用于按钮,另一个元素用于无限远及无限远的线条。
无限元素部分隐藏在
#wrap
或#header
元素的背景下。http://jsfiddle.net/lollero/62wcV/1
CSS:
HTML:
One element for the button and another element for the line that goes into the infinity and beyond..
The infinity element is partially hidden under
#wrap
or#header
element's background.http://jsfiddle.net/lollero/62wcV/1
CSS:
HTML:
我不会说这是最好的方法,但它对我有用。
第一个 div 只是为您提供了对页面中心的引用。第二个是“按钮”,左侧可按您想要的偏移量进行偏移。
I'm not going to say this is the best way, but it works for me.
The first div just gives you a reference to the centre of the page. The second is the 'button' where the left is offset by however much you want.
使用 CSS 创建按钮时,请务必计算宽度、高度、填充和边距。它有助于提供准确的盒子尺寸以适合任何特定的容器。看看这篇文章。 http://www.phcityonweb.com/tutorial/css-programming-lessons /margin-padding 另请查看他们的定位教程。
When creating buttons with CSS, always calculate the width, height, paddings and margin. it helps to give accurate box size to fit any particular container. check out this post. http://www.phcityonweb.com/tutorial/css-programming-lessons/margin-padding Also check out their positioning tutorials.