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

Detailed steps to install MySQL 8.0.27 in Linux 7.6 binary

Table of contents 1. Environmental Preparation 1....

VMware virtual machine to establish HTTP service steps analysis

1. Use xshell to connect to the virtual machine, ...

Implementation of debugging code through nginx reverse proxy

background Now the company's projects are dev...

JavaScript basics for loop and array

Table of contents Loop - for Basic use of for loo...

Vue3 (V) Details of integrating HTTP library axios

Table of contents 1. Install axios 2. Use of axio...

MySQL binlog opening steps

Binlog is a binary log file that is used to recor...

Detailed explanation of bash command usage

On Linux, bash is adopted as the standard, which ...

How to achieve centered layout in CSS layout

1. Set the parent container to a table and the ch...

How to modify the "Browse" button of the html form to upload files

Copy code The code is as follows: <!DOCTYPE HT...

Detailed explanation of Linux index node inode

1. Introduction to inode To understand inode, we ...

JavaScript to achieve balance digital scrolling effect

Table of contents 1. Implementation Background 2....

18 sets of exquisite Apple-style free icon materials to share

Apple Mug Icons and Extras HD StorageBox – add on...