当调整浏览器窗口大小时div正在移动。图像可以是任何gif / png图像
主页代码背后
protected void Page_Load(object sender, EventArgs e)
{
const string imageGreen = "~/App_Ressources/Images/traffic_light_green_small.png";
HtmlGenericControl imgDiv = new HtmlGenericControl();
HtmlImage imgGreen = new HtmlImage();
imgGreen.Src = imageGreen;
imgDiv.Controls.Add(imgGreen);
HtmlGenericControl txtDiv = new HtmlGenericControl();
txtDiv.Attributes.Add("style", "color:green;");
StringBuilder sb = new StringBuilder();
sb.Append("Feed name as of " + DateTime.Now.ToString("dd MMM yyyy HH:mm"));
sb.Append("<br/>");
sb.Append("<br/>");
txtDiv.InnerHtml = sb.ToString();
imgDiv.Controls.Add(txtDiv);
Refeshbox.Controls.Add(imgDiv);
}
母版页
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="WebApplication1.SiteMaster" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
<title></title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
<style type="text/css">
.Refeshdiv
{
position: absolute;
top: 130px;
right: 400px;
width: 240px;
height: 244px;
padding: 10px;
color: green;
display: none;
border: 1px solid green;
z-index: 98001;
background-color: White;
}
.imgdivclass
{
position: absolute;
top: 56px;
right: 640px;
display: inline;
white-space: nowrap;
margin-left:0px;
margin-right:0px;
}
.anchordivclass
{
position: absolute;
top: 62px;
right: 530px;
text-align: right;
display: inline;
white-space: nowrap;
margin-left:0px;
margin-right:0px;
}
body
{
width: 100%;
background-color: white;
}
</style>
</head>
<body>
<form runat="server">
<script type="text/javascript" language="javascript">
function Show(id, visibility) {
var id = '<%=Refeshbox.ClientID%>';
document.getElementById(id).style.display = visibility;
}
</script>
<div class="page">
<div class="header">
<div class="title">
<h1>
My ASP.NET Application
</h1>
</div>
<div class="loginDisplay">
<asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
<AnonymousTemplate>
[ <a href="~/Account/Login.aspx" id="HeadLoginStatus" runat="server">Log In</a>
]
</AnonymousTemplate>
<LoggedInTemplate>
Welcome <span class="bold">
<asp:LoginName ID="HeadLoginName" runat="server" />
</span>! [
<asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out"
LogoutPageUrl="~/" />
]
</LoggedInTemplate>
</asp:LoginView>
</div>
<div class="clear hideSkiplink">
<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false"
IncludeStyleBlock="false" Orientation="Horizontal">
<Items>
<asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home" />
<asp:MenuItem NavigateUrl="~/About.aspx" Text="About" />
</Items>
</asp:Menu>
</div>
</div>
<div class="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
<%--<div id="divlink" class="adiv">--%>
<div id="imgdiv" class="imgdivclass">
<img id="imgLights" src="App_Ressources/Images/traffic_light_green_small.png" height="29px"
width="20px" alt="" />
</div>
<div id="anchordiv" class="anchordivclass">
<a href="" style="color: Black" onmouseover="Show('Refeshbox','block');" onmouseout="Show('Refeshbox','none');">
last updates info</a>
</div>
<%--</div>--%>
<div id="Refeshbox" class="Refeshdiv" runat="server">
</div>
</div>
<div class="clear">
</div>
</div>
<div class="footer">
</div>
</form>
</body>
</html>
当调整浏览器窗口大小时,div正在向左移动。 问题在于以下div标签。
<div id="anchordiv" class="anchordivclass">
<a href="" style="color: Black" onmouseover="Show('Refeshbox','block');" onmouseout="Show('Refeshbox','none');">
last updates info</a>
</div>
非常感谢任何帮助。
由于 婆
答案 0 :(得分:0)
查看您的anchordivclass
CSS。您拥有position: absolute
和right: 530px
的课程。在这种情况下,div将不遵循正常布局。它将始终保持自窗口右边缘530像素,因为没有指定位置的祖先元素。
.anchordivclass
{
position: absolute;
top: 62px;
right: 530px;
text-align: right;
display: inline;
white-space: nowrap;
margin-left:0px;
margin-right:0px;
}