MANAS BLOG
-----------------------------------------------------------------------------------
How to Create a Responsive Table with HTML, CSS, and a "View Details" Button
In this blog post, made by Manas, we'll walk through creating a responsive table using HTML and CSS. We'll explore how to set up the table, make it mobile-friendly, and enhance the design with styling techniques like hover effects and a call-to-action button. This table is designed to display basic data like No., Name, Age, and Year, and is styled with modern web design principles.
HTML Structure
The foundation of the table is built using HTML. Below is the HTML code that creates a simple table and the structure around it.
The DOCTYPE declaration defines the document type, and we specify UTF-8 encoding for compatibility with various characters. We also set the viewport to ensure the table looks great on different screen sizes, especially mobile.
The head section contains:
-
The title for the page. -
A favicon link (icon for the browser tab).
Styling with CSS
The majority of the styling is done within the <style>
tags, and we focus on making the table visually appealing and responsive.
Here’s a breakdown of the key sections of the CSS:
Body Styling
We start by setting a background color and using flexbox to center the content vertically and horizontally.
-
Background Color: A warm yellow/orange to create a vibrant, welcoming tone.
-
Flexbox Layout: The entire page uses flexbox for easy vertical centering.
-
Full Viewport Height: Ensures the body takes the entire height of the screen.
Table Wrapper Styling
This section makes sure the table is centered within a container that has some style, like borders and shadows, for added visual appeal.
-
Responsive Width: The table wrapper takes up 90% of the screen width, with a maximum of 600px to prevent it from becoming too wide on larger screens.
-
Box Shadow: Subtle shadow effect to create a card-like feel.
-
Overflow-X: Allows horizontal scrolling on smaller screens if the table overflows.
Table Styling
We focus on making the table look clean with borders, padding, and alternating row colors.
-
Table Width: The table is 100% wide within the wrapper.
-
Cell Padding: The cells have generous padding for better readability.
The hover effect on rows adds interactivity:
When a user hovers over a row, the background color changes to a light wheat shade, making the table feel more interactive.
Typography and Caption
The header and table caption are styled for clarity and to make the content more visually engaging.
The h1 header for the page is large and prominent. The table caption is centered, italicized, and colored with a soft gray to provide a gentle, subtle finish.
-----------------------------------------------------------------------------------------------------------------------------
Interactive "View Details" Button
To add an extra layer of interactivity, a "View Details" button is positioned in the center of the screen. When clicked, it links to Google (or any link you choose).
-
Button Design: The button is styled with a blue background and white text. It has rounded corners and a hover effect that changes the color and slightly scales the button up for emphasis.
-
Positioning: The button is absolutely positioned at the center of the screen, making it float over the content.
Mobile Responsiveness
The table and button design are made fully responsive through media queries. This ensures the table adapts to smaller screen sizes, such as tablets and mobile phones.
For Tablets and Smaller Laptops (max-width: 768px):
For Mobile Devices (max-width: 480px):
-
Text Size Adjustments: Font sizes decrease slightly on smaller screens.
-
Padding Adjustments: Cell padding is reduced to make better use of screen space.
Comments
Post a Comment