jsp中css float,CSS Float

CSS Float

You can "float" an element to the right or left so that other content flows around it.

The CSS float property enables you to determine where to position an element relative to the other elements on the page. When you use the float property, other elements will simply wrap around the element you applied the float to.

Float Left Example

In this example, we set a

element to float: left, which results in the rest of the content wrapping around it.

Note that I apply a margin to the right and bottom of the box, so that the rest of the content doesn't run right up against the box.

Run

Stack editor

Unstack editor

Example

.float-left {

float: left;

padding: 20px;

margin: 0 10px 10px 0;

background: gold;

}

Float left

This text rearranges itself to flow around the element that is floated left.

I added a margin to the right and bottom of the floated box so that this text doesn't run right up against it. Play around with the property values to see how it changes the layout.

Float Right Example

In this example, we set a

element to float: right, which results in the rest of the content wrapping around it.

In this case, I keep the bottom margin, but I move the right margin to the left of the box instead.

Run

Stack editor

Unstack editor

Example

.float-right {

float: right;

padding: 20px;

margin: 0 0 10px 10px;

background: gold;

}

Float right

This text rearranges itself to flow around the element that is floated right.

I added a margin to the left and bottom of the floated box so that this text doesn't run right up against it. Play around with the property values to see how it changes the layout.

Aligning Boxes Side by Side

Here we use float: left to align

elements side by side. Normally these elements would stack up on top of each other, but by using float: left, we can get them to display next to each other.

Run

Stack editor

Unstack editor

Example

div {

float: left;

padding: 20px;

}

.gold {

background: gold;

}

.limegreen {

background: limegreen;

}

.orange {

background: orange;

}

Gold

Limegreen

Orange

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值