您的位置:首页 > Web前端 > CSS

CSS 对齐方式

2017-03-02 15:05 197 查看
居中设置

Center Align - Using margin

Setting the width of a block-level element will prevent it from stretching out to the edges of its container. Use
margin: auto;
, to horizontally center an element within its container.

The element will then take up the specified width, and the remaining space will be split equally between the two margins:

<!DOCTYPE html>
<html>
<head>
<style>
.right {
position: absolute;
right: 0px;
width: 300px;
border: 3px solid #73AD21;
padding: 10px;
}
</style>

<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "//hm.baidu.com/hm.js?73c27e26f610eb3c9f3feb0c75b03925";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
</head>
<body>

<div class="right">
<p>In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since.</p>
</div>

</body>
</html>


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: