CSS solves the misalignment problem of inline-block

CSS solves the misalignment problem of inline-block

No more nonsense, post code

HTML part

<div class="positionleft">I am on the left side of the position method, accounting for 30%</div>
        <div class="positionright">I am on the right side of the position method, accounting for 70%</div>

CSS part

 .positionleft {
           position: relative;
           display: inline-block;
           background-color: #8d8d8d;
           width: 30%;
           height: 20%;

       }
       .positionright {
           position: relative;
           display: inline-block;
           left: 0;
           background-color: #ff8888;
           width: 70%;
           height: 20%;
       }

Display Effect

insert image description here

It can be clearly seen that the two div blocks are misaligned. After consulting the information, it is found that this phenomenon occurs when there is a space between the two inline-blocks.

Modify the html code as follows

<div class="positionleft">I am on the left side of the position method, accounting for 30%</div> <div class="positionright">I am on the right side of the position method, accounting for 70%
</div>

Just delete the space between the two divs and see the effect.

insert image description here

Problem Solving

Please pay attention to this problem when using document formatting tools such as prettier

Summarize

This is the end of this article about how to solve the misalignment problem of inline-block with CSS. For more relevant CSS inline-block misalignment content, please search 123WORDPRESS.COM’s previous articles or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

<<:  JS cross-domain XML--with AS URLLoader

>>:  Detailed explanation of anonymous slots and named slots in Vue

Recommend

js to realize a simple disc clock

This article shares the specific code of js to im...

Nginx dynamic and static separation implementation case code analysis

Separation of static and dynamic Dynamic requests...

mysql indexof function usage instructions

As shown below: LOCATE(substr,str) Returns the fi...

A brief discussion on the lazy loading attribute pattern in JavaScript

Table of contents 1. Introduction 2. On-demand at...

Learn how to write neat and standard HTML tags

Good HTML code is the foundation of a beautiful w...

Implementing the preview function of multiple image uploads based on HTML

I recently wrote a script for uploading multiple ...

Detailed explanation of Docker Swarm service orchestration commands

1. Introduction Docker has an orchestration tool ...

JavaScript to implement the back to top button

This article shares the specific code for JavaScr...

Table related arrangement and Javascript operation table, tr, td

Table property settings that work well: Copy code ...

Specific use of MySQL internal temporary tables

Table of contents UNION Table initialization Exec...

How to implement checkbox & radio alignment

Not only do different browsers behave differently...

MySQL max_allowed_packet setting

max_allowed_packet is a parameter in MySQL that i...