html - 现代网页设计中的CSS布局

标签 html css css-float

自从 CSS 诞生以来,我就被它吓坏了。 无论如何,我正在尝试了解一种进行现代 css 布局的功能方法。

假设一个网站有一个顶部菜单、一个左浮动菜单、一个右浮动新闻提要和一个居中内容。

我试过这个:

.leftcontent {
  float:left;
  height:100%;
  background-color:blue;
}
.rightcontent {
  float:left;
  height:100%;
  background-color:aqua;
}
.centercontent {
  height:100%;
  background-color:green;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>

<div class="container">

  <div class="leftcontent">
    <p>
      Well, you can tell by the way I use my walk
      I'm a woman's man, no time to talk
      Music loud and women warm, I've been kicked around
      Since I was born
      And now it's alright, it's okay
      And you may look the other way
      We can try to understand
      The New York Times' effect on man
      Whether you're a brother or whether you're a mother
      You're stayin' alive, stayin' alive
      Feel the city breakin' and everybody shakin'
      And we're stayin' alive, stayin' alive
      Ah, ha, ha, ha, stayin' alive, stayin' alive
      Ah, ha, ha, ha, stayin' alive
      Well now, I get low and I get high
      And if I can't get either, I really try
      Got the wings of heaven on my shoes
      I'm a dancin' man and I just can't lose
      You know it's alright, it's okay
      I'll live to see another day
      We can try to understand
      The New…
    </p>
  </div>
  <div class="centercontent">
    Every day I wake up
    Every day I wake up alone
    Every day I wake up
    Every day I wake up alone
    Let me open up the discussion with 
    I'm not impressed 
    With any mother fucking word I say
    See I lied that I cried
    When he came inside
    And now I'm burning a highway Hades
    Shut the fuck up
    When I'm trying to think
    I gotta keep my concentration 
    Give me one more drink
    And then I'll try to remember all the advice 
    That my good book told me
    And all the lost souls say
    Every day I wake up
    Every day I wake up alone
    (Kill me just kill me)
    Or get me out of the sun
    Every day I wake up
    Every day I wake up alone
    (Kill me just kill me)
    Someone get me out of the sun
    Drugs, bars, backseats of cars blowing boys
    What a boring life I've led so far
    Just a prime thirteen 
    When I…
    Every day I wake up
    Every day I wake up alone
    Every day I wake up
    Every day I wake up alone
    Let me open up the discussion with 
    I'm not impressed 
    With any mother fucking word I say
    See I lied that I cried
    When he came inside
    And now I'm burning a highway Hades
    Shut the fuck up
    When I'm trying to think
    I gotta keep my concentration 
    Give me one more drink
    And then I'll try to remember all the advice 
    That my good book told me
    And all the lost souls say
    Every day I wake up
    Every day I wake up alone
    (Kill me just kill me)
    Or get me out of the sun
    Every day I wake up
    Every day I wake up alone
    (Kill me just kill me)
    Someone get me out of the sun
    Drugs, bars, backseats of cars blowing boys
    What a boring life I've led so far
    Just a prime thirteen 
    When I…Every day I wake up
    Every day I wake up alone
    Every day I wake up
    Every day I wake up alone
    Let me open up the discussion with 
    I'm not impressed 
    With any mother fucking word I say
    See I lied that I cried
    When he came inside
    And now I'm burning a highway Hades
    Shut the fuck up
    When I'm trying to think
    I gotta keep my concentration 
    Give me one more drink
    And then I'll try to remember all the advice 
    That my good book told me
    And all the lost souls say
    Every day I wake up
    Every day I wake up alone
    (Kill me just kill me)
    Or get me out of the sun
    Every day I wake up
    Every day I wake up alone
    (Kill me just kill me)
    Someone get me out of the sun
    Drugs, bars, backseats of cars blowing boys
    What a boring life I've led so far
    Just a prime thirteen 
    When I…
  </div>
  <div class="rightcontent">
    The only thing I ever wanted
    The only thing I ever needed
    Is my own way, I gotta have it all
    I don't want your opinion, I don't need your ideas
    Stay the fuck out of my face, stay away from me
    I am my own God, I do as I please
    Just wipe your own ass and shut your mouth
    I had enough and you're going down
    Shut your mouth
    What comes around you know goes around
    My mind is playing tricks on me
    I am not as stable as I used to be
    Pushed and shoved, you know you're going too far
    I will not break my back for you no more
    I am gonna go my way, I am gonna take control
    Time to wake up and dig myself out of this hell
    Just wipe your own ass and shut your mouth
    I had enough and you're going down
    Shut your…
  </div>

</div>

</body>
</html>

not working, wow

好吧,我很失望。所有 float 的解释都付之东流。 我期待的是左右浮动的 div 和居中的内容。

或者,执行我描述的操作的最佳方法是什么?具有内联(或内联 block )显示的 div?如果您链接示例,我也可以工作

有人可以修复或提供工作示例吗?

最佳答案

您可以使用 position: fixed 使左右菜单 float 。

body {
  margin: 0;
  padding: 0;
}
.leftcontent {
  position: fixed;
  width: 25%;
  top: 0;
  left: 0;
  background-color:blue;
}
.rightcontent {
  position: fixed;
  width: 25%;
  top: 0;
  right: 0;
  background-color:aqua;
}
.centercontent {
  width: 50%;
  margin: 0 auto;
  background-color:green;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>

<div class="container">

  <div class="leftcontent">
    Well, you can tell by the way I use my walk
    I'm a woman's man, no time to talk
    Music loud and women warm, I've been kicked around
    Since I was born
    And now it's alright, it's okay
    And you may look the other way
    We can try to understand
    The New York Times' effect on man
    Whether you're a brother or whether you're a mother
    You're stayin' alive, stayin' alive
    Feel the city breakin' and everybody shakin'
    And we're stayin' alive, stayin' alive
    Ah, ha, ha, ha, stayin' alive, stayin' alive
    Ah, ha, ha, ha, stayin' alive
    Well now, I get low and I get high
    And if I can't get either, I really try
    Got the wings of heaven on my shoes
    I'm a dancin' man and I just can't lose
    You know it's alright, it's okay
    I'll live to see another day
    We can try to understand
    The New…
  </div>
  <div class="centercontent">
    Every day I wake up
    Every day I wake up alone
    Every day I wake up
    Every day I wake up alone
    Let me open up the discussion with 
    I'm not impressed 
    With any mother fucking word I say
    See I lied that I cried
    When he came inside
    And now I'm burning a highway Hades
    Shut the fuck up
    When I'm trying to think
    I gotta keep my concentration 
    Give me one more drink
    And then I'll try to remember all the advice 
    That my good book told me
    And all the lost souls say
    Every day I wake up
    Every day I wake up alone
    (Kill me just kill me)
    Or get me out of the sun
    Every day I wake up
    Every day I wake up alone
    (Kill me just kill me)
    Someone get me out of the sun
    Drugs, bars, backseats of cars blowing boys
    What a boring life I've led so far
    Just a prime thirteen 
    When I…
    Every day I wake up
    Every day I wake up alone
    Every day I wake up
    Every day I wake up alone
    Let me open up the discussion with 
    I'm not impressed 
    With any mother fucking word I say
    See I lied that I cried
    When he came inside
    And now I'm burning a highway Hades
    Shut the fuck up
    When I'm trying to think
    I gotta keep my concentration 
    Give me one more drink
    And then I'll try to remember all the advice 
    That my good book told me
    And all the lost souls say
    Every day I wake up
    Every day I wake up alone
    (Kill me just kill me)
    Or get me out of the sun
    Every day I wake up
    Every day I wake up alone
    (Kill me just kill me)
    Someone get me out of the sun
    Drugs, bars, backseats of cars blowing boys
    What a boring life I've led so far
    Just a prime thirteen 
    When I…Every day I wake up
    Every day I wake up alone
    Every day I wake up
    Every day I wake up alone
    Let me open up the discussion with 
    I'm not impressed 
    With any mother fucking word I say
    See I lied that I cried
    When he came inside
    And now I'm burning a highway Hades
    Shut the fuck up
    When I'm trying to think
    I gotta keep my concentration 
    Give me one more drink
    And then I'll try to remember all the advice 
    That my good book told me
    And all the lost souls say
    Every day I wake up
    Every day I wake up alone
    (Kill me just kill me)
    Or get me out of the sun
    Every day I wake up
    Every day I wake up alone
    (Kill me just kill me)
    Someone get me out of the sun
    Drugs, bars, backseats of cars blowing boys
    What a boring life I've led so far
    Just a prime thirteen 
    When I…
  </div>
  <div class="rightcontent">
    The only thing I ever wanted
    The only thing I ever needed
    Is my own way, I gotta have it all
    I don't want your opinion, I don't need your ideas
    Stay the fuck out of my face, stay away from me
    I am my own God, I do as I please
    Just wipe your own ass and shut your mouth
    I had enough and you're going down
    Shut your mouth
    What comes around you know goes around
    My mind is playing tricks on me
    I am not as stable as I used to be
    Pushed and shoved, you know you're going too far
    I will not break my back for you no more
    I am gonna go my way, I am gonna take control
    Time to wake up and dig myself out of this hell
    Just wipe your own ass and shut your mouth
    I had enough and you're going down
    Shut your…
  </div>

</div>

</body>
</html>

关于html - 现代网页设计中的CSS布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52142948/

相关文章:

javascript - 填充 HTML 元素时的断点

c# - 如何在最终生成的 pdf 文档中使用库 TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator 下载嵌入式图像?

android - 当使用绝对定位元素构建页面时,WebKit 似乎错误计算了窗口/主体大小,如何修复?

html - 将鼠标悬停在 HTML 上,元素下划线闪烁白色然后淡入红色

html - 面板标题中的边框底部在窗口缩小时不显示全宽

html - div 的文本内容没有 float 框

css - 为什么 `float:left` 不适用于固定宽度?

html - ION-LIST 左右填充不同内容

javascript - 使标签的首字母大写

CSS Float left, right, left, right... 全部到顶部