gpt4 book ai didi

HTML/CSS div 标签无法正常工作

转载 作者:行者123 更新时间:2023-11-28 16:37:40 25 4
gpt4 key购买 nike

我正在为一个学校元素(从头开始)制作一个网站。我打算在我的网站上有一栏作为标题,三栏作为信息,最后一行作为附加信息,但它看起来一团糟。即:

标题

信息 1 信息 2 信息 3

页脚

我已将信息替换为 Lorem Ipsum。

我做了一个可以查看的JSfiddle here .

我的 HTML 看起来像:

<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="styles.css">
<title>Profile</title>
</head>
<body>
<div class="container">
<div class="main-content">
<div class="title">
<h1>Lorem Ipsum</h1>
</div>
<div class="about">
<h3>About Me</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque ut lorem enim. Fusce ac varius ante. Mauris consequat, nibh viverra finibus consequat, erat mauris porttitor risus, id cursus nisi nunc id massa. Nullam imperdiet scelerisque lorem eget luctus. Nullam massa magna, luctus sit amet tellus vel, viverra ultrices velit. In commodo luctus odio ac tincidunt. Nullam feugiat erat tincidunt, cursus odio eu, accumsan lacus. Nunc sit amet tellus elementum, vehicula magna vel, feugiat tellus. Nullam et lorem iaculis lorem imperdiet commodo. Nulla facilisi. Etiam pulvinar vulputate auctor.</p>
</div>
<div class="school-life">
<h3>School Life</h3>
<p>Nam in quam euismod, sollicitudin arcu in, posuere erat. Phasellus ligula justo, efficitur quis odio eget, faucibus mollis sapien. Cras mi ipsum, sagittis ac orci porttitor, porta rutrum ipsum. Donec at libero molestie, venenatis eros et, faucibus lectus. Nullam ex enim, aliquam in tellus vel, porttitor egestas est. Nunc fermentum nisi justo, in ultricies arcu ornare sit amet. Duis nunc nulla, semper et libero ut, pulvinar condimentum sem. Aenean non eros id libero consectetur venenatis id nec magna. Fusce quis risus iaculis, tempus lectus eu, posuere nulla. Donec vitae posuere est, nec pellentesque elit. Phasellus mollis orci vel ex dignissim, sit amet pellentesque mauris luctus. Suspendisse eget dapibus sem.</p>
</div>
<div class="favourites">
<h3>My Favourites</h3>
<p>Aenean libero erat, pharetra sed feugiat id, tempus quis nulla. Donec a mi quam. Aenean nisl neque, blandit at scelerisque ac, finibus sit amet tellus. Fusce nec eros ac nulla suscipit molestie. Donec imperdiet nunc ac diam dignissim consectetur. Etiam malesuada cursus tellus, volutpat dignissim metus laoreet non. Etiam id quam hendrerit quam varius blandit vel consequat ex.</p>
</div>
</div>
<div class="hopes">
<h3>Hopes for the Future</h3>
<p>Proin eget condimentum turpis. Mauris elementum at nisi nec condimentum. Donec maximus diam sapien, eu rhoncus erat volutpat quis. Nulla tortor felis, tincidunt id sagittis vel, laoreet in erat. Nunc ultricies sed tellus sit amet faucibus. Nulla molestie justo id odio molestie aliquam. In fermentum diam in sapien molestie porttitor.</p>
</div>
</div>
</body>
</html>

我的 CSS 是:

.container {
margin: auto;
width: 1000px;
}
.title {
width:auto;
margin-top: 0px;
height: 100px;
background-color: red;
text-align: center;
line-height: 100px;
padding-top: 0px;
}
.main-content {
display: block;
}
.about {
width: 333px;
height: 700px;
background-color: lightblue;
float: left;
padding:10px 10px 10px 10px;
margin:0px 0px 0px 0px;
display: inline;
}
.school-life {
width: 300px;
height: 700px;
background-color: lightgreen;
float: center;
padding:10px 10px 10px 10px;
margin:0px 0px 0px 0px;
display: inline;
}
.favourites {
width: 333px;
height: 700px;
background-color: moccasin;
float: right;
padding:10px 10px 10px 10px;
margin:0px 0px 0px 0px;
display: inline
}
.hopes {
width:1000px;
height:auto;
background-color: black;
color:white;
padding: 10px 10px 10px 10px;
bottom: 0;
}

非常感谢您的帮助

最佳答案

给你:http://jsfiddle.net/jm3p7moj/2/

我不会解释我做了什么,因为发生了太多事情。只需阅读有关 css floats(你有 float: center; 这不是有效的 css),溢出(我用它来清除 float ),清除 float 。

* {
box-sizing: border-box;
}

这只是告诉浏览器对于每个元素,填充向内。

关于HTML/CSS div 标签无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25845757/

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