gpt4 book ai didi

html - 子div影响父div?

转载 作者:太空宇宙 更新时间:2023-11-04 04:33:09 25 4
gpt4 key购买 nike

我想做的是给一个 div margin-top: 30px; 但它似乎将整个页面向下移动 30px,而不是仅将那个 div。这就像子 div 正在影响父 div?

有什么建议吗?

HTML:

   <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="BBcolForum.master.cs" Inherits="BBcolForum.BBcolForum" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link type="text/css" rel="stylesheet" href="css/default.css" />
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>

<div id="content">
<form id="form1" runat="server">

<div class="header" style="margin-top:0px;">
<h1 style="color:Aqua; margin-top:30px;">Student Forum</h1>
</div>

<div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">



</asp:ContentPlaceHolder>
</div>



</form>
</div>


</body>
</html>

CSS;

body 
{
background-image:url('/img/blue_back.png');
background-repeat:repeat-x;

}

#content
{
background-color:White;
width: 800px;
height:900px;
margin: 0 auto 0 auto;

}

.header
{
border-bottom:1px solid #000000;
height:100px;
color:Blue;



}

最佳答案

这正是正在发生的事情,是的。具有 margin-top 的元素的直接子元素也将插入父元素。作为一个非常简单/快速的修复方法,您是否考虑过使用填充来代替?

否则,您可以根据 this previous discussion on the topic 在父级上使用 overflow: auto , 和 this one too .

关于html - 子div影响父div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16899899/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com