html – 如何将CSS元素直接放在彼此之下?

前端之家收集整理的这篇文章主要介绍了html – 如何将CSS元素直接放在彼此之下?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我知道这可能是一个已经解决的问题,但我已经搜索过了,我无法解决问题.

所以,看.我有一个网站的基础知识.标题,精选内容,主要内容和页脚.我希望主要内容属于特色内容,但现在却落后于它.我怎样才能让它在它下面?

HTML

  1. <html>
  2. <head>
  3. <link href="style.css" type="text/css" rel="stylesheet">
  4. </head>
  5. <body>
  6. <div class="navigation"></div>
  7. <div class="content-featured"></div>
  8. </body>

CSS:

  1. html,body {
  2. margin: 0;
  3. padding: 0;
  4. }
  5.  
  6. .navigation {
  7. float: left;
  8. padding: 15px 0;
  9. min-width: 100%;
  10. opacity: .48; /* layer alpha */
  11. background-color: #1f1f1f; /* layer fill content */
  12. height: 20px;
  13. }
  14.  
  15. .content-featured {
  16. height: 384px;
  17. background-image: -moz-linear-gradient(bottom left,#1db568 -25%,#1db568 17.74%,#257755 125%); /* gradient overlay */
  18. background-image: -o-linear-gradient(bottom left,#257755 125%); /* gradient overlay */
  19. background-image: -webkit-linear-gradient(bottom left,#257755 125%); /* gradient overlay */
  20. background-image: linear-gradient(bottom left,#257755 125%); /* gradient overlay */
  21. }
  22.  
  23. .content-main {
  24. height: 308px;
  25. }

解决方法

创建一个容器div.无论您是想垂直堆叠还是水平堆叠,它都可以容纳您想要的一切.所以粗略看起来像这样:
  1. <div id="container">
  2. <div class="header">
  3. </div>
  4.  
  5. <div class="navigation">
  6. </div>
  7.  
  8. <div class="left-sidebar">
  9. </div>
  10.  
  11. <div class="content">
  12. </div>
  13. </div>

你的CSS就是

  1. #container {
  2. width:960px;
  3. }
  4. .header,.navigation {
  5. width: 100%;
  6. float:left;
  7. height: 80px;
  8. }
  9. .sidebar {
  10. width: 200px;
  11. float:left;
  12. min-height: 500px;
  13. }
  14. .content {
  15. width: 760px;
  16. float: left;
  17. min-height: 500px;
  18. }

猜你在找的HTML相关文章