我为初学者html / css项目完成了我的代码编写,但我很快就学会了,我的主容器容纳了另外两个较小的容器需要宽度为960px。较小的内部必须是650px和270px。当我更改两个较小的宽度时,我没有问题,但是当我将父容器宽度更改为960时,内容似乎在浏览器中的大约2/3处切断。我有一个上面的标题部分和下面的页脚部分,它们遍布整个浏览器。我不确定为什么我的主要父容器会这样做。保存所有代码的被列为宽度为831,高度为1060或其他。为什么我的身体比容器小?当我没有将父容器的宽度设置为960px时,我的页面看起来很完美。
<body>
section.sidebar {
background-color: #ffffff;
margin-top: 0;
padding-top: 0;
overflow: auto;
}
h1.HeadOne {
color: white;
font-size: 30px;
font-weight: bold;
background-color: #4aaaa5;
padding-top: 30px;
padding-bottom: 30px;
padding-right: 20px;
padding-left: 20px;
overflow: auto;
margin-left: 135px;
margin-bottom: auto;
margin-top: auto;
float: left;
}
section.main {
width: 960px;
background-image: url(../images/vichy.png);
border-top: solid;
border-color: black;
border-width: thin;
clear: both;
overflow: auto;
}
ul {
margin-left: 575px;
padding-top: 35px;
float: left;
margin-top: auto;
list-style-type: none;
}
li {
display: inline-block;
font-size: 23px;
}
a {
text-decoration: none;
color: #A9A9A9;
font-size: 18px;
padding-left: 10px;
padding-right: 10px;
font-family: "Times New Roman", Times, serif;
}
a.blue:hover {
color: blue;
}
a.contact:hover {
color: orange;
}
a:link {
color: orange;
}
a:hover {
color: green;
}
a.contact {
border-left: solid;
border-right: solid;
border-color: #A9A9A9;
border-width: thin;
padding-right: 10px;
padding-left: 10px;
}
#Profile {
width: 190px;
height: 160px;
float: left;
margin-left: 20px;
margin-right: 20px;
padding-top: 25px;
}
#Profile:hover {
-ms-transform: rotate(-160deg);
-webkit-transform: rotate(-160deg);
-moz-transform: rotate(-160deg);
-o-transform: rotate(-160deg);
transform: rotate(-160deg);
}
.mainDiv {
background-color: white;
border: solid;
border-color: black;
border-width: thin;
width: 650px;
float: left;
margin-left: 130px;
margin-top: 50px;
margin-bottom: 50px;
padding-right: 30px;
padding-left: 10px;
overflow: auto;
}
h1.mainDivH1 {
font-size: 30px;
font-weight: bold;
color: #4aaaa5;
padding-top: 35px;
padding-bottom: 25px;
padding-left: 0px;
margin-left: 20px;
border-bottom: solid;
border-width: medium;
border-color: #cccccc;
}
p {
margin-left: auto;
margin-right: auto;
padding-top: 25px;
padding-right: 10px;
padding-left: 20px;
padding-bottom: 25px;
line-height: 150%;
font-family: 'Arial', 'Helvetica Neue', Helvetica, sans-serif;
}
p.p2 {
padding-top: 5px;
}
div.DivConnect {
float: left;
border: solid;
border-color: black;
border-width: thin;
background-color: white;
width: 270px;
height: 160px;
*/ padding-left: 0;
padding-bottom: 5px;
padding-top: 1px;
margin-left: 50px;
margin-top: 50px;
overflow: auto;
}
h2.ConnectHeader {
text-align: left;
color: #4aaaa5;
font-weight: bold;
padding-bottom: 20px;
padding-top: 20px;
margin-left: 30px;
font-size: 20px;
}
ol.ConnectList {
border-top: solid;
border-width: thin;
border-color: #cccccc;
padding-right: 5px;
padding-left: 1px;
padding-top: 20px;
margin-left: 19px;
margin-right: 5px;
}
li.connectLI {
float: left;
}
#facebook {
width: 58px;
}
#facebook:hover {
-ms-transform: rotate(90deg);
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
transform: rotate(90deg);
}
#linked {
width: 58px;
}
#linked:hover {
-ms-transform: rotate(270deg);
-webkit-transform: rotate(270deg);
-moz-transform: rotate(270deg);
-o-transform: rotate(270deg);
transform: rotate(270deg);
}
#twitter {
width: 58px;
}
#twitter:hover {
-ms-transform: rotate(-160deg);
-webkit-transform: rotate(-160deg);
-moz-transform: rotate(-160deg);
-o-transform: rotate(-160deg);
transform: rotate(-160deg);
}
footer.foot {
height: 60px;
border-color: black;
/*border-width: medium;*/
border-top: solid;
border-top-width: 8px;
background-color: #666666;
text-align: center;
padding-top: 30px;
}
form {
margin-left: 20px;
color: #A9A9A9;
font-family: 'Georgia', Times, Times New Roman, serif;
font-size: 15px;
margin-bottom: 1px;
padding-top: 20px;
}
input {
width: 580px;
}
h3 {
background-color: #4aaaa5;
width: 80px;
margin-left: 20px;
font-family: 'Georgia', Times, Times New Roman, serif;
font-weight: lighter;
color: white;
text-align: center;
padding: 10px;
margin-top: 1px;
margin-bottom: 30px;
}
h1.PortfolioH1 {
font-size: 30px;
font-weight: bold;
color: #4aaaa5;
padding-top: 40px;
padding-bottom: 20px;
padding-left: 0px;
padding-right: 20px;
margin-right: 70px;
margin-left: 35px;
margin-right: 20px;
border-bottom: solid;
border-width: medium;
border-color: #cccccc;
}
div.PortIm1 {
position: relative;
width: 230px;
top: 33px;
left: 35px;
}
#Pic1 {
width: 275px;
height: 170px;
margin-right: -50px;
}
#Pic1:hover {
outline: 5px solid green;
outline-offset: 10px;
}
div.mainDivPortfolio {
background-color: white;
border: solid;
border-color: black;
border-width: thin;
height: 720px;
width: 650px;
float: left;
margin-left: 130px;
margin-top: 50px;
margin-bottom: 50px;
padding-right: 30px;
padding-left: 10px;
overflow: hidden;
}
h4 {
text-align: center;
font-family: 'Times New Roman', Georgia, serif;
font-weight: lighter;
font-size: 20px;
color: white;
width: 275px;
background-color: #4aaaa5;
position: absolute;
bottom: 2px;
padding-top: 10px;
padding-bottom: 10px;
margin-bottom: 10px;
}
div.PortIm2 {
position: relative;
width: 230px;
left: 355px;
top: -140px;
bottom: 170px;
}
#Pic2 {
width: 275px;
height: 170px;
}
#Pic2:hover {
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}
div.PortIm3 {
position: relative;
width: 230px;
left: 355px;
top: -100px;
}
#Pic3 {
width: 275px;
height: 170px;
}
#Pic3:hover {
outline: thin solid orange;
outline-offset: 10px;
}
div.PortIm4 {
position: relative;
width: 230px;
bottom: 273px;
right: -35px;
}
#Pic4 {
width: 275px;
height: 170px;
}
#Pic4:hover {
-ms-transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
}
div.PortIm5 {
position: relative;
bottom: 235px;
left: 35px;
}
#Pic5 {
width: 275px;
height: 170px;
}
#Pic5:hover {
outline: medium solid yellow;
outline-offset: 10px;
}
答案 0 :(得分:0)
你已经在每个div中添加了边距,并且还为div元素添加了宽度,现在屏幕已被[small-div-width] + [margin]占用,并且此区域大于960px&#39; s为什么当你给主div的手动宽度时,较小的元素截止