页面布局

页面布局

高度已知左右固定中间自适应


  • float布局
    缺点:清除浮动的处理
    优点:兼容性好
<section class="layout float">
    <style>
      .layout.float .left-right-center div{
        height: 100px;
      }
      .layout.float .left{
        float: left;
        width: 200px;
        background: blue;
      }
      .layout.float .right{
        float: right;
        width: 200px;
        background: red;
      }
      .layout.float .center{
        background: green
      }
    </style>
    <article class="left-right-center">
        <div class="left"></div>
        <div class="right"></div>
        <div class="center">
          <h1>内容标题</h1>
          <p>主要内容</p>
        </div>
    </article>   
  </section>
  • 绝对定位
    缺点:下面子元素脱离文档流,有效性差
    优点:快捷
<section class="layout absolute">
    <style>
      .layout.absolute .left-center-right>div{
        position: absolute;   
        height: 100px;     
      }
      .layout.absolute .left{
        width: 200px;
        left: 0;
        background: blue;
      }
      .layout.absolute .right{
        right: 0;       
        width: 200px;
        background: red;
      }
      .layout.absolute .center{
        left: 200px;     
        right:200px;
        background: green
      }
    </style>
    <article class="left-center-right">
      <div class="left"></div>
      <div class="center">
          <h1>内容标题</h1>
          <p>主要内容</p>
      </div>
      <div class="right"></div>
    </article>
  </section>
  • flexbox
    解决上述两个缺点的,移动端很好的兼容
<section class="layout flex">
    <style>
      .layout.flex .left-center-right>div{
        height: 100px;
      }
      .layout.flex .left-center-right{
        display: flex;
      }
      .layout.flex .left{
        width: 200px;
        background: blue;
      }
      .layout.flex .right{     
        width: 200px;
        background: red;
      }
      .layout.flex .center{
        flex: 1;
      }
    </style>
    <article class="left-center-right">
      <div class="left"></div>
      <div class="center">
          <h1>内容标题</h1>
          <p>flex</p>
      </div>
      <div class="right"></div>
    </article>
  </section>
  • table
    优点:兼容性好
    缺点:一个单元格影响其他单元格
<section class="layout table">
    <style>
      .layout.table .left-center-right{
        display: table;
        width: 100%;
        height: 100px;
        
      }
      .layout.table .left-center-right>div{
        display: table-cell;
      }
      .layout.table .left{
        width: 200px;
        background: blue;
      }
      .layout.table .right{     
        width: 200px;
        background: red;
      }
      .layout.table .center{
        background: green;
      }
    </style>
    <article class="left-center-right">
      <div class="left"></div>
      <div class="center">
          <h1>内容标题</h1>
          表格
      </div>
      <div class="right"></div>
    </article>
  </section>
  • grid
    优点:各种复杂布局,代码简单
  <section class="layout grid">
    <style>
      .layout.grid .left-center-right{
        display: grid;
        width: 100%;
        grid-template-rows: 100px;
        grid-template-columns: 200px auto 200px;
      }
      .layout.grid .left{
        background: blue;
      }
      .layout.grid .right{     
        background: red;
      }
      .layout.grid .center{
        background: green;
      }
    </style>
    <article class="left-center-right">
      <div class="left"></div>
      <div class="center">
          <h1>内容标题</h1>
          网格
      </div>
      <div class="right"></div>
    </article>
  </section>
  • 双飞翼
    最后说一下双飞翼布局,也叫圣杯布局
<style>
		div{
			height: 100px;
		}
		.center-left-right .content{
			float: left;;
			background:red; 
			width: 100%;
		}
		.center-left-right .content .body{
			margin-left: 200px;
			margin-right: 120px;
		}
		.center-left-right .left{
			float: left;
			background: blue;
			width: 200px;
			margin-left: -100%
		}
		.center-left-right .right{
			float: left;
			background: yellow;
			width: 120px;
			margin-left: -120px;
		}
	</style>
	<article class="center-left-right">
		<div class="content">
			<div class="body">1234567890</div>
		</div>
		<div class="left"></div>
		<div class="right"></div>
	</article>

注意这里article会失去高度,解决办法使用伪元素

article.center-left-right:after {
    clear: both;
    display: block;
    content: '';
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Streamlit是一个用于创建数据应用程序的开源Python库,它非常适合快速原型设计和数据可视化。在Streamlit中,页面布局可以通过多种方式来创建,包括容器(`st.container`)、网格(`st.grid`)、卡片(`st.beta_expander`)和Markdown文本等。 以下是一些基本的布局元素: 1. **标题和标签**: - `st.title(text)`:设置页面标题。 - `st.subheader(text)`:设置子标题。 2. **容器**: - `st.container()`:创建一个水平或垂直的容器,可以添加多个组件。 ```python st.container([st.text('Element 1'), st.text('Element 2')]) ``` 3. **网格布局**: - `st.columns(n)`:创建一个n列的网格布局,其中n是一个整数。 ```python st.columns(2, [st.text('Column 1'), st.text('Column 2')]) ``` 4. **卡片(Expander)**: - `st.beta_expander(title, contents)`:创建一个可折叠的卡片,点击标题后显示内容。 ```python with st.beta_expander('Click to see more'): st.write('This is the content.') ``` 5. **Markdown**: - `st.markdown(text)`:使用Markdown语法编写文本,支持富文本格式。 ```python st.markdown('# My Heading') ``` 6. **分隔符**: - `st.empty()`:创建一个空白区域,可以用来分隔组件。 - `st.sidebar` 和 `st.beta_container`:创建侧边栏和独立的容器。 7. **响应式布局**: - `st.beta_expander(key='my_key')`:使用`key`参数来控制组件的缓存和重用,对于移动设备的响应式布局很有帮助。 要了解更多布局选项,你可以查阅官方文档:https://streamlit.io/docs/api
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值