In "Pet's House," a virtual realm for pet enthusiasts, Alex, a web developer, embarks on a quest to revamp their service showcase using CSS Grid.
This lab aims to captivate users by presenting services in an organized, visually appealing manner. Alex's mission is to transform the "Display" section into a grid layout that highlights pet services with elegance and efficiency.
Skills Graph
%%%%{init: {'theme':'neutral'}}%%%%
flowchart RL
css(("`CSS`")) -.-> css/CoreLayoutGroup(["`Core Layout`"])
css(("`CSS`")) -.-> css/AdvancedLayoutGroup(["`Advanced Layout`"])
css/CoreLayoutGroup -.-> css/positioning("`Positioning`")
css/AdvancedLayoutGroup -.-> css/grid_layout("`Grid Layout`")
subgraph Lab Skills
css/positioning -.-> lab-289077{{"`Pet Service Showcase with CSS Grid`"}}
css/grid_layout -.-> lab-289077{{"`Pet Service Showcase with CSS Grid`"}}
end
Position Property
The CSS position property is a powerful tool that allows developers to control the exact placement of elements on a page. It enables elements to be positioned based on their normal flow, relative to their parent element, relative to the viewport, or relative to their nearest scrolling ancestor.
Static Positioning
static is the default value for all elements, meaning that elements are laid out according to the normal document flow. Static positioned elements are not affected by top, right, bottom, or left properties.
When you want elements to follow the standard flow, static positioning is your best choice.
For example, there is an image of a robot on the left side of the page, and if we set this element to position:static, then when we scroll the page, this image will also scroll with the page flow.
fixed positioning places an element relative to the browser window's viewport. The element will stay in the same place even if the page scrolls.
For making a navigation bar that is fixed at the top or bottom of the page.
For example, there is an image of a robot on the left side of the page, if we set this element to position:fixed, then when we scroll the page, this image will not disappear because of scrolling the page, the image will be in a fixed position.
relative positioning allows you to offset an element relative to its normal position. Even if offset, the element still occupies its original space.
When you need to slightly adjust the position of an element without affecting other parts of the layout.
For example, we moved the robot image on the left side of the page by a set number of pixels in the top and left directions relative to its normal position.
absolute positioning makes an element positioned relative to its nearest positioned ancestor if any, or otherwise relative to the initial containing block. It is removed from the document flow and does not occupy space.
When you need to create a floating element, such as a modal or dropdown menu.
In the previous lab, learning Flexbox, but the layout of the pet page, or not achieve the effect we want, so the next study another layout - Grid Layout.
CSS Grid Layout (Grid) is a grid-based layout system that allows developers to create responsive web page layouts. Grid can divide pages into major regions or define the layout of smaller components.
To use the Grid layout, you first need to set the display: grid; property on a container element.we can add the following to style.css:
In this lab, Alex successfully utilized CSS Grid to redesign the "Pet's House" display section, showcasing pet services in a structured, attractive grid layout. This approach not only improved the visual presentation but also demonstrated the flexibility and power of CSS Grid in web design.
We use cookies for a number of reasons, such as keeping the website reliable and secure, to improve your experience on our website and to see how you interact with it. By accepting, you agree to our use of such cookies. Privacy Policy