- button
- half-transparent-border
- multiple-borders
- callout
- extended-bg-position
- inner-rounding
- stripes
- gridding
- polka
- checkerboard
- marching-ants
- footnote
- ellipse
- half-ellipse
- parallelograms-pseudo
- diamond-images
- bevel-corners-gradients
- scoop-corners
- trapezoid-tabs
- pie-static
- shadow
- color-tint-filter
- frosted-glass
- folded-corner
- hypenation
- line-breaks
- zebra-lines
- tab-size
- ampersands
- underlines
- text-effects
- circular-text
- cursor
- hit-area
- checkboxes
- weaken-background-by-shadow
- weaken-background-by-blur
- scrolling-hints
- image-slider
- intrinsic-sizing
- table-column-widths
- styling-sibling-count
- fluid-fixed
- vertical-centering
- sticky-footer
- bounce
- elastic
- frame-by-frame
- text-blink
- text-typing
- state-animations
- circular
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
vertical-centering
base on absolute position
main {
position: absolute;
top: 50%;
left: 50%;
margin-top: -3em; /* 6/2 = 3 */
margin-left: -9em; /* 18/2 = 9 */
width: 18em;
height: 6em;
}
Or use calc()
function:
main {
position: absolute;
top: calc(50% - 3em);
left: calc(50% - 9em);
width: 18em;
height: 6em;
}
Disadvantage:
require element's width and height are both fixed value.
Or use
transform
feature:main { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); }
Disadvantage:
- sometimes we can't use absolute position
- element will be clipped if it's height is larger than viewport's.
- cause element seem to look like fuzzy if it's putted in 0.5px when in some browsers. (use
transform-style: preserve-3d
to fix)
base on vh
<style>
main {
width: 18em;
padding: 1em 1.5em;
margin: 50vh auto 0;
transform: translateY(-50%);
box-sizing: border-box;
background: #655;
color: white;
text-align: center;
}
h1 {
margin: 0 0 .2em;
font-size: 150%;
}
p {
margin: 0;
}
body {
background: #fb3;
font: 100%/1.5 sans-serif;
}
</style>
<main>
<h1>Am I centered yet?</h1>
<p>Center me, please!</p>
</main>
Link: one line to implement full screen area
.section { height: 100vh; }
base on flexbox
<style>
body {
display: flex;
min-height: 100vh;
background: #fb3;
font: 100%/1.5 sans-serif;
}
main {
padding: 1em 2em;
margin: auto;
box-sizing: border-box;
background: #655;
color: white;
text-align: center;
}
h1 {
margin-bottom: .2em;
font-size: 150%;
}
</style>
<body>
<main>
<h1>Am I centered yet?</h1>
<p>Center me, please!</p>
</main>
</body>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论