Code Monkey home page Code Monkey logo

Comments (3)

MMmaXingXing avatar MMmaXingXing commented on June 22, 2024

BFC实现

<body>
    <div class='content'>
        <div class="left"></div>
        <div class="right"></div>
    </div>
</body>

<style>
.content {
  overflow: hidden;
  width: 100%;
  border: 1px solid pink;
}
.left {
  float: left;
  width: 100px;
  height: 100px;
  border: 1px solid #000;
}
.right {
  height: 100px;
  border: 1px solid red;
}
</style>

Flex实现

<body>
    <div class='content'>
        <div class="left"></div>
        <div class="right"></div>
    </div>
</body>

<style>
.content {
  display: flex;
  border: 1px solid pink;
}
.left {
  width: 100px;
  height: 100px;
  border: 1px solid #000;
}
.right {
  flex: 1;
  height: 100px;
  border: 1px solid red;
}
</style>

float 布局

<body>
    <div class='content'>
        <div class="left"></div>
        <div class="right"></div>
    </div>
</body>

<style>
.content {
  width: 100%;
  border: 1px solid pink;
}
.left {
  width: 100px;
  height: 100px;
  float: left;
  background: blue;
}
.right {
  width: 100%;
  background: red;
  height: 100px;
}
</style>

calc 布局

<body>
    <div class='content'>
        <div class="left"></div>
        <div class="right"></div>
    </div>
</body>

<style>
* {
  margin: 0;
  padding: 0;
  font-size: 0;
}
.content {
  width: 100%;
  border: 1px solid pink;
}
.left {
  width: 100px;
  height: 100px;
  display: inline-block;
  background: blue;
}
.right {
  width: calc(100% - 100px);
  background: red;
  display: inline-block;
  height: 100px;
}
</style>

from daily.

GenXiaoLe avatar GenXiaoLe commented on June 22, 2024

position布局

<body>
    <div class='outside'>
        <div class="left"></div>
        <div class="right"></div>
    </div>
</body>

<style>
.outside {
  width: 100%;
  height: 300px;
  position: relative;
}
.left {
  width: 100px;
  height: 100%;
  background: blue;
}
.right {
  position: absolute;
  left: 100px;
  right: 0;
  top: 0;
  bottom: 0;
  background: red;
}
</style>

from daily.

lamelamb avatar lamelamb commented on June 22, 2024

也可以使用margin 为负值实现

from daily.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.