list and grid layout switch demo based on Bootstrap



Two types of popular responsive layout:list layout and grid layout, which are based on Bootstrap with jQuery to switch.

Step1:

link the bootstrap css
<!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
link the font-awesome for icon if you want
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
head

link the jquery in the bottom of body
 <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <!-- Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
body bottom

Step2:
Html contains two parts: btn-wrapper and products
html
The btn-wrapper contains two linked buttons with icon classed fa.
Every image and paragraph wrapped in the div named item.

css
The grid style is basic , so the point is how to style the list-group-item.

Goals:
list-group-item should be in a line each, so width should be 100%.
Both image and paragraph should be in the box , so display should be table to make it fit.
To splendid the site, hovering the list adds the background color.

Step3:
js
When click each button, the different function should be lauched.
With the addClass and removeClass to show different styles.





Popular posts from this blog

Fancyapps — easily build overlay windows with carousel

Meet Tippy.js: The Complete Tooltip Popover Plugin

Meet Mantine: A TS-Based Open-Source React Components Library