有時後會遇到需要div畫面置中的情況
.float_windows_background {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
background-repeat: repeat;
z-index: 80;
}
<div class="float_windows_background">
<div id="Div1" style="width: 100%; height: 100%; vertical-align: middle; text-align: center;">
<span id="float_windows_top" style="height: 50%; display: inline-block;"></span>
<div class="float_windows_detail" style="text-align: center;">
<%-- 內容放此--%>
</div>
</div>
</div>
var divdetail = $('.float_windows_detail');
$(document).ready(function () {
var detailh = parseInt('100') + 10; //高度為100
divdetail.height(detailh);
var margintop = "-" + (detailh / 2).toString() + "px";
$(".float_windows_detail").css({ "margin-top": margintop });
});
解說:
先讓畫面div佔一半,然後再讓div2設定好位置移上去即可
.float_windows_background {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
background-repeat: repeat;
z-index: 80;
}
<div class="float_windows_background">
<div id="Div1" style="width: 100%; height: 100%; vertical-align: middle; text-align: center;">
<span id="float_windows_top" style="height: 50%; display: inline-block;"></span>
<div class="float_windows_detail" style="text-align: center;">
<%-- 內容放此--%>
</div>
</div>
</div>
var divdetail = $('.float_windows_detail');
$(document).ready(function () {
var detailh = parseInt('100') + 10; //高度為100
divdetail.height(detailh);
var margintop = "-" + (detailh / 2).toString() + "px";
$(".float_windows_detail").css({ "margin-top": margintop });
});
解說:
先讓畫面div佔一半,然後再讓div2設定好位置移上去即可