首页 > 其他分享 >写一个左中右的满屏布局,左右固定220px,中间自适应并且要优先加载

写一个左中右的满屏布局,左右固定220px,中间自适应并且要优先加载

时间:2024-12-09 09:13:30浏览次数:5  
标签:loading layout center 左中右 满屏 content 220px right left

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Left-Center-Right Layout</title>
    <style>
        body, html {
            margin: 0;
            padding: 0;
            height: 100%;
            width: 100%;
        }
        .container {
            display: flex;
            height: 100%;
        }
        .left, .right {
            width: 220px;
            background-color: #f0f0f0; /* Example background color */
        }
        .center {
            flex: 1; /* This makes the center div take up the remaining space */
            background-color: #ffffff; /* Example background color */
        }



    </style>
</head>
<body>

<div class="container">
    <div class="left">Left Content</div>
    <div class="center">Center Content (Loads First)</div>
    <div class="right">Right Content</div>
</div>

</body>
</html>

Explanation and Key Improvements for Prioritized Loading:

  • Flexbox for Layout: The display: flex on the container and flex: 1 on the center element make this layout clean and easy to manage. Flexbox handles the sizing and distribution efficiently.
  • No float or position: absolute: This avoids common layout pitfalls and makes the layout more robust.
  • HTML Structure for Prioritized Loading: The order of elements in the HTML influences loading priority. Placing the center content (<div class="center">) before the left and right divs encourages the browser to render it sooner. While not a guaranteed solution, it generally leads to the center content appearing first, especially if the left/right content involves more complex rendering or external resource loading (images, etc.).
  • Full Height: height: 100% on the body, html, and .container ensures the layout stretches to the full browser height.
  • Clearer Styling: Using clearer background colors helps visualize the layout sections during development.

Further Optimization for Loading:

While the above structure helps, for even more control over loading, consider these techniques:

  • Lazy Loading for Left/Right: If the left and right content is image-heavy or contains a lot of data, use lazy loading techniques (Intersection Observer API or JavaScript libraries) to defer their loading until they are about to scroll into view. This significantly improves initial page load time.
  • Asynchronous JavaScript: Ensure any JavaScript related to the left or right columns is loaded asynchronously (using <script async> or <script defer>) so it doesn't block the rendering of the center content.
  • Resource Hints: Use <link rel="preload"> or <link rel="prefetch"> to give the browser hints about resources it should prioritize loading. For example, if the center content relies on a specific CSS file or font, preloading those resources can further improve perceived performance.

By combining these HTML structure adjustments with performance optimization techniques, you can create a left-center-right layout that prioritizes the loading and display of the center content effectively.

标签:loading,layout,center,左中右,满屏,content,220px,right,left
From: https://www.cnblogs.com/ai888/p/18594170

相关文章

  • 自动引入神器unplugin-auto-import,和满屏的import说拜拜
    目录简介功能安装在Vite中使用在Webpack中使用配置选项简介unplugin-auto-import是一个现代的自动导入插件,它支持多种构建工具(例如Vite和Webpack),可以根据你在代码中使用的标识符自动生成相应的import语句,从而减少重复代码,简化开发过程。官方仓库功能自动导入常用库的API......
  • Typora 1.0.3 markdown 满屏显示,去除两边的留白
    Typora宽度在CSS样式文件中有个max-width值,现在的显示器分辨率比较高,会导致编辑器两边留白比较多导致文档编辑时,高分辨率的显示器,得不到充分利用解决方案查看不要直接去安装目录下修改,实际目录可能会不一样......
  • uni-app 组件 uview u-action-sheet 项太多,占满屏幕,设置滚动
    找到文件/uni_modules/uview-ui/components/u-action-sheet/u-action-sheet.vue找到u-action-sheet__item-wrap的类名<viewclass="u-action-sheet__item-wrap">修改成<scroll-viewclass="u-action-sheet__item-wrap"scroll-ystyle=&......
  • Typora markdown 满屏显示,去除两边的留白
    Typora宽度在CSS样式文件中有个max-width值,现在的显示器分辨率比较高,会导致编辑器两边留白比较多导致文档编辑时,高分辨率的显示器,得不到充分利用解决方案修改源码编辑器样式Typora安装目录下找到base_control.css文件,复制一份备份打开文件后查找typora-source下的m......
  • el-aside无法铺满屏幕
    第一步:在App.vue中写入样式<stylescoped>#app{position:absolute;top:0;left:0;width:100%;height:100%;}</style>第二步:调节el-aside样式(注意如果没有背景色的话,看起来还是没有铺满)<stylescoped>.el-aside{height:100vh;}</style>第三步:第二步的......
  • 别再满屏找日志了!推荐一款 IDEA 日志管理插件,看日志轻松多了!
    1.简介GrepConsole是一款方便开发者对idea控制台输出日志进行个性化管理的插件。2.功能特性GrepConsole的主要功能特性:支持自定义规则来过滤日志信息;支持不同级别的日志的输出样式的个性化配置;总结:通过过滤功能、输出日志样式配置功能,可以更方便开发者在大量的日志信......
  • 写一个左中右布局占满屏幕,其中左右两块是苦丁宽200px,中间自适应宽,要求先加载中间块。
    <htmllang="en"><body><divclass="container"><divclass="main">中间</div><divclass="left">左边</div><divclass=......
  • python 字符串 格式化输出 槽格式 左中右对齐的内容
    """槽的格式限定冒号:左边填序号或名称,右边填写格式"""#右对齐的字符串,宽度为20s1="{:>20}".format("hello")print(s1)#右对齐,宽20,!填充s2="{:!>20}".format("python")p......
  • Css实现DIV铺满屏幕的几种方法
    1.第一种方式div{/*div的CSS样式*/position:absolute;width:100%;height:100%;}*{/*CSSReset*/margin:0;padding......
  • 利用snowfall.jquery.js实现满屏爱心表白代码
    利用snowfall.jquery.js实现满屏爱心表白代码一、效果展示二、代码分析第一步:利用伪元素before和:after画两个重叠在一起的长方形,如图所示:<!DOCTYPEhtml><html><head>......