Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set the div offset to the right in css

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to set div offset to the right in css". The explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to set div to the right in css".

Div offset to the right at a certain interval, you can adopt the margin outer margin, or you can use padding to do it, which depends on how sharp the difference is. Here CSS5 introduces all kinds of css organs div to the right for everyone.

The former is a blue div and the latter is a blood div. In this kind of environment, how to flexibly let the blood div float to the right is not necessarily spaced.

Gentile states that:

In order to facilitate the example, the two boxes are side by side, we set float floating in both div, and the equipment is similar in width and height in both div box.

1. Configure margin-left to move div to the right

1. In the environment with frame or background color

Both div set the equipment float:left organization to the left css pattern, to move the second (red) div a little to the right, usually set the margin-left for the second (red) div.

2. Move the code to the right to configure div:

The div moves to the right not necessarily from the instance css5.com.cn.box-a,.box-b {width:200px;height:100px; float:left}. Box-a {border:1px solid # 00F} .box-b {border:1px solid # F00} first (former) div second (latter) div

3. Screenshot

Set div to move to the right before

4. Monopoly equipment installation second div left outside isolation distance pattern

Hub CSS code:

.box-a,.box-b {width:200px;height:100px; float:left} .box-a {border:1px solid # 00F} .box-b {border:1px solid # F00; margin-left:20px}

Screenshot

Set up the equipment margin-left to complete the blood div shift to the right a certain isolation distance

Second, using margin-right to make the second div fire to the right may not be at an interval.

1. Instructions for use

The previous method is to directly move the div to the right to set the equipment margin-left itself to the left, so as to realize the div itself to move to the right.

If you use margin-right, you can not move the div setting to the right of the demand, but set the equipment for the former (blue div). It may not be cut off to complete the right shift of the red div.

2. CSS code:

. box-a,.box-b {width:200px;height:100px; float:left}. Box-a {border:1px solid # 00F

3. Screenshot:

Margin-right completes moving div box to the right

By setting the outer right distance of the margin-right to the blue div, how to make the red naturally depend on the blue div at a certain interval, so as to complete the right shift of the div.

Third, use padding-left to set the equipment div to the right and set the distance.

To move the div to the right to set up the equipment padding-left, there is a premise that the div does not have a frame and the setting of the div itself and the external color aid of the div are not discriminated, how to rely on the left margin of the padding-left to complete the div does not move to the right, the mode moves to the right, it looks like the same result of the div shift to the right.

1. Link CSS code

. box-a,.box-b {width:200px;height:100px; float:left}. Box-a {border:1px solid # 00F}. Box-b {padding-left:20px}

2. Screenshot

Thank you for reading, the above is the content of "how to set div offset to the right in css". After the study of this article, I believe you have a deeper understanding of how to set div offset to the right in css, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report