圣杯布局应用

本文介绍了两种经典的前端布局解决方案——圣杯布局和双飞翼布局。圣杯布局利用外框的padding和元素的相对定位实现两侧固定宽度的内容区域,而双飞翼布局则将中心区域单独包裹,通过调整中心区域和侧边栏的margin实现相同效果。这两种方法都旨在解决页面中头部、主体和两侧栏的复杂布局问题。
摘要由CSDN通过智能技术生成

圣杯布局

**HTML**

```HTML

<div class="wrap">

<div class="center">中间</div>

<div class="left">左侧</div>

<div class="right">右侧</div>

</div>

```

**CSS**

```css

.wrap:after{

content:"";

display: block;

clear: both;

}

.wrap{

border:1px solid #000;

padding:0 200px;

min-width:200px;

}

.left,.center,.right{

float:left;

}

.left{

width:200px;

min-height:200px;

background-color: pink;

margin-left:-100%;

position: relative;

left:-200px;

}

.right{

width:200px;

min-height:200px;

background-color: skyblue;

margin-left:-200px;

position:relative;

left:200px;

}

.center{

width:100%;

min-height:200px;

background-color: yellowgreen;

}

```

#### 2.2、圣杯实现步骤

- 外框左右固定padding值,预留左侧列和右侧列的列宽

- .center宽度100%,.left,.right固定宽度

- 结构上.center,.left,.right依次浮动在一行排列

- 移动.left通过margin-left:-100%;配合相对定位position:relative;left:-200px;移动至左侧列位置

- 移动.right通过margin-left:-200px;配合相对定位position:relative;left:200px;移动至右侧列位置

### 3、双飞翼

**HTML**

```html

<div class="wrap">

<div class="centerbox">

<div class="center">中间</div>

</div>

<div class="left">左侧</div>

<div class="right">右侧</div>

</div>

```

**CSS**

```css

.wrap:after {

content: "";

display: block;

clear: both;

}

.wrap {

border: 1px solid #000;

min-width:600px;

}

.left,

.centerbox,

.right {

float: left;

}

.centerbox{

width:100%;

}

.left {

margin-left:-100%;

width: 200px;

min-height: 200px;

background-color: pink;

margin-left: -100%;

}

.right {

margin-left:-200px;

width: 200px;

min-height: 200px;

background-color: skyblue;

margin-left: -200px;

}

.center {

margin:0 200px;

min-height: 200px;

background-color: yellowgreen;

}

```

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值