gpt4 book ai didi

html - 布局问题( float /填充)

转载 作者:行者123 更新时间:2023-11-28 06:19:29 26 4
gpt4 key购买 nike

我有布局问题,试图理解 float 和如何定位元素。我对 css/html 很陌生。有人可以帮助我了解此布局的工作原理。一些问题:

1) 无法在不破坏布局的情况下更改页脚的高度,页脚似乎被向上推了。

2) 当我通过 chrome 检查页面时,页脚 div 包含在代码中的“包装”div 内部。

3) 向内容 div 添加 padding 似乎也破坏了布局

<!DOCTYPE html>

<html lang="en">

<head>
<title>DCW</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>

<body>

<!--NAV BAR -->

<nav>
<ul>
<div class="float-left">
<li><a class="active" href="default.asp">PD</a></li>
<li><a href="news.asp">Projects</a></li>
<li><a href="About.asp">About</a></li>
<li><a href="Contact.asp">Contact</a></li>
</div>
<div class="float-right">
<li><a href="#">Hire Us!</a></li>
</div>
</ul>

</nav>

<!-- HEADER -->

<header>

<div id="title_wrapper">

</div>

</header>

<!-- BODY CONTENT -->

<div id="wrapper">

<div id="content">

<div class="info">
col1

</div>

<div class="info">
col2

</div>

</div>

<!-- SIDEBAR -->

<div id="sidebar">

<div id="sidebar-text">
content 2

</div>

</div>

</div>

<!-- FOOTER -->

<footer>
Footer

</footer>

</body>

CSS:

html, body
{
width: 100%;
height: 100%;
margin:0;
padding: 0;
}

p.thick {
font-weight: bold;
}

h1, p {
padding: 0;
margin: 0;
}



/*Nav */


nav ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}

nav li {
float: left;
}

nav li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}

/* Change the link color to #111 (black) on hover */
nav li a:hover {
background-color: #111;
}

.active {
background-color: #4CAF50;
}

.float-left {
float:left;
}
.float-right {
float:right;
}


/* Header */

header #title_text{

font-size: 100px;
font-family: arial;

}

header #title_wrapper{
text-align:center;
position: relative;
top: 200px;

}

header {

background-color: orange;
position: relative;
height:100%;
width: 100%;
color:white;
margin:0;




}

/*Content*/

#wrapper{

min-height: 70%;
height: auto;
height: 70%;

}

#content{
float:left;
width:100%;
height: 100%;
text-align: center;

}


#sidebar{

float: left;
background-color: lightgrey;
height: 75%;
text-align: center;
width: 100%;

}

#sidebar-text{
font: 14px/22px normal helvetica, sans-serif;
padding-top: 30px;
text-decoration: none;
line-height: 200%;
}



.img-circle {
border-radius: 50%;
}


.info{
width: 50%;
float: left;
}


blockquote.style2 {
font: 14px/22px normal helvetica, sans-serif;
margin-top: 10px;
margin-bottom: 10px;
margin-left: 50px;
padding-left: 15px;
border-left: 3px solid #ccc;
outline-style: double;
outline-color: lightgrey;

}

/* footer */
footer{
background-color: orange;
}

干杯

最佳答案

我确实制作了一个 +200 像素的填充内容和一个 +200 像素的页脚。除了页脚上的 display:inline-block 和内容上的 box-sizing: border-box; 外,没有任何改变。

html, body
{
width: 100%;
height: 100%;
margin:0;
padding: 0;
}

p.thick {
font-weight: bold;
}

h1, p {
padding: 0;
margin: 0;
}



/*Nav */


nav ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}

nav li {
float: left;
}

nav li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}

/* Change the link color to #111 (black) on hover */
nav li a:hover {
background-color: #111;
}

.active {
background-color: #4CAF50;
}

.float-left {
float:left;
}
.float-right {
float:right;
}


/* Header */

header #title_text{

font-size: 100px;
font-family: arial;

}

header #title_wrapper{
text-align:center;
position: relative;
top: 200px;

}

header {

background-color: orange;
position: relative;
height:100%;
width: 100%;
color:white;
margin:0;




}

/*Content*/

#wrapper{

min-height: 70%;
height: auto;
height: 70%;

}

#content{
float:left;
width:100%;
height: 100%;
text-align: center;
padding:100px;
box-sizing: border-box;
}


#sidebar{

float: left;
background-color: lightgrey;
height: 75%;
text-align: center;
width: 100%;

}

#sidebar-text{
font: 14px/22px normal helvetica, sans-serif;
padding-top: 30px;
text-decoration: none;
line-height: 200%;
}



.img-circle {
border-radius: 50%;
}


.info{
width: 50%;
float: left;
}


blockquote.style2 {
font: 14px/22px normal helvetica, sans-serif;
margin-top: 10px;
margin-bottom: 10px;
margin-left: 50px;
padding-left: 15px;
border-left: 3px solid #ccc;
outline-style: double;
outline-color: lightgrey;

}

/* footer */
footer{
display: inline-block;
background-color: orange;
height:200px;
width: 100%;
}
<!DOCTYPE html>

<html lang="en">

<head>
<title>DCW</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>

<body>

<!--NAV BAR -->

<nav>
<ul>
<div class="float-left">
<li><a class="active" href="default.asp">PD</a></li>
<li><a href="news.asp">Projects</a></li>
<li><a href="About.asp">About</a></li>
<li><a href="Contact.asp">Contact</a></li>
</div>
<div class="float-right">
<li><a href="#">Hire Us!</a></li>
</div>
</ul>

</nav>

<!-- HEADER -->

<header>

<div id="title_wrapper">

</div>

</header>

<!-- BODY CONTENT -->

<div id="wrapper">

<div id="content">

<div class="info">
col1

</div>

<div class="info">
col2

</div>

</div>

<!-- SIDEBAR -->

<div id="sidebar">

<div id="sidebar-text">
content 2

</div>

</div>

</div>

<!-- FOOTER -->

<footer>
Footer

</footer>

</body>

关于html - 布局问题( float /填充),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35693348/

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