我有一个带有CSS和jQuery选项卡的html页面。现在,当我尝试将固定宽度应用于主体或主容器时,所有div
都变得疯狂并且未对齐......我们如何给身体提供最小固定宽度1200px?
预期输出
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Faisy's</title>
<script src="http://mihaifrentiu.com/wp-content/themes/mf/js/jquery_1.7.1.min.js"
type="text/javascript">
</script>
<style type="text/css">
body, html, div, ul, li, a
{
margin: 0;
padding: 0;
background-color: #000000;
color: #ffffff;
font-family: Comic Sans MS;
/*min-width:800px;*/
}
ul
{
list-style: none;
position: relative;
z-index: 2;
top: 1px;
display: table;
border-left: 1px solid #ff0000;
}
ul li
{
float: left;
}
ul li a
{
background: #5A005A;
color: #ffffff;
display: block;
padding: 6px 15px;
text-decoration: none;
border-right: 1px solid white;
border-top: 1px solid white;
border-right: 1px solid white;
}
ul li a.selected
{
border-bottom: 1px solid #fff;
color: #344385;
background: #fff;
}
#navigation
{
width: 100%;
margin: 0 auto;
}
#content
{
width: 100%;
margin: 0 auto;
height: 500px;
background: #fff;
border: 1px solid #ff0000;
z-index: 1;
padding: 10px 0;
}
.clear
{
clear: both;
}
.blockDivFloatLeft
{
float: left;
width: 100%;
display: block;
}
#banner
{
height: 100px;
font-family: Comic Sans MS;
font-size: 40px;
text-align: center;
}
#containerDiv
{
/*width:1200px;*/
}
#leftSub
{
float: left;
width: 15%;
min-width:250px;
border: 3px solid white;
height: 250px;
margin-right:1px;
text-align:center;
vertical-align:middle;
}
#rightSub
{
float: left;
width: 80%;
}
</style>
</head>
<body>
<div id="containerDiv">
<div id="banner" class="blockDivFloatLeft">
Sample
</div>
<div class="clear" />
<div id="mainContent" class="blockDivFloatLeft">
<div id="leftSub">
<img border="0" src="/images/pulpit.jpg" alt="Photo" width="304" height="228"/>
</div>
<div id="rightSub">
<div id="navigation">
<ul>
<li><a href="javascript:void(0);" id="tab1" class="selected">About Me</a></li>
<li><a href="javascript:void(0);" id="tab2">My Interests</a></li>
<li><a href="javascript:void(0);" id="tab3">Talents</a></li>
<li><a href="javascript:void(0);" id="tab4">Academic</a></li>
<li><a href="javascript:void(0);" id="tab5">Achievements</a></li>
</ul>
<div class="clear">
</div>
</div>
<div id="content">out
<p id="content_changer">
You have selected Tab 1</p>
<p>
See the page source for full code</p>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
//Tab Navigation
$('#navigation ul a').click(function ()
{
//Tab Selection setting
$('#navigation ul a').removeClass('selected');
$(this).addClass('selected');
//Content Setting
$('#content_changer').html('You have selected ' + $(this).html());
});
});
</script>
</body>
</html>
答案 0 :(得分:0)
问题是您定义的宽度(width: 1200px;
)对于您定义的其他宽度来说太小了。因为您将#leftSub
定义为min-width: 250px
而将#rightSub
定义为width: 80%;
,因此您没有足够的空间并排放置这两个元素,因此float: left
是不要把两者放在一起。根据您定义的宽度,您需要width: 1667px
至少#containerDiv
。
您可以将正文定义为min-width: 1200px;
,但由于min-width
上的#rightSub
,您仍会遇到较小屏幕的问题。
注意:在CSS文件的顶部,它一起应用于body, html, div, ul, li, a
。这可以分成多个以避免混淆