CSS realizes the layout method of fixed left and adaptive right

CSS realizes the layout method of fixed left and adaptive right

1. Floating layout

1. Let the fixed width div float first! Take it out of the document flow.
2.The value of margin-left is equal to the width of the fixed div.

   .aside{
        float: left;
        width: 200px;
        background-color: red;
    }
    .content{
        margin-left: 200px;
        background-color: blue;
    }
    
<div class="aside">
    I have always been a very good person, and I have always been a very good person. I have always been a very good person, and I have always been a very good person.
</div>
<div class="content">
    I have always been a very good person, and I have always been a very good person. I have always been a very good person, and I have always been a very good person.
</div>

2. Negative value of margin (3 divs)

  1. The fixed width div is out of the document flow.
  2. Using negative marin values ​​can make the following divs be displayed in the same line as the previous divs.
  3. Adding margin-left to the div that wraps the content can prevent it from overlapping with the text on the left.
.aside{
    float: left;
    margin-right: -200px;
    width: 200px;
    background-color: red;
}
.content{
    float: right;
}
.content .inner{
    margin-left: 200px;
    background-color: blue;
}
<div class="aside">
I have always been a very good person, and I have always been a very good person. I have always been a very good person, and I have always been a very good person.
</div>
<div class="content">
<div class="inner">
I am a very good person, and I am very happy with my work. I am very happy with my work. I am very happy with my work. I am very happy with my work. I am very happy with my work. I am very happy with my work. I am very happy with my work.
</div>
</div>

3.calc() calculation properties

Note: When using calc to calculate properties, there must be spaces on both sides of the operator (- + etc.)

Note that the two divs must float left and right.

The width that must be subtracted from the calc width must be consistent with the fixed width.

.aside{

float: left;
width: 200px;
}
.content{

float: right;
calc:(100% - 200px);
}
<div class="aside"> 
I have always been a very good person, and I have always been a very good person. I have always been a very good person, and I have always been a very good person.
</div>
<div class="content">
I have always been a very good person, and I have always been a very good person. I have always been a very good person, and I have always been a very good person.
</div>

4.Flex layout

  1. You need to set the display: flex attribute for the parent div.
  2. For a fixed-width div, just set flex: 0 0 200px.
  3. Just write flex: 1 for the div in the content area.
body{
display: flex;
}
.aside{

flex: 0 0 200px;
background-color: red;
}
.content{

flex: 1;
background-color:blue;
}

<div class="aside">
I have always thought that the world is full of energy, but I have always thought that the world is full of energy. I have always thought that the world is full of energy, but I have always thought that the world is full of energy!
</div>
<div class="content">
I am a very good person, very good at dealing with things. I am a very good person, very good at dealing with things, very good at being a good person, very good at being a good person.
</div>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

<<:  JavaScript to achieve mouse drag effect

>>:  202 Free High Quality XHTML Templates (1)

Recommend

How to run py files directly in linux

1. First create the file (cd to the directory whe...

How to operate MySQL database with ORM model framework

What is ORM? ORM stands for Object Relational Map...

Using zabbix to monitor the ogg process (Linux platform)

The ogg process of a database produced some time ...

vue-router history mode server-side configuration process record

history route History mode refers to the mode of ...

Detailed explanation of grep and egrep commands in Linux

rep / egrep Syntax: grep [-cinvABC] 'word'...

Application and implementation of data cache mechanism for small programs

Mini Program Data Cache Related Knowledge Data ca...

Summary of MySQL common SQL statements including complex SQL queries

1. Complex SQL queries 1.1. Single table query (1...

Vue.js implements tab switching and color change operation explanation

When implementing this function, the method I bor...

Solution to Ubuntu not being able to connect to the Internet

Problem description: I used a desktop computer an...

Vue easily realizes watermark effect

Preface: Use watermark effect in vue project, you...

JavaScript implements asynchronous acquisition of form data

This article example shares the specific code for...

MySQL 5.7.17 installation and configuration tutorial under CentOS6.9

CentOS6.9 installs Mysql5.7 for your reference, t...

Detailed application of Vue dynamic form

Overview There are many form requirements in the ...