2014-12-02 36 views
-2

在asp.net主頁時的瀏覽器窗口是resized.The圖像可以是任何GIF/PNG圖象防止-DIV - 嵌段 - 來自-運動時窗口調整大小的使用CSS

萬事達DIV的移動背後

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 id="anchordiv" class="anchordivclass"> 
      <a href="" style="color: Black" onmouseover="Show('Refeshbox','block');" onmouseout="Show('Refeshbox','none');"> 
       last updates info</a> 
     </div> 

任何幫助,高度讚賞。

感謝 溼婆

+0

「div正在移動」哪個div? – Zack 2014-12-02 15:13:28

+0

我很抱歉,我沒有描述這個問題。現在更新它。 – Shiva 2014-12-02 15:50:45

回答

0

看看你anchordivclass CSS。您有position: absoluteright: 530px。在這種情況下,div不會遵循正常的佈局。由於沒有指定位置的祖先元素,因此它始終保持自身距離窗口的右邊緣530個像素。

.anchordivclass 
{ 
    position: absolute; 
    top: 62px; 
    right: 530px; 
    text-align: right; 
    display: inline; 
    white-space: nowrap; 
    margin-left:0px; 
    margin-right:0px; 
} 
+0

Zack你能告訴我什麼是我需要在div的CSS做的改變。任何幫助表示讚賞 – Shiva 2014-12-02 16:18:57

+0

我只是說從'anchordivclass' CSS樣式中刪除'right:530px;'。你知道爲什麼當窗口調整大小時讓你的div移動嗎? 'right:530px;'使它從窗口的右邊緣保持530像素... – Zack 2014-12-02 16:21:15

+0

我有一個菜單,我需要將菜單結束後的圖像和超鏈接文本放在同一行。菜單是一個asp。淨用戶控制。爲了將圖像和超鏈接文本旁邊的菜單我用530px.and頂部:62px.我試過幾個選項,但每次它發生相同的。任何幫助讚賞 – Shiva 2014-12-02 16:38:28

相關問題