<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><style type="text/css"> div{ border:1px solid #039; text-align:center; } #header{ width:100%; height:80px; } .logo{ width:30%; background-color:#0fc; float:left; } .today{ width:30%; background-color:#ccc; float:left; } .search{ width:39.5%;/*定义为40%会导致搜索栏不能和前两个在同一行。*/ background-color:#cf9; float:left; } </style></head><body> <div id="header"> <div class="logo">网站Logo</div> <div class="today">当前日期</div> <div class="search">搜索栏</div> </div></body></html>
你把所有div样式
div{
border:1px solid #039;
text-align:center;
}
加了边框,肯定不能按照100%来设置,你把边框去掉就可以了