0

CSS 新手的第二个布局问题。

我在站点母版页的 ASP.NET 布局中有生成的 .Main div。我添加了一个名为“Show.aspx”的新页面,并为此添加了一些 div。我想做的是根据'Show.aspx'的描述div的大小来扩展'.main'div

要添加,我在源服务器端添加了“描述”div,其中 .main 在站点主 CSS 页面中。

这是显示问题的屏幕截图:

在此处输入图像描述

如图所示,白色的 .main div 没有展开。我尝试添加溢出:自动但再次无济于事。因为我在经过一些研究后在我的 div 上使用了浮动样式,所以这可能是问题所在,但我不知道为什么。

代码:

网站管理员.main:

<!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" />

</head>
<body>
<form runat="server">
<div class="page">

    <asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
    <div class="header">
        <div class="title">

            <h1>

             <img id="Img1" src = "Images/coffe pic.png" alt="" runat="server" />
                Coffee Stop

                </h1>
        </div>
        <div class="loginDisplay">
        </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 Text="Shop Online" Value="Shop Online"></asp:MenuItem>
                    <asp:MenuItem Text="Contact Us" Value="Contact Us"></asp:MenuItem>
                    <asp:MenuItem Text="About Us" Value="About Us"></asp:MenuItem>
                </Items>
            </asp:Menu>
        </div>
    </div>
    <div class="main">
        <asp:ContentPlaceHolder ID="MainContent" runat="server"/>
    </div>
    <div class="clear">
    </div>
</div>
<div class="footer">

</div>
</form>
</body>
</html>

我的服务器端添加了 Show.aspx 页面的 div:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Show.aspx.cs" Inherits="ViewCDs.Show" %>

   <asp:FormView ID="FormView1" runat="server" Height="141px">
       <EditItemTemplate>
           coffeeName:
           <asp:TextBox ID="coffeeNameTextBox" runat="server" 
               Text='<%# Bind("coffeeName") %>' />
           <br />
           coffeeOrigin:
           <asp:TextBox ID="coffeeOriginTextBox" runat="server" 
               Text='<%# Bind("coffeeOrigin") %>' />
           <br />
           coffeeStrength:
           <asp:TextBox ID="coffeeStrengthTextBox" runat="server" 
               Text='<%# Bind("coffeeStrength") %>' />
           <br />
           coffeeGrind:
           <asp:TextBox ID="coffeeGrindTextBox" runat="server" 
               Text='<%# Bind("coffeeGrind") %>' />
           <br />
           coffeePrice:
           <asp:TextBox ID="coffeePriceTextBox" runat="server" 
               Text='<%# Bind("coffeePrice") %>' />
           <br />
           coffeeQty:
           <asp:TextBox ID="coffeeQtyTextBox" runat="server" 
               Text='<%# Bind("coffeeQty") %>' />
           <br />
           coffeeRRP:
           <asp:TextBox ID="coffeeRRPTextBox" runat="server" 
               Text='<%# Bind("coffeeRRP") %>' />
           <br />
           <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
               CommandName="Update" Text="Update" />
           &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
               CausesValidation="False" CommandName="Cancel" Text="Cancel" />
       </EditItemTemplate>
       <InsertItemTemplate>
           coffeeName:
           <asp:TextBox ID="coffeeNameTextBox" runat="server" 
               Text='<%# Bind("coffeeName") %>' />
           <br />
           coffeeOrigin:
           <asp:TextBox ID="coffeeOriginTextBox" runat="server" 
               Text='<%# Bind("coffeeOrigin") %>' />
           <br />
           coffeeStrength:
           <asp:TextBox ID="coffeeStrengthTextBox" runat="server" 
               Text='<%# Bind("coffeeStrength") %>' />
           <br />
           coffeeGrind:
           <asp:TextBox ID="coffeeGrindTextBox" runat="server" 
               Text='<%# Bind("coffeeGrind") %>' />
           <br />
           coffeePrice:
           <asp:TextBox ID="coffeePriceTextBox" runat="server" 
               Text='<%# Bind("coffeePrice") %>' />
           <br />
           coffeeQty:
           <asp:TextBox ID="coffeeQtyTextBox" runat="server" 
               Text='<%# Bind("coffeeQty") %>' />
           <br />
           coffeeRRP:
           <asp:TextBox ID="coffeeRRPTextBox" runat="server" 
               Text='<%# Bind("coffeeRRP") %>' />
           <br />
           <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
               CommandName="Insert" Text="Insert" />
           &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
               CausesValidation="False" CommandName="Cancel" Text="Cancel" />
       </InsertItemTemplate>
       <ItemTemplate>

           <b>Origin:</b>
           <asp:Label ID="coffeeOriginLabel" runat="server" 
               Text='<%# Bind("coffeeOrigin") %>' />
           <br />

           <b>Grind:</b>
           <asp:Label ID="coffeeGrindLabel" runat="server" 
               Text='<%# Bind("coffeeGrind") %>' />
           <br />

           <b>Price: £</b>
           <asp:Label ID="coffeePriceLabel" runat="server" 
               Text='<%# Bind("coffeePrice") %>' />
           <br />

               <b>Strength:</b>
           <asp:Label ID="coffeeStrengthLabel" runat="server" 
               Text='<%# Bind("coffeeStrength") %>' />
           <br />

           <b>Stock Level:</b>
           <asp:Label ID="coffeeQtyLabel" runat="server" Text='<%# Bind("coffeeQty") %>' />
           <br />


       </ItemTemplate>
   </asp:FormView>
   <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
       ConnectionString="<%$ ConnectionStrings:CoffeeConnectionString %>" 
       SelectCommand="SELECT [coffeeName], [coffeeOrigin], [coffeeStrength], [coffeeGrind], [coffeePrice], [coffeeQty], [coffeeRRP] FROM [Coffees]">
   </asp:SqlDataSource>

   <br />


豆子光滑课程
  <div style=" float:left; width: 165px; height: 40px;">
  <br />
      <b><asp:Label ID="Label2" runat="server" Text="Quantity:"></asp:Label></b>
 </div>

  <div style=" float:right; width: 165px; height: 40px;">
   <br />

      <asp:TextBox ID="TextBox1" runat="server" Width="40px">1</asp:TextBox>

 </div>
     <div style=" float:left; width: 165px; height: 40px;">
     <br />

         <asp:Button ID="Button1" runat="server" Text="Buy" />

 </div>

 <div>

</div>
</div>

<br />
<br />

<div id = "titleDescrip" style="position:absolute; top:445px; font-size:20pt;" runat="server" > 

</div> 

<div id="divDescrip" style="position:absolute; top:480px; width:925px;" runat="server"> 

</div>

</asp:Content>
4

2 回答 2

1

看到有几件事情你需要了解。

母版页和子页在运行时都合并为一个。

我的意思是假设您的母版页中有以下容器

<div class="main">
     <asp:ContentPlaceHolder id="mainContent" runat="server">
     </asp:ContentPlaceHolder">
</div>

在你的子页面中,即Show.aspx,你有你的容器,比如

   <asp:Content id="mains" ContentPlaceHolderId="mainContent">
         <div class="pagecontent">
         </div>
         <div class="description">
         </div> 
   </asp:Content>

然后在运行时它们会被渲染成这样(当然还有更多的容器):

<div class="main">
    <div class="pagecontent">
    </div>
    <div class="description">
    </div>
</div>

其次,你正在使用position:absolute你的内在元素,不要那样做。

当您这样做时position:absolute,您会从文档正常流程中删除该元素,所以现在,松散地说,父 div 并不关心其绝对定位的子元素的尺寸!

看到这个小提琴

无论你给内部 div 的高度是多少,main 总是相应地扩展,因为 main 没有定义高度,因此它的 height:auto

于 2013-03-23T20:03:52.217 回答
0

尝试

.main

{

display:table-column;
padding: 0px 12px;
margin: 12px 8px 8px 8px;
min-height: 420px;

}

并添加显示:块;到儿童班

于 2013-03-23T20:29:17.253 回答