html,为什么右边框会被挡住?

我用这样的样式描绘,为什么container块的右边框会被挡住呢?请达人指教,感谢。

‘’‘html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" type="text/css" href="almanac.css">
<title>Almanac</title>
<style type="text/css">
.container {border:10px solid #000;width:100%; float: left;}
.year {margin-top: 10px;border-top: 1px solid #000;padding: 10px}
.week {float: right;}
.date {padding-top: 10px;border-top: 1px solid #000;font-size: 150px;text-align:center;}
.today {padding-bottom: 10px;text-align: center;font-size:50px}
.example {padding: 10px;border-top: 1px solid #000;text-align: justify;}
.author {float: right; padding: 10px;font-size: 12px}

</style>
</head>
<body>

<div class="container">

<div class="year"> <span>May 12th, 2016</span> <span class="week">Thursday</span></div>
<div class="date">12</div>
<div class="today">oath</div>
<div class="example"> He swore an oath promising to uphold and protect the country's laws and constitution. </div>
<div class="author">WeChat:xxx</div>

</div>
</body>
</html>

'''

阅读 5.5k
3 个回答

下面有个滚动条嘛,你拉到右边去就看到啦。
你的宽度设置太大把整个页面都撑宽了。
给你的container加个box-sizing:border-box;

html每个标签都会有外边距和内边距的

你把div设置成100%而没有把边距消去掉的话
页面宽度 = 窗口宽度 + 2*margin值
显然会溢出窗口

样式里加下面代码

*{
    padding:0px;
    margin:0px;
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题