我正在设置我的所有div
代码' height
以像素为单位。我遇到了一些问题,我认为如果我在height
设置%
,它会对我有所帮助。 %
正在使用width
,但很遗憾,我无法将div
height
设置为%。
这是我的CSS,我想用%
高度替换像素。
.header{
width:100%;
height:100px;
background: rgb(226,226,226); /* Old browsers */
background: -moz-linear-gradient(left, rgba(226,226,226,1) 0%, rgba(201,201,201,1) 37%, rgba(229,229,229,1) 65%, rgba(209,209,209,1) 78%, rgba(209,209,209,1) 78%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(226,226,226,1)), color-stop(37%,rgba(201,201,201,1)), color-stop(65%,rgba(229,229,229,1)), color-stop(78%,rgba(209,209,209,1)), color-stop(78%,rgba(209,209,209,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, rgba(226,226,226,1) 0%,rgba(201,201,201,1) 37%,rgba(229,229,229,1) 65%,rgba(209,209,209,1) 78%,rgba(209,209,209,1) 78%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, rgba(226,226,226,1) 0%,rgba(201,201,201,1) 37%,rgba(229,229,229,1) 65%,rgba(209,209,209,1) 78%,rgba(209,209,209,1) 78%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, rgba(226,226,226,1) 0%,rgba(201,201,201,1) 37%,rgba(229,229,229,1) 65%,rgba(209,209,209,1) 78%,rgba(209,209,209,1) 78%); /* IE10+ */
background: linear-gradient(to right, rgba(226,226,226,1) 0%,rgba(201,201,201,1) 37%,rgba(229,229,229,1) 65%,rgba(209,209,209,1) 78%,rgba(209,209,209,1) 78%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#e2e2e2', endColorstr='#d1d1d1',GradientType=1 ); /* IE6-9 */
}
.logo{
margin: 0px 0;
padding: 15px 0px 0px 130px;
cursor: pointer;
float:left;
}
.heading{
float: left;
margin-top: 0px;
margin-left: 6px;
height: 50px;
width: 75%;
background-color: #D1D0CE;
text-align:center;
}
body{
margin:0;
padding:0;
width:100%;
font:normal 12px/1.5em "Liberation sans", Arial, Helvetica, sans-serif;
overflow-x: hidden;
background-image:url('image/silver.jpg');
background-repeat:no-repeat;
background-size:cover;
}
.footer{
width:100%;
height:50px;
background: rgb(226,226,226); /* Old browsers */
background: -moz-linear-gradient(left, rgba(226,226,226,1) 0%, rgba(201,201,201,1) 37%, rgba(229,229,229,1) 65%, rgba(209,209,209,1) 78%, rgba(209,209,209,1) 78%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(226,226,226,1)), color-stop(37%,rgba(201,201,201,1)), color-stop(65%,rgba(229,229,229,1)), color-stop(78%,rgba(209,209,209,1)), color-stop(78%,rgba(209,209,209,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, rgba(226,226,226,1) 0%,rgba(201,201,201,1) 37%,rgba(229,229,229,1) 65%,rgba(209,209,209,1) 78%,rgba(209,209,209,1) 78%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, rgba(226,226,226,1) 0%,rgba(201,201,201,1) 37%,rgba(229,229,229,1) 65%,rgba(209,209,209,1) 78%,rgba(209,209,209,1) 78%); /* Opera 11.10+ */
background: -ms-linear-gradient(left, rgba(226,226,226,1) 0%,rgba(201,201,201,1) 37%,rgba(229,229,229,1) 65%,rgba(209,209,209,1) 78%,rgba(209,209,209,1) 78%); /* IE10+ */
background: linear-gradient(to right, rgba(226,226,226,1) 0%,rgba(201,201,201,1) 37%,rgba(229,229,229,1) 65%,rgba(209,209,209,1) 78%,rgba(209,209,209,1) 78%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#e2e2e2', endColorstr='#d1d1d1',GradientType=1 ); /* IE6-9 */
}
h1{
display:inline-block;
}
.outer {
margin-left: 20%;
margin-top: 3%;
margin-bottom: 3%;
height: 737px;
width: 60%;
box-shadow: 10px 10px 5px #888888;
border: 1px solid #f9f2f2;
border-radius: 10px;
}
button.logout{
float:right;
margin-right:10px;
}
.log {
width:60%;
height: 10%;
position: absolute;
border: 1px solid #f9f2f2;
border-radius: 10px;
background: -o-linear-gradient(bottom, #e5e3e3 5%, #ffffff 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #e5e3e3), color-stop(1, #ffffff));
background: -moz-linear-gradient(center top, #e5e3e3 5%, #ffffff 100%);
filter: progid: DXImageTransform.Microsoft.gradient(startColorstr="#e5e3e3", endColorstr="#ffffff");
background: -o-linear-gradient(top, #e5e3e3, ffffff);
background-color: #e5e3e3;
border: 0px solid #f9f2f2;
text-align: center;
line-height:20px;
border-width: 0px 0px 1px 1px;
}
.rest {
height: 685px;
background: -o-linear-gradient(bottom, #e5e3e3 5%, #ffffff 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #e5e3e3), color-stop(1, #ffffff));
background: -moz-linear-gradient(center top, #e5e3e3 5%, #ffffff 100%);
filter: progid: DXImageTransform.Microsoft.gradient(startColorstr="#e5e3e3", endColorstr="#ffffff");
background: -o-linear-gradient(top, #e5e3e3, ffffff);
background-color: #e5e3e3;
border: 1px solid #f9f2f2;
border-width: 0px 0px 0px 0px;
border-radius: 0px 0px 10px 10px;
text-align: left;
padding: 0px 7px;
}
.sidemenu {
float: left;
margin-top: 150px;
width: 100%;
}
.content {
border-left: thick solid #f9f2f2;
}
.side{
width: 24%;
float: left;
display: inline-block;
}
hr {
margin: 0;
width: 1px;
height: 660px;
border: 0;
background: #fff;
float: left;
}
.astext {
background:none;
border:none;
margin:0;
padding:0;
cursor:pointer;
color:#000000;
line-height:35px;
font-family:arial;
font-size:13px;
font-weight:bold;
}
a.astext:link,a.astext:visited {
color:black;
background-color:transparent;
text-decoration:none;
}
a.astext:hover,a.astext:active {
color:black;
background-color:transparent;
text-decoration:none;
}
.menu{
height: 45px;
text-align:left;
margin-left:2px;
background: -o-linear-gradient(bottom, #e5e3e3 5%, #ffffff 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #e5e3e3), color-stop(1, #ffffff));
background: -moz-linear-gradient(center top, #e5e3e3 5%, #ffffff 100%);
filter: progid: DXImageTransform.Microsoft.gradient(startColorstr="#e5e3e3", endColorstr="#ffffff");
background: -o-linear-gradient(top, #e5e3e3, ffffff);
background-color: #e5e3e3;
border: 1px solid #f9f2f2;
border-width: 0px 0px 0px 0px;
border-radius: 0px 0px 10px 10px;
text-align: left;
padding: 0px 7px;
}
.menu:hover{
background: -o-linear-gradient(top, #e5e3e3 5%, #ffffff 100%);
background: -webkit-gradient(linear, left bottom, left top, color-stop(0.05, #e5e3e3), color-stop(1, #ffffff));
background: -moz-linear-gradient(center bottom, #e5e3e3 5%, #ffffff 100%);
filter: progid: DXImageTransform.Microsoft.gradient(startColorstr="#e5e3e3", endColorstr="#ffffff");
background: -o-linear-gradient(bottom, #e5e3e3, ffffff);
background-color: #e5e3e3;
border: 1px solid #f9f2f2;
border-width: 0px 0px 0px 0px;
border-radius: 0px 0px 10px 10px;
text-align: left;
padding: 0px 7px;
}

<body>
<div class="main">
<div class="header">
<img src="image/DZB.png" class="logo" style="width:110px;height:70px" alt="logo"/>
</div> <!--End of header div-->
<div class="outer">
<div class="log">
<h1>Profile</h1>
<form method="post"> <button class="logout" name="logout" >Logout</button></form>
</div> <!--End of log div -->
<div class="rest">
<div class="side">
<div class="sidemenu">
<div class="1 menu">
<a href="admin_dashboard.php" class="astext">Profile</a>
</div> <!--End of menu1 -->
<div class="2 menu">
<a href="clients.php" class="astext">Clients</a>
</div> <!--End of menu 2-->
<div class="3 menu">
<a href="employees.php" class="astext">Employees</a>
</div> <!--End of menu 3-->
<div class="menu 4">
<a href="admin_file_view.php" class="astext">Documents</a>
</div> <!--End of menu 4-->
</div> <!--End of side menu -->
</div> <!--End of side div -->
<hr>
<!-- <div class="heading" >
<h1>Profile</h1>
</div> End of heading div -->
<div class="content">
</div> <!--End of content -->
</div> <!--End of rest div -->
</div> <!--End of outer div-->
<div class="footer">
</div>
</div> <!--End of main div-->
</body>
&#13;
答案 0 :(得分:1)
试试这个
.sidemenu
{
left: 0px;
margin-top: 150px;
position: absolute;
height: 25%;
width: 30%;
}
<div class="sidemenu">
<div class="1 menu">
<a href="admin_dashboard.php" class="astext">Profile</a>
</div>
<div class="2 menu">
<a href="clients.php" class="astext">Clients</a>
</div>
<div class="3 menu">
<a href="employees.php" class="astext">Employees</a>
</div>
<div class="menu 4">
<a href="admin_file_view.php" class="astext">Documents</a>
</div>
</div>
答案 1 :(得分:1)
div
修正了%
的任何高度,则必须修正它的父div
的高度。下面是一个例子...
的CSS -
.parent_div{
height:500px;
position:relative;
}
.chield_div{
height:50%;
position:relative;
}