Web page layout method, device and equipment and readable storage medium
By dynamically adjusting the web page layout and structure, combined with different screen width configurations in CSS and HTML files, it solves the problem of traditional layout design not performing well on different devices, achieving a good visual experience and simplified management on different devices.
Patent Information
- Application Number
- CN202410585204.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-13
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2044-05-13
AI Technical Summary
Traditional web page layout design is difficult to maintain good visual effects under different devices and screen sizes, resulting in disordered layout, incomplete display of elements, or excessively long page scroll bars, affecting user experience and increasing maintenance costs.
By obtaining the screen width size information of the current browser window, dynamically adjust the layout and structure of the web page, and use the page layout and structure corresponding to different screen widths in the pre-configured CSS files and HTML files to achieve the separation of style and structure, and Combine global and local variables to implement responsive design to adapt to different screen sizes.
Ensure that pages maintain consistent visual effects and user experience on different devices, simplify management and maintenance, improve code readability and reusability, and implement layout adjustments that respond to window size changes in real time.
Smart Images

Figure CN118535822A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of page layout, and in particular to a web page layout method, device, equipment and readable storage medium. Background Art
[0002] With the continuous development of the world wide web, web applications have become an indispensable part of people's daily life and work. However, different users use different types of devices and screen sizes, ranging from large desktop computers (PCs) to portable mobile phones and tablets. This makes the layout design of web pages face great challenges.
[0003] Traditional web page layout design often adopts a fixed width or fixed grid approach, which works well on certain devices and screen sizes, but may cause layout disorder, incomplete element display, or excessive page scroll bar on other devices. This not only affects the user experience, but also increases the maintenance cost of developers. Summary of the invention
[0004] The technical problem to be solved by the present invention is: how to ensure that a web page can present a good visual effect on various devices and screen sizes and achieve page adaptation.
[0005] The technical solution of the present invention to solve the above technical problems is as follows:
[0006] In a first aspect, the present application provides a web page layout method, which adopts the following technical solution:
[0007] A web page layout method, comprising:
[0008] Get the user's access request for the target web page on the current page;
[0009] In response to the access request, a target page layout and a target page structure corresponding to the target web page are determined according to the screen width size of the browser corresponding to the current page, a pre-configured CSS file and an HTML file, wherein the CSS file pre-configures page layouts corresponding to different screen width sizes, the HTML file pre-configures page structures corresponding to different screen width sizes, the page layout represents an arrangement and combination of various elements in the web page, and the page structure represents a hierarchical relationship of content in the web page;
[0010] According to the target page layout and the target page structure, the target web page is displayed on the current page through the browser.
[0011] The beneficial effects of the present invention are as follows: by obtaining the screen width size information of the current window of the browser, the target page layout and target page structure corresponding to the target web page are dynamically adjusted according to the screen size of the user device. According to the different screen sizes, the arrangement, size, spacing, etc. of the elements can be automatically adjusted so that the page can maintain consistent visual effects and user experience on different devices. By pre-configuring the page layout corresponding to different screen width sizes in the CSS file and pre-configuring the page structure corresponding to different screen width sizes in the HTML file, the separation of style and structure is achieved. This separation makes the style and content of the page easier to manage and maintain, and also improves the readability and reusability of the code.
[0012] Based on the above technical solution, the present invention can also be improved as follows.
[0013] Furthermore, the CSS file includes global variables, row attributes, column attributes, grid layout mode, preset response size and hidden classes of corresponding breakpoints corresponding to different screen width sizes; the HTML file includes element types, element attributes, element hierarchical relationships or local variables corresponding to different screen width sizes;
[0014] The global variables include the width of each row of the grid system, the number of grids in a row, the spacing between columns, the layout of rows, the layout of rows in flex layout mode, and the movement of columns;
[0015] The row attributes include the overall layout and style of the row;
[0016] The column attributes include the overall layout and style of the column;
[0017] The grid layout methods include common layout, mixed layout and responsive layout;
[0018] The preset response size and the hidden class of the corresponding breakpoint are grids corresponding to the class for hiding or showing specific elements according to the preset response size;
[0019] The element type represents the page structure corresponding to different screen width sizes;
[0020] The element attribute represents the appearance and response mode of the element corresponding to different screen width sizes, and the response mode represents the display attribute of the element;
[0021] The element hierarchical relationship represents the hierarchical relationship of elements corresponding to different screen width sizes in the corresponding page structure;
[0022] The local variables include the width of any one or more rows, the number of rows in the grid, the spacing between columns, the layout of rows, the layout of rows in flex layout mode, and the movement of columns.
[0023] The beneficial effects of adopting the above further scheme are: realizing basic layout by using a single row and column to create a basic layout, and freely combining the layout through the attributes of the column. Realizing mixed layout by arbitrarily expanding, combining and nesting the number of basic grids to form a more complex mixed layout. Realizing responsive layout by setting different values of preset responsive sizes and combining with breakpoint-based hidden classes to achieve free responsive layout.
[0024] By presetting the response size and the hidden class corresponding to the breakpoint, this method can achieve responsive design of the page. This means that when the browser window size changes, the page can automatically adjust the display and hiding of elements to adapt to different screen sizes.
[0025] Further, after displaying the target web page on the current page through the browser according to the target page layout and the target page structure, it also includes:
[0026] When the window size of the browser changes, reacquiring the screen width size of the browser corresponding to the current page to obtain a new screen width size;
[0027] Determine a new target page layout and a new target page structure corresponding to the current target web page according to the new screen width size, CSS file and HTML file;
[0028] According to the new target page layout and the new target page structure, the target web page is displayed on the current page through the browser.
[0029] The beneficial effect of adopting the above further solution is that by monitoring the browser window size change event, the page can perceive the user's operation of adjusting the browser window size in real time. Once the window size changes, the page will immediately re-acquire the new screen width size information, and based on this information, CSS files and HTML files, determine the new target page layout and new target page structure corresponding to the current target web page, and re-render and display the page according to the new target page structure and new target page layout. This enables the page to respond to changes in the window size in real time and always maintain the best layout effect.
[0030] Further, determining the target page layout and target page structure corresponding to the target web page according to the screen width size of the browser corresponding to the current page, the CSS file and the HTML file includes:
[0031] Detect whether there is a local variable in the HTML file;
[0032] If there are local variables in the HTML file, based on the preset priority of the local variables, the content in the local variables overwrites the corresponding content in the global variables to form new variable information;
[0033] Determine a target page layout corresponding to the target web page based on the screen width of the browser corresponding to the current page, the new variable information, the attributes of the row, the attributes of the column, the grid layout mode, the preset response size, and the hidden class of the corresponding breakpoint;
[0034] A target page structure corresponding to the target web page is determined based on the screen width size of the browser corresponding to the current page, the element type, the element attribute and the element hierarchical relationship.
[0035] The beneficial effect of adopting the above further scheme is that by defining local variables in the HTML file, the developer can customize certain parameters of the grid system according to the needs of the specific page. This allows the developer to more accurately control the number, width and other attributes of the grid, thereby achieving a more flexible and personalized page layout. The combination of global variables and local variables allows the developer to define a set of common grid system styles in the CSS file, and make local adjustments in the HTML file according to the needs of the specific page. This method not only ensures the uniformity of the style, but also simplifies the style maintenance process, because most styles only need to be updated in the CSS file, and the style of a specific page can be achieved by modifying the local variables in the HTML file.
[0036] Further, if no local variable is defined in the HTML file, determining the target page layout corresponding to the target web page according to the screen width size of the browser corresponding to the current page and the CSS file includes:
[0037] A target page layout corresponding to the target web page is determined based on the screen width size of the browser corresponding to the current page, the global variables, the attributes of the rows, the attributes of the columns, the grid layout mode, the preset response size, and the hidden class of the corresponding breakpoint.
[0038] The beneficial effect of adopting the above further solution is that if local variables do not need to be defined in the HTML file, its structure will be more concise and clear. This helps to reduce the amount of code and improve the readability and maintainability of the code. At the same time, it also reduces the risk of layout problems caused by incorrect local variable definition.
[0039] Further, displaying the target web page on the current page through the browser according to the target page layout and the target page structure includes:
[0040] Perform responsive breakpoint detection according to the screen width size of the browser corresponding to the current page and a preset responsive size to obtain a display level of the page layout;
[0041] Based on the display level, determining in the CSS file a grid hidden class and a grid size of the current page;
[0042] Based on the grid hidden class, the grid size, the target page layout and the target page structure, the elements to be displayed in each grid are rendered to display the target web page.
[0043] The beneficial effect of adopting the above further scheme is that by performing responsive breakpoint detection based on the screen width size information and the preset responsive size, the size range of the current browser window can be accurately determined, and the display level of the page layout can be determined accordingly. This enables the page to automatically adjust the layout and style according to different screen sizes, achieving more accurate responsive design. Based on the display level, the hidden class and grid size of the grid can be determined. This means that under different screen sizes, the page can flexibly hide or display specific grids, as well as adjust the size and spacing of the grid. This flexibility enables the page to better adapt to different devices and screen sizes, providing the best user experience.
[0044] Further, performing responsive breakpoint detection according to the screen width size of the browser corresponding to the current page and a preset response size to obtain a display level includes:
[0045] When the screen width size information is less than 768px, the display level of the current window of the browser is the first size level;
[0046] When the screen width size information is not less than 768px and less than 992px, the display level of the current window of the browser is the second size level;
[0047] When the screen width dimension information is not less than 992px and less than 1200px, the display level of the current window of the browser is the third size level;
[0048] When the screen width dimension information is not less than 1200px and less than 1920px, the display level of the current window of the browser is the fourth size level;
[0049] When the screen width size information is not less than 1920px, the display level of the current window of the browser is the fifth size level;
[0050] Among them, the screen width size information corresponding to the first size level is smaller than the screen width size information corresponding to the second size level, the screen width size information corresponding to the second size level is smaller than the screen width size information corresponding to the third size level, the screen width size information corresponding to the third size level is smaller than the screen width size information corresponding to the fourth size level, and the screen width size information corresponding to the fourth size level is smaller than the screen width size information corresponding to the fifth size level.
[0051] The beneficial effect of adopting the above further solution is that by adjusting the display level according to the screen size, the page layout and element size can be more closely matched to the user's device screen, providing better readability and operability. On devices of different sizes, users can get a comfortable and intuitive browsing experience.
[0052] In a second aspect, the present application provides a web page layout device, which adopts the following technical solution:
[0053] A web page layout device, characterized by comprising:
[0054] The acquisition module is used to obtain the user's access request for the target web page on the current page;
[0055] a response module, configured to respond to the access request and determine a target page layout and a target page structure corresponding to the target web page according to the screen width size of the browser corresponding to the current page, a pre-configured CSS file and an HTML file, wherein the CSS file pre-configures page layouts corresponding to different screen width sizes, the HTML file pre-configures page structures corresponding to different screen width sizes, the page layout represents an arrangement and combination of elements in the web page, and the page structure represents a hierarchical relationship of content in the web page;
[0056] The display module is used to display the target web page on the current page through the browser according to the target page layout and the target page structure.
[0057] The beneficial effects of the present invention are as follows: by obtaining the screen width size information of the current window of the browser, the target page layout and target page structure corresponding to the target web page are dynamically adjusted according to the screen size of the user device. According to the different screen sizes, the arrangement, size, spacing, etc. of the elements can be automatically adjusted so that the page can maintain consistent visual effects and user experience on different devices. By pre-configuring the page layout corresponding to different screen width sizes in the CSS file and pre-configuring the page structure corresponding to different screen width sizes in the HTML file, the separation of style and structure is achieved. This separation makes the style and content of the page easier to manage and maintain, and also improves the readability and reusability of the code.
[0058] In a third aspect, the present application provides an electronic device, which adopts the following technical solution:
[0059] An electronic device comprises a memory and a processor, wherein the memory stores a computer program that can be loaded by the processor and executes a web page layout method as described in any one of the first aspects.
[0060] In a fourth aspect, the present application provides a computer-readable storage medium, which adopts the following technical solution:
[0061] A computer-readable storage medium stores a computer program that can be loaded by a processor and executes a web page layout method as described in any one of the first aspects. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] Figure 1 A schematic diagram of a flow chart of a web page layout method of the present invention;
[0063] Figure 2 It is a structural block diagram of a web page layout device of the present invention;
[0064] Figure 3 The figure is a structural block diagram of an electronic device of the present invention. DETAILED DESCRIPTION
[0065] The present application is further described in detail below in conjunction with the accompanying drawings.
[0066] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0067] An embodiment of the present application provides a web page layout method based on HTML and CSS and executed by relying on CSS attribute selectors. The web page layout method can be executed by an electronic device, which can be a mobile terminal device. The mobile terminal device can be a laptop computer, a desktop computer, a mobile phone, a tablet computer, etc., but is not limited to this.
[0068] The following is a further detailed description of the embodiments of the present application in conjunction with the accompanying drawings. Figure 1 As shown,
[0069] Step S1, obtaining a user's access request for a target web page on the current page;
[0070] In the implementation mode of the present application, when a user clicks or triggers an operation (such as clicking a link, button, etc.) in the current page to access a target web page, the browser will send an HTTP request to the server. This request usually contains the URL that the user wants to access (i.e., the address of the target web page) and other related information, such as the request method (GET, POST, etc.), the request header (including the browser type, user agent, etc.) and possible request body (for POST requests).
[0071] Step S2, in response to the access request, determining a target page layout and a target page structure corresponding to the target web page according to the screen width size of the browser corresponding to the current page, a pre-configured CSS file and an HTML file, wherein the CSS file pre-configures page layouts corresponding to different screen width sizes, and the HTML file pre-configures page structures corresponding to different screen width sizes, the page layout represents the arrangement and combination of elements in the web page, and the page structure represents the hierarchical relationship of the content in the web page, the content hierarchical relationship refers to the logic and organizational structure between the page contents, the hierarchical relationship of the content in the page determines which content is the most important, which content is secondary, and the relationship and order between them, and the element is the basic component constituting the web page, and the element can be text, picture, video, link, button, etc.;
[0072] In the implementation manner of the present application, the screen width size information refers to data such as the width and pixel ratio of the page window currently visited by the user. Specifically, if the page is displayed in full screen of the user terminal, then the screen width size information of the page may include the screen resolution data of the user terminal; if the page is displayed in a browser, then the screen width size information of the page may include the resolution data of the browser window.
[0073] In the implementation manner of the present application, the CSS file includes global variables corresponding to different screen width sizes, row attributes, column attributes, grid layout methods, preset response sizes, and hidden classes corresponding to breakpoints.
[0074] Among them, the global variables of the grid system are set through the CSS selector, including: the default row width is 100% of the browser window, that is, the row will occupy the full width of its parent element. The number of grids in the row of the grid system defaults to 24 grids per row. The interval between columns in the grid system defaults to 0 pixels, that is, there is no interval between columns. The default layout mode of the row is block layout from left to right. The default layout mode of the row in flex layout mode is horizontal alignment and vertical alignment. The default column movement mode is the default number of columns to move the column to the right, and the default number of columns is 0.
[0075] Set the properties of the grid system row. The properties of the row are the overall layout and style of the row. Specifically, set --t:value in the style property of the row to specify the total number of grids in each row, that is, divide the row into value grids evenly, and the width of each grid is 1 / value, such as --t:24, the width of each grid is 1 / 24; set --g:value in the style property of the row to specify the spacing between columns, such as --g:10px, which specifies that the spacing between columns is 10 pixels; set --d:flex / block in the style property of the row to specify whether to flexibly align columns through flex layout; set --d:flex and --fh:value in the style property of the row to allow the horizontal arrangement of justify-content in the flex layout to be one of start / end / center / space-around / space-between; set --d:flex and --fv:value in the style property of the row to allow the vertical arrangement of align-content in the flex layout to be one of top / middle / bottom.
[0076] Set the properties of the grid system column. The properties of the column are the overall layout and style of the column. Specifically, set --s:value in the style property of the column to specify the number of grids occupied by this column. For example, if you set --t:24 in the style property of the row and --s:12 in the style property of the column, the total number of grids in each row is 24, and the width of the column is the width of 12 grids. Since the width of each grid is 1 / 24, the width of the column is 12 / 24;
[0077] In the style attribute of the column, the number of grid cells that the column occupies within the specified screen size is set according to the preset display level; in the style attribute of the column, --o:value is set to specify that the value of the current column offset to the right is realized by margin-left:value.
[0078] In the embodiment of the present application, five display levels are defined according to the preset response size. First, when the screen width size information is less than 768px, the display level of the current window of the browser is the first size level - xs;
[0079] Second, when the screen width size information is not less than 768px and less than 992px, the display level of the current window of the browser is the second size level - sm;
[0080] The third type, when the screen width size information is not less than 992px and less than 1200px, the display level of the current window of the browser is the third size level - md;
[0081] Fourth, when the screen width dimension information is not less than 1200px and less than 1920px, the display level of the current window of the browser is the fourth size level - lg;
[0082] Fifth, when the screen width dimension information is not less than 1920px, the display level of the current window of the browser is the fifth size level - xl.
[0083] Among them, the screen width size information corresponding to the first size level is smaller than the screen width size information corresponding to the second size level, the screen width size information corresponding to the second size level is smaller than the screen width size information corresponding to the third size level, the screen width size information corresponding to the third size level is smaller than the screen width size information corresponding to the fourth size level, and the screen width size information corresponding to the fourth size level is smaller than the screen width size information corresponding to the fifth size level.
[0084] Set the hidden class of the breakpoint corresponding to the preset response size. A series of CSS class names are defined based on the preset response size. For each size range, one or more breakpoints are set. These breakpoints are used to trigger style changes. When the screen size of the device reaches or exceeds a certain breakpoint, the hidden class corresponding to the breakpoint will be applied, thereby changing the display state of the element.
[0085] For example, some elements need to be hidden on devices with a screen size corresponding to the second size class, but need to be visible on devices with a screen size corresponding to the second size class. In this case, define a hidden class (such as .hide-on-small) and apply it to the elements that need to be hidden. Then, in CSS, use media queries to specify that when the screen size reaches medium screen and above, remove this hidden class and make the element visible.
[0086] In the implementation manner of the present application, the HTML file includes element types, element attributes, element hierarchical relationships or local variables corresponding to different screen width sizes.
[0087] The element type represents the page structure corresponding to different screen widths. The element types include: title elements (such as <h1> to< / h1> <h6>), falling elements (such as ), table elements (such as 、 and ), link elements (such as ), picture elements (such as ), form elements (such as <input> , <textarea> etc.) and container elements (such as< / textarea> 、 <section> 、 <article>wait).
[0088] Element attributes represent the appearance and responsiveness of elements according to different screen sizes. The responsiveness represents the display properties of elements. Display properties refer to how elements are scaled to fit the screen width, whether elements need to be hidden or displayed, etc., to fit the screen width. For example, through CSS media queries, we can set elements to automatically reduce or hide when the screen width is less than a certain value; when the screen width is greater than a certain value, elements are displayed or enlarged. This responsive design ensures that the page is well presented on different devices. Appearance includes colors, fonts, borders, and shadows.
[0089] The element hierarchy relationship represents the hierarchy relationship of elements corresponding to different screen width sizes in the corresponding page structure, and the element hierarchy relationship determines the relative positions between the elements.
[0090] The local variables include the width of any one or more rows, the number of rows in the grid, the spacing between columns, the layout of rows, the layout of rows in flex layout mode, and the movement of columns.
[0091] Specifically, determining the target page layout and target page structure corresponding to the target web page according to the screen width size of the browser corresponding to the current page, the CSS file and the HTML file includes:
[0092] Detect whether there is a local variable in the HTML file;
[0093] If there are local variables in the HTML file, based on the preset priority of the local variables, the content in the local variables overwrites the corresponding content in the global variables to form new variable information;
[0094] Determine a target page layout corresponding to the target web page based on the screen width of the browser corresponding to the current page, the new variable information, the attributes of the row, the attributes of the column, the grid layout mode, the preset response size, and the hidden class of the corresponding breakpoint;
[0095] A target page structure corresponding to the target web page is determined based on the screen width size of the browser corresponding to the current page, the element type, the element attribute and the element hierarchical relationship.
[0096] If no local variables are defined in the HTML file, the target page layout corresponding to the target web page is determined based on the screen width size of the browser corresponding to the current page, the global variables, the attributes of the rows, the attributes of the columns, the grid layout mode and the preset response size and the hidden class of the corresponding breakpoint.
[0097] By defining local variables in HTML files, developers can customize certain parameters of the grid system according to the needs of specific pages. This allows developers to more accurately control the number, width and other attributes of the grid, thereby achieving a more flexible and personalized page layout. The combination of global variables and local variables allows developers to define a set of common grid system styles in the CSS file, and make local adjustments in the HTML file according to the needs of specific pages. This method not only ensures the uniformity of the style, but also simplifies the style maintenance process, because most styles only need to be updated in the CSS file, and the style of a specific page can be achieved by modifying the local variables in the HTML file.
[0098] Step S3, displaying the target web page on the current page through the browser according to the target page layout and the target page structure.
[0099] In the implementation manner of the present application, step S3 includes:
[0100] Perform responsive breakpoint detection according to the screen width size of the browser corresponding to the current page and a preset responsive size to obtain a display level of the page layout;
[0101] Based on the display level, determining in the CSS file a grid hidden class and a grid size of the current page;
[0102] Based on the grid hidden class, the grid size, the target page layout and the target page structure, the elements to be displayed in each grid are rendered to display the target web page.
[0103] By using the JavaScript window.innerWidth property to obtain the width of the current browser window, the obtained screen width is compared with the preset breakpoint to determine the display level of the page layout corresponding to the current screen size. This allows the page to automatically adjust the layout and style according to different screen sizes to achieve more accurate responsive design. Based on the display level, the hidden class and grid size of the grid are determined. This means that under different screen sizes, the page can flexibly hide or display specific grids, as well as adjust the size and spacing of the grid. This flexibility allows the page to better adapt to different devices and screen sizes, providing the best user experience.
[0104] According to the display level and grid hidden class definition, use JavaScript or directly set the corresponding class in the HTML element to control the display or hiding of the grid.
[0105] Through CSS or JavaScript, the calculated grid size is applied to the corresponding grid elements, and the elements to be displayed (such as text, pictures, etc.) are placed in the corresponding grid through DOM operations or template engines. According to the grid system style and display level, other related style rules are applied, such as font size, color, alignment, etc. The browser draws and displays the web page according to the final DOM structure and style information.
[0106] As another optional implementation of the implementation of the present application, after displaying the target web page on the current page through the browser according to the target page layout and the target page structure, it also includes:
[0107] When the window size of the browser changes, reacquiring the screen width size of the browser corresponding to the current page to obtain a new screen width size;
[0108] Determine a new target page layout and a new target page structure corresponding to the current target web page according to the new screen width size, CSS file and HTML file;
[0109] According to the new target page layout and the new target page structure, the target web page is displayed on the current page through the browser.
[0110] By listening to the browser window size change event, the page can sense the user's operation of adjusting the browser window size in real time. Once the window size changes, the page will immediately re-acquire the new screen width size information, and determine the new target page layout and new target page structure corresponding to the current target web page based on the new screen width size, CSS file and HTML file, and re-render and display the page. This allows the page to respond to changes in window size in real time and always maintain the best layout effect.
[0111] This method obtains the screen width size information of the current browser window and dynamically adjusts the target page layout and target page structure corresponding to the target web page according to the screen size of the user's device. According to different screen sizes, the arrangement, size, spacing, etc. of elements can be automatically adjusted so that the page can maintain consistent visual effects and user experience on different devices. The page layout corresponding to different screen width sizes is pre-configured in the CSS file, and the page structure corresponding to different screen width sizes is pre-configured in the HTML file, so that the separation of style and structure is achieved. This separation makes the style and content of the page easier to manage and maintain, and also improves the readability and reusability of the code.
[0112] The procedure for the electronic device's browser to load the CSS file and HTML file is as follows:
[0113] Grid system "row" element settings:
[0114]
[0115] Grid system "column" element settings:
[0116] .col{
[0117] --s:var(--t);
[0118] width:calc(var(--w) / var(--t)*var(--s));
[0119] float:left;
[0120] margin-left:calc(var(--w) / var(--t)*var(--o));
[0121] padding-left:calc(var(--g) / 2);
[0122] padding-right:calc(var(--g) / 2);
[0123] }
[0124] Grid system has five grid level settings:
[0125] @media only screen and(max-width:767px){
[0126] .col[style~="--xs:"]{--s:var(--xs);}
[0127] }
[0128] @media only screen and (min-width: 768px) {
[0129] .col[style~="--sm:"] { --s: var(--sm);}
[0130] }}
[0131] @media only screen and (min-width: 992px) {
[0132] .col[style~="--md:"] { --s: var(--md);}
[0133] }}
[0134] @media only screen and (min-width: 1200px) {
[0135] .col[style~="--lg:"] { --s: var(--lg);}
[0136] }}
[0137] @media only screen and (min-width: 1920px) {
[0138] .col[style~="--xl:"] { --s: var(--xl);}
[0139] }}
[0140] Grid system hidden class settings:
[0141] @media only screen and (max-width: 767px) {
[0142] .hidden-xs-only { display: none!important;}
[0143] }}
[0144] @media only screen and (min-width: 768px) {
[0145] .hidden-sm-and-up { display: none!important;}
[0146] }}
[0147] @media only screen and(min-width:768px)and(max-width:991px){
[0148] .hidden-sm-only{display:none!important;}
[0149] }
[0150] @media only screen and(max-width:991px){
[0151] .hidden-sm-and-down{display:none!important;}
[0152] }
[0153] @media only screen and(min-width:992px){
[0154] .hidden-md-and-up{display:none!important;}
[0155] }
[0156] @media only screen and(min-width:992px)and(max-width:1199px){
[0157] .hidden-md-only{display:none!important;}
[0158] }
[0159] @media only screen and(max-width:1199px){
[0160] .hidden-md-and-down{display:none!important;}
[0161] }
[0162] @media only screen and(min-width:1200px){
[0163] .hidden-lg-and-up{display:none!important;}
[0164] }
[0165] @media only screen and(min-width:1200px)and(max-width:1919px){
[0166] .hidden-lg-only{display:none! important;}
[0167] }
[0168] @media only screen and(max-width:1919px){
[0169] .hidden-lg-and-down{display:none! important;}
[0170] }
[0171] @media only screen and(min-width:1920px){
[0172] .hidden-xl-only{display:none! important;}
[0173] }
[0174] Basic layout:
[0175]
[0176]
[0177] Hybrid layout:
[0178]
[0179] Responsive layout:
[0180] <div class="row"style="--t:24;--g:10px">
[0181] <div class="col hidden-xs-only"style="--xs:8;--sm:6;--md:4;--lg:3;--xl:1;"> content
[0182] <div class="col"style="--xs:4;--sm:6;--md:8;--lg:9;--xl:11;"> content
[0183] <div class="col"style="--xs:4;--sm:6;--md:8;--lg:9;--xl:11;"> content
[0184] <div class="col hidden-xs-only"style="--xs:8;--sm:6;--md:4;--lg:3;--xl:1;"> content
[0185] .
[0186] Figure 3 A structural block diagram of a web page layout device 200 is shown.
[0187] like Figure 3 As shown, a web page layout device 200 mainly includes:
[0188] The acquisition module 201 is used to acquire the user's access request for the target web page on the current page;
[0189] A response module 202 is used to respond to the access request and determine a target page layout and a target page structure corresponding to the target web page according to the screen width size of the browser corresponding to the current page, a pre-configured CSS file and an HTML file, wherein the CSS file pre-configures page layouts corresponding to different screen width sizes, and the HTML file pre-configures page structures corresponding to different screen width sizes, wherein the page layout represents the arrangement and combination of each element in the web page, and the page structure represents the hierarchical relationship of the content in the web page;
[0190] The display module 203 is used to display the target web page on the current page through the browser according to the target page layout and the target page structure.
[0191] Optionally, the CSS file includes global variables, row attributes, column attributes, grid layout mode, preset response sizes, and hidden classes of corresponding breakpoints corresponding to different screen width sizes; the HTML file includes element types, element attributes, element hierarchical relationships, or local variables corresponding to different screen width sizes;
[0192] The global variables include the width of each row of the grid system, the number of grids in a row, the spacing between columns, the layout of rows, the layout of rows in flex layout mode, and the movement of columns;
[0193] The row attributes include the overall layout and style of the row;
[0194] The column attributes include the overall layout and style of the column;
[0195] The grid layout methods include common layout, mixed layout and responsive layout;
[0196] The preset response size and the hidden class of the corresponding breakpoint are grids corresponding to the class for hiding or showing specific elements according to the preset response size;
[0197] The element type represents the page structure corresponding to different screen width sizes;
[0198] The element attributes represent the appearance and response mode of the element adjusted according to different screen sizes, and the response mode includes scaling, hiding and displaying the element;
[0199] The element hierarchical relationship represents the hierarchical relationship of elements corresponding to different screen width sizes in the corresponding page structure;
[0200] The local variables include the width of any one or more rows, the number of rows in the grid, the spacing between columns, the layout of rows, the layout of rows in flex layout mode, and the movement of columns.
[0201] Optionally, the web page layout device further includes a monitoring module, wherein the monitoring module is specifically used to:
[0202] After the target web page is displayed on the current page through the browser according to the target page layout and the target page structure, when the window size of the browser changes, the screen width size of the browser corresponding to the current page is reacquired to obtain a new screen width size;
[0203] Determine a new target page layout and a new target page structure corresponding to the current target web page according to the new screen width size, CSS file and HTML file;
[0204] According to the new target page layout and the new target page structure, the target web page is displayed on the current page through the browser.
[0205] Optionally, the response module 202 is specifically configured to:
[0206] Detect whether there is a local variable in the HTML file;
[0207] If there are local variables in the HTML file, based on the preset priority of the local variables, the content in the local variables overwrites the corresponding content in the global variables to form new variable information;
[0208] Determine a target page layout corresponding to the target web page based on the screen width of the browser corresponding to the current page, the new variable information, the attributes of the row, the attributes of the column, the grid layout mode, the preset response size, and the hidden class of the corresponding breakpoint;
[0209] A target page structure corresponding to the target web page is determined based on the screen width size of the browser corresponding to the current page, the element type, the element attribute and the element hierarchical relationship.
[0210] Optionally, the response module 202 is further specifically configured to:
[0211] If no local variables are defined in the HTML file, a target page layout corresponding to the target web page is determined based on the screen width size of the browser corresponding to the current page, the global variables, the attributes of the rows, the attributes of the columns, the grid layout mode, the preset response size, and the hidden class of the corresponding breakpoint.
[0212] Optionally, the display module includes:
[0213] The acquisition submodule is used to perform responsive breakpoint detection according to the screen width size of the browser corresponding to the current page and the preset response size, and obtain the display level of the page layout;
[0214] A determination submodule, used for determining the grid hidden class and grid size of the current page in the CSS file based on the display level;
[0215] The display submodule is used to render the elements to be displayed in each grid based on the grid hidden class, grid size, target page layout and target page structure, so as to display the target web page.
[0216] Optionally, get the submodule specifically for:
[0217] When the screen width size information is less than 768px, the display level of the current window of the browser is the first size level;
[0218] When the screen width size information is not less than 768px and less than 992px, the display level of the current window of the browser is the second size level;
[0219] When the screen width dimension information is not less than 992px and less than 1200px, the display level of the current window of the browser is the third size level;
[0220] When the screen width dimension information is not less than 1200px and less than 1920px, the display level of the current window of the browser is the fourth size level;
[0221] When the screen width size information is not less than 1920px, the display level of the current window of the browser is the fifth size level;
[0222] Among them, the screen width size information corresponding to the first size level is smaller than the screen width size information corresponding to the second size level, the screen width size information corresponding to the second size level is smaller than the screen width size information corresponding to the third size level, the screen width size information corresponding to the third size level is smaller than the screen width size information corresponding to the fourth size level, and the screen width size information corresponding to the fourth size level is smaller than the screen width size information corresponding to the fifth size level.
[0223] In one example, the module in any of the above devices can be one or more integrated circuits configured to implement the above methods, such as: one or more application specific integrated circuits (ASICs), or, one or more digital signal processors (DSPs), or, one or more field programmable gate arrays (FPGAs), or a combination of at least two of these integrated circuit forms.
[0224] For another example, when the modules in the device can be implemented in the form of a processing element scheduling program, the processing element can be a general-purpose processor, such as a central processing unit (CPU) or other processor that can call a program. For another example, these modules can be integrated together and implemented in the form of a system-on-a-chip (SOC).
[0225] Various objects such as various messages / information / equipment / network elements / systems / devices / actions / operations / processes / concepts that may appear in this application are named. It can be understood that these specific names do not constitute a limitation on the relevant objects. The names assigned may change with factors such as scenarios, contexts or usage habits. The understanding of the technical meaning of the technical terms in this application should be mainly determined from the functions and technical effects embodied / executed in the technical scheme.
[0226] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and modules described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0227] Those of ordinary skill in the art will appreciate that the modules and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0228] Figure 3 This is a structural block diagram of an electronic device 300 according to an embodiment of the present application.
[0229] like Figure 3 As shown, the electronic device 300 includes a processor 301 and a memory 302 , and may further include one or more of an information input / information output (I / O) interface 303 and a communication component 304 .
[0230] The processor 301 is used to control the overall operation of the electronic device 300 to complete all or part of the steps in the web page layout method described above; the memory 302 is used to store various types of data to support the operation of the electronic device 300, and these data may include, for example, instructions for any application or method operated on the electronic device 300, and application-related data. The memory 302 may be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0231] The I / O interface 303 provides an interface between the processor 301 and other interface modules, and the above-mentioned other interface modules can be keyboards, mice, buttons, etc. These buttons can be virtual buttons or physical buttons. The communication component 304 is used to test the wired or wireless communication between the electronic device 300 and other devices. Wireless communication, such as Wi-Fi, Bluetooth, Near Field Communication (NFC), 2G, 3G or 4G, or a combination of one or more of them, so the corresponding communication component 304 can include: Wi-Fi components, Bluetooth components, NFC components.
[0232] The communication bus 305 may include a path to transmit information between the above components. The communication bus 305 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. The communication bus 305 may be divided into an address bus, a data bus, a control bus, etc.
[0233] The electronic device 300 may include but is not limited to mobile terminals such as digital broadcast receivers, PDAs (personal digital assistants), PMPs (portable multimedia players), etc., and fixed terminals such as digital TVs, desktop computers, etc., and may also be servers, etc.
[0234] The computer-readable storage medium provided in the embodiments of the present application is introduced below. The computer-readable storage medium described below and the web page layout method described above can be referenced to each other.
[0235] The present application also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the above-mentioned web page layout method are implemented.
[0236] The computer-readable storage medium may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0237] The terms "comprises," "comprising," or any other variations thereof are intended to cover a non-exclusive inclusion such that a process, method, article, or apparatus that includes a list of elements includes not only those elements but also other elements not expressly listed, or also includes elements inherent to such process, method, article, or apparatus.
[0238] The above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of application involved in the present application is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the aforementioned application concept. For example, the above features are replaced with (but not limited to) technical features with similar functions applied in the present application.< / article> < / section> < / h6>
Claims
1. A web page layout method, characterized in that: include: Get the user's access request for the target web page on the current page; In response to the access request, determining a target page layout and a target page structure corresponding to the target web page based on the screen width of the browser corresponding to the current page, a pre-configured CSS file, and an HTML file, wherein the CSS file pre-configures page layouts corresponding to different screen widths, and the HTML file pre-configures page structures corresponding to different screen widths, the page layout representing an arrangement and combination of elements in the web page, and the page structure representing a hierarchical relationship of content in the web page; According to the target page layout and target page structure, the target web page is displayed on the current page through the browser.
2. A web page layout method according to claim 1, characterized in that: The CSS file includes global variables, row properties, column properties, grid layout mode, preset responsive sizes, and hidden classes corresponding to breakpoints corresponding to different screen widths; the HTML file includes element types, element properties, element hierarchical relationships, or local variables corresponding to different screen widths; The global variables include the width of each row of the grid system, the number of grid cells in a row, the spacing between columns, the layout of rows, the layout of rows in flex layout mode, and the movement of columns; The row attributes include the overall layout and style of the row; The column properties include the overall layout and style of the column; The grid layout methods include normal layout, mixed layout and responsive layout; The preset response size and the hidden class of the corresponding breakpoint are grids corresponding to the class of hiding or showing specific elements according to the preset response size; The element type represents the page structure corresponding to different screen width sizes; The element attributes represent the appearance and response mode of the element corresponding to different screen width sizes, and the response mode represents the display properties of the element; The element hierarchical relationship represents the hierarchical relationship of elements corresponding to different screen width sizes in the corresponding page structure; The local variables include the width of any row or rows, the number of rows in the grid, the spacing between columns, the layout of rows, the layout of rows in flex layout mode, and the movement of columns.
3. A web page layout method according to claim 1, characterized in that: After displaying the target web page on the current page through the browser according to the target page layout and the target page structure, the method further includes: When the window size of the browser changes, reacquiring the screen width size of the browser corresponding to the current page to obtain a new screen width size; Determine a new target page layout and a new target page structure corresponding to the current target web page according to the new screen width, CSS file, and HTML file; The target web page is displayed on the current page through the browser according to the new target page layout and the new target page structure.
4. A web page layout method according to claim 2, characterized in that: The determining of a target page layout and a target page structure corresponding to the target web page according to the screen width size of the browser corresponding to the current page, the CSS file, and the HTML file includes: Detect whether there is a local variable in the HTML file; If there are local variables in the HTML file, based on the preset priority of the local variables, the content of the local variables overwrites the corresponding content in the global variables to form new variable information; Determining a target page layout corresponding to the target web page based on the screen width of the browser corresponding to the current page, the new variable information, the attributes of the row, the attributes of the column, the grid layout mode, the preset responsive size, and the hidden class of the corresponding breakpoint; A target page structure corresponding to the target web page is determined based on the screen width of the browser corresponding to the current page, the element type, the element attribute, and the element hierarchical relationship.
5. A web page layout method according to claim 4, characterized in that: If no local variables are defined in the HTML file, determining a target page layout corresponding to the target web page according to the screen width size of the browser corresponding to the current page and the CSS file includes: A target page layout corresponding to the target web page is determined based on the screen width size of the browser corresponding to the current page, the global variable, the attributes of the row, the attributes of the column, the grid layout mode, the preset response size, and the hidden class of the corresponding breakpoint.
6. A web page layout method according to claim 4 or 5, characterized in that: The step of displaying the target web page on the current page through the browser according to the target page layout and the target page structure includes: Performing responsive breakpoint detection based on the screen width of the browser corresponding to the current page and a preset responsive size to obtain a display level of the page layout; Based on the display level, determining, in the CSS file, a grid hidden class and a grid size of the current page; Based on the grid hidden class, grid size, target page layout and target page structure, the elements to be displayed in each grid are rendered to realize display of the target web page.
7. A web page layout method according to claim 6, characterized in that: The step of performing responsive breakpoint detection based on the screen width of the browser corresponding to the current page and a preset responsive size to obtain a display level includes: When the screen width is less than 768px, the display level of the current browser window is the first size level; When the screen width is not less than 768px and less than 992px, the current window of the browser is displayed at the second size level. When the screen width is not less than 992px and less than 1200px, the current window of the browser is displayed at the third size level. When the screen width dimension information is not less than 1200px and less than 1920px, the display level of the current browser window is the fourth size level; When the screen width dimension information is not less than 1920px, the display level of the current browser window is the fifth size level; Among them, the screen width size information corresponding to the first size level is smaller than the screen width size information corresponding to the second size level, the screen width size information corresponding to the second size level is smaller than the screen width size information corresponding to the third size level, the screen width size information corresponding to the third size level is smaller than the screen width size information corresponding to the fourth size level, and the screen width size information corresponding to the fourth size level is smaller than the screen width size information corresponding to the fifth size level.
8. A web page layout device, characterized in that: include: The acquisition module is used to obtain the user's access request for the target web page on the current page; a response module, configured to, in response to the access request, determine a target page layout and a target page structure corresponding to the target web page based on the screen width of the browser corresponding to the current page, a pre-configured CSS file, and an HTML file, wherein the CSS file pre-configured page layouts corresponding to different screen widths, and the HTML file pre-configured page structures corresponding to different screen widths, the page layout representing the arrangement and combination of elements in the web page, and the page structure representing the hierarchical relationship of content in the web page; The display module is used to display the target web page on the current page through the browser according to the target page layout and target page structure.
9. An electronic device, characterized in that: comprising a processor coupled to a memory; The processor is configured to execute the computer program stored in the memory, so that the electronic device performs the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that The method comprises a computer program or an instruction, which, when executed on a computer, causes the computer to execute the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Html-based module encapsulation loading method
CN104102485A
CSS compatibility optimizing method and system
CN104537002A
Progressively enhanced responsive web design method
CN107291477A
Webpage response type display method and device based on Bootstrap framework
CN115705185A
Form page layout system and method
CN116382690A
Cited By
Grid-based cross-terminal responsive design system and method
CN118760420A
