Its required to create a mobile responsive card menu like this using HTML & CSS:
**
Requirement
**
required design
But the outcome was like the below. The text are going all over,cards aren't centered,and changes the position from device to device:
actual outcome
**
My coding
**
<section id="edu-coursecategory-section" class="ed-coursecategory layout-2">
<style>
* {
box-sizing: border-box;
}
/* Float four columns side by side */
.columncat {
float: left;
width: 25%;
padding: 0 10px;
}
/* Remove extra left and right margins, due to padding */
.row {margin: 0 -5px;}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/* Style the counter cards */
.cardcat {
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
padding: 16px;
text-align: center;
background-color: #f1f1f1;
width: 80px;
height: 80px;
margin-left: 50%;
font-size: 50%;
}
}
#media screen and (min-width: 780px) {
.ed-coursecategory layout-2 , .isotop-active, .ed-courses layout-2{
display:box;
}
.columncat{
display:none ;
}
}
#media screen and (max-width: 781px) {
.ed-coursecategory layout-2, .isotop-active, .ed-courses layout-2{
display:none;
}
.columncat{
width: auto;
display: box;
margin-bottom: 20px;
}
}
</style>
<div class="row">
<div class="columncat">
<div class="cardcat">
<h3>Technology</h3>
</div>
</div>
<div class="columncat">
<div class="cardcat">
<h3>Science</h3>
</div>
</div>
<div class="columncat">
<div class="cardcat">
<h3>Math</h3>
</div>
</div>
<div class="columncat">
<div class="cardcat">
<h3>Health & Lifestyle</h3>
</div>
</div>
<div class="columncat">
<div class="cardcat">
<h3>Language</h3>
</div>
</div>
</div>
</section>
Appreciate if you could support me to achieve the required design.
Related
for a small codeing project in codehs.com I have separate containers some labeled image some with actual images however i cannot figure out how to scale proportionally with size of webpage
here is the code for my project:
index.html
* {
box-sizing: border-box;
}
body {
font-family: Arial;
padding: 10px;
background-image: url(https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSYY0m5M4elle5s14mIhUSPJQJNXWE626vaxJfyLMp-t5aQYsuS8fDBTApBr1bvM6Yu4L4:https://files.123freevectors.com/wp-content/original/110787-dark-color-blurred-background-vector.jpg&usqp=CAU);
background-size: cover;
}
/* Header/Blog Title */
.header {
padding: 30px;
text-align: center;
background: white;
}
.header h1 {
font-size: 50px;
}
/* Style the top navigation bar */
.topnav {
overflow: hidden;
background-color: #333;
}
/* Style the topnav links */
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
/* Change color on hover */
.topnav a:hover {
background-color: #ddd;
color: black;
}
/* Create two unequal columns that floats next to each other */
/* Left column */
.leftcolumn {
float: left;
width: 75%;
}
/* Right column */
.rightcolumn {
float: right;
width: 25%;
padding-left: 20px;
}
/* Fake image */
.fakeimg {
background-color: #aaa;
width: 100%;
padding: 20px;
}
#first3dp {
background-image: url("https://i.all3dp.com/wp-content/uploads/2021/01/21134921/Lead.jpg");
background-size: cover;
}
/* Add a card effect for articles */
.card {
background-color: white;
padding: 20px;
margin-top: 20px;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
/* Footer */
.footer {
padding: 20px;
text-align: center;
background: #ddd;
margin-top: 20px;
}
/* Responsive layout - when the screen is less than 800px wide, make the two columns stack on top of each other instead of next to each other */
#media screen and (max-width: 800px) {
.leftcolumn,
.rightcolumn {
width: 100%;
padding: 0;
}
}
/* Responsive layout - when the screen is less than 400px wide, make the navigation links stack on top of each other instead of next to each other */
#media screen and (max-width: 400px) {
.topnav a {
float: none;
width: 100%;
}
}
<div class="header">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSzbKAzXZFQY6Sf3Jkfh_f8XPYJSMt1vHb5ZYCj4IjghC6Ue-cKiUAg78vx09asJCYmiw:https://www.fbla-pbl.org/media/2022/09/FBLA_HorizontalLogo_cropped-01.png&usqp=CAU">
<h1>Alex's 3D Printing Journey</h1>
<p></p>
</div>
<div class="topnav">
Link
Link
Link
Contact me
</div>
<div class="row">
<div class="leftcolumn">
<div class="card">
<h2>Where it started!</h2>
<h5>sometime, 2020</h5>
<div class="fakeimg" id="first3dp" style="height:200px;"> </div>
<p>Some text..</p>
<p></p>
</div>
<!--<img src="https://i.all3dp.com/wp-content/uploads/2021/01/21134921/Lead.jpg"> -->
<div class="card">
<h2>TITLE HEADING</h2>
<h5>Title description, Sep 2, 2022</h5>
<div class="fakeimg" style="height:200px;">Image</div>
<p>Some text..</p>
<p></p>
</div>
</div>
<div class="rightcolumn">
<div class="card">
<h2>About Us</h2>
<div class="fakeimg" style="height:100px;">Image</div>
<p>text...</p>
</div>
<div class="card">
<h3>Popular Post</h3>
<div class="fakeimg">
<p>Image</p>
</div>
<div class="fakeimg">
<p>Image</p>
</div>
<div class="fakeimg">
<p>Image</p>
</div>
</div>
<div class="card">
<h3>Follow Us</h3>
<p>Some text.. can use embed with social media links</p>
</div>
</div>
</div>
<div class="footer">
<h2>Footer</h2>
<h2>Footer to include credits to website creators and copyright information</h2>
</div>
use of background-size: cover;
in the id #first3dp on style.css however it did fit it to the container it did not scale proportionally with the container rather resizing the image kicking it off screen
your need to add the background-position property is you want a specific position when using background images in CSS.. add this code I also fixed your header which was overflowing.
.header > *{
width: 100%;
}
#first3dp {
background-image: url("https://i.all3dp.com/wp-content/uploads/2021/01/21134921/Lead.jpg");
background-size: 100% 100%;
}
On the header img use max-width: 100%;
I have this html and css layout. I want to make it when reaching tablet with media query and phone to show like in those 2 images. So I have in normal (desktop mode) 4 products all of them in the same line. When the view reaches tablet - 1199 pixels I want those 4 products to be each 2 on a separate line, so 2 lines with 2 products. On the phone mode 768 pixels I want each product to be on its line with the width full like the wrapper.
Here is the code :
body {
margin: 0px;
padding: 0px;
}
/* Header */
.header {
background-color: yellow;
width: 100%;
margin: 0 auto;
}
.wrapper {
max-width: 1200px;
margin: 0 auto;
}
.logo {
background-color: grey;
width: 150px;
height: 50px;
margin-top: 20px;
float: left;
}
.info {
background-color: grey;
width: 285px;
height: 50px;
margin-top: 20px;
float: right;
}
.clear {
clear: both;
}
.menu {
background-color: grey;
width: 1200px;
height: 50px;
margin-top: 20px;
}
/* */
/* Nav-Bar */
.nav-bar {
background-color: lightgray;
width: 1200px;
height: 340px;
margin-top: 20px;
}
/* */
/* Product grid */
.product1,
.product2,
.product3 {
background-color: lightgray;
width: 285px;
height: 320px;
margin-top: 20px;
margin-right: 20px;
float: left;
}
.product4 {
background-color: lightgray;
width: 285px;
height: 320px;
margin-top: 20px;
float: left;
}
/* */
/* Bottom Part */
.content-area {
background-color: lightgray;
width: 100%;
height: 420px;
margin-top: 20px;
}
/* */
/* Footer */
.footer-area {
background-color: gray;
width: 100%;
height: 50px;
margin-top: 20px;
}
/* */
/* Responsive */
#media screen and (max-width: 1199px) {
.product1,
.product2,
.product3,
.product4 {
display: none;
}
}
<!DOCTYPE html>
<html>
<head>
<title>Home View</title>
<link rel="stylesheet" type="text/css" href="../style/homestyle.css">
</head>
<body>
<!-- Header -->
<div class="header">
<div class="wrapper">
<div class="logo"></div>
<div class="info"></div>
<div class="clear"></div>
<div class="menu"></div>
</div>
</div>
<!-- -->
<!-- NavBar -->
<div class="header">
<div class="wrapper">
<div class="nav-bar"></div>
<div class="clear"></div>
</div>
</div>
<!-- -->
<!-- Product Grid -->
<div class="wrapper">
<div class="def1">
<div class="product1"></div>
</div>
<div class="def2">
<div class="product2"></div>
</div>
<div class="def3">
<div class="product3"></div>
</div>
<div class="def4">
<div class="product4"></div>
</div>
<div class="clear"></div>
</div>
<!-- -->
<!-- Bottom Part -->
<div class="wrapper">
<div class="content-area"></div>
</div>
<!-- Footer -->
<div class="header">
<div class="wrapper">
<div class="footer-area"></div>
</div>
</div>
</body>
</html>
The CSSTablet :
I attached the images needed for the layout. Please help!
First you add the view port element to Head of the HTML page.
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Ref. link - https://www.w3schools.com/css/css_rwd_viewport.asp
Then Remove fixed width's from .menu and .nav-bar classes and add as max-width.
.menu {
background-color: grey;
max-width: 1200px;
height: 50px;
margin-top: 20px;
}
.nav-bar {
background-color: lightgray;
max-width: 1200px;
height: 340px;
margin-top: 20px;
}
And also you need to wrap your "Product slots" using "div".
(I used class called "wrapper-inner")
<!-- Product Grid -->
<div class="wrapper">
<div class="wrapper-inner">
<div class="def1">
<div class="product1"></div>
</div>
<div class="def2">
<div class="product2"></div>
</div>
<div class="def3">
<div class="product3"></div>
</div>
<div class="def4">
<div class="product4"></div>
</div>
<div class="clear"></div>
</div>
</div>
<!-- -->
Then after you can add required CSS media queries.
/* Responsive */
#media all and (max-width: 1199px) {
.wrapper-inner {
margin: 0 -20px;
background: orange;
padding: 0 20px;
}
.def1, .def2, .def3, .def4 {
width: 50%;
padding: 20px;
float: left;
}
.product1, .product2, .product3, .product4 {
width: 100%;
margin: 0 0;
}
}
#media all and (max-width: 768px) {
.def1, .def2, .def3, .def4 {
width: 100%;
padding: 20px;
float: left;
}
}
You are correct in using media queries. In those you can f.e. set the width of your elements like this:
#media screen and (max-width: 1199) {
.product { // you can write .product1, .product2,... but I would suggest creating this new class, as none of those images really need their own css
max-width: 25%; //this will change for tablet and mobile to 50% and 100%
}
}
Now do that for all modes that you want.
Also note that instead of setting a margin-right you could use flexbox with justify-content: space-between in the wrapper; Otherwise you will have to remove those margins for different screen sizes.
It's my first time here. A friend suggested this as a good source of knowledge, and I am in dire need of that!
I am trying to write HTML and CSS using a viewport, media queries and a fluid grid to create a page which scales from desktop (desktop example ) to mobile (mobile example).
I have tried to cobble it together with help from the w3c site, but someone who wasn't particularly helpful said I had bootstrap in there (I didn't intend to use that, and want it taken out but I have no idea what it is).
What I've managed to achieve is to have the mobile size work, but for some reason the colour area of the boxes that should be 50% and 25% of the width of the rows in desktop don't stretch as they should.
What did I do wrong? Help would be most, most appreciated!
This is the html I had written:
And this is the CSS: #charset "utf-8";
/* CSS Document */
* {
box-sizing: border-box;
}
.row::after {
content: "";
clear: both;
display: table;
}
[class*="col-"] {
float: left;
padding: 8px;
border: thin rgba(0, 0, 0, 1.00);
}
.col-1 {
width: 8.33%;
}
.col-2 {
width: 16.66%;
}
.col-3 {
width: 25%;
}
.col-4 {
width: 33.33%;
}
.col-5 {
width: 41.66%;
}
.col-6 {
width: 50%;
}
.col-7 {
width: 58.33%;
}
.col-8 {
width: 66.66%;
}
.col-9 {
width: 75%;
}
.col-10 {
width: 83.33%;
}
.col-11 {
width: 91.66%;
}
.col-12 {
width: 100%;
}
html {
font-family: Constantia, "Lucida Bright", "DejaVu Serif", Georgia, "serif";
}
.navspot {
width: 100%;
max-width: 100%;
padding: 10px;
height: auto;
vertical-align: middle;
background: #d9cf91;
text-align: right;
}
.maincontent {
/*properties for cell*/
/*Nothing is required here
because we can use default styles*/
background: #30332c;
color: #FFFFFF;
padding: 10px;
}
.box1 {
background-color: #dfcf91;
color: #FFFFFF;
padding: 10px;
text-align: left;
float: left;
}
.box2 {
background-color: rgba(107, 35, 36, 1.00);
color: #FFFFFF;
text-align: center;
padding: 10px;
float: left;
}
.box3 {
background-color: #8D9981;
text-align: center;
padding: 10px;
float: left;
}
.box4 {
background-color: #606956;
text-align: center;
padding: 10px;
float: left;
}
.box5 {
background-color: #8D9981;
text-align: center;
padding: 10px;
float: left;
}
.box6 {
background-color: #606956;
text-align: center;
padding: 10px;
float: left;
}
.footer {
/*properties for cell*/
/*Nothing is required here because we can use default styles*/
/*background: #d9cf91;*/
padding: 10px;
}
/*for phone*/
#media only screen and (max-width: 768px) {
[class*="col-"] {
width: 100%;
}
}
<div class="row">
<div class="col">
<div class="navspot">Navigation Spot
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="maincontent">Main Content Spot
</div>
</div>
</div>
<div class="row">
<div class="col-6">
<div class="box1">Box 1
</div>
</div>
<div class="col-6">
<div class="box2">Box 2
</div>
</div>
</div>
<div class="row">
<div class="col-3">
<div class="box3">Box 3
</div>
</div>
<div class="col-3">
<div class="box4">Box 4
</div>
</div>
<div class="col-3">
<div class="box5">Box 5
</div>
</div>
<div class="col-3">
<div class="box6">Box 6
</div>
</div>
<div class="row">
<div class="col">
<div class="footer">Footer Area
</div>
</div>
</div>
Sorry if I'm being a dunce. Really struggling with the concepts of CSS and fluidity. Thanks in advance!
Fix 1: Colored content boxes not stretching
Do as ovokuro said, and remove float:left; line from ALL of your ".box" classes.
Fix 2: Column behavior and wrapping in your grid
Some div elements in your grid are not inheriting the border-box model, as you expected. To fix this for all browsers add:
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
For more about this see Box Sizing > Universal Box Sizing with Inheritance
Fix 3: Guides
While you are learning add some guides to your grid so you can more easily see what you are doing, and how things relate. For example:
/* temporary orange column guides */
[class*="col-"] {
border: 1px dotted orange;
}
Considering a grid that contains fixed size items (not my choice), and is not fixed size.
I would like to centralize the container (.grid-container) to have same side margin no matter how many items it have and how they are placed inside container as long as they are left-aligned.
If it isn't possible to do this only with CSS how can I do using JavaScript?
It's not necessary to use twitter-bootstrap grid system like the demo code.
Here a code to illustrate: https://embed.plnkr.co/F6niiwaosnO8tr0ss4XF/
.container {
background-color: #2B3643;
}
.grid-container {
padding: 30px 30px 0 30px;
}
.grid-item-wrapper {
width: 200px;
margin-bottom: 15px;
}
.grid-item {
margin-bottom: 15px;
}
.grid-item > .item-desc {
padding: 8px;
background-color: #333333;
color: #CFCFCF;
}
<div class="container">
<div class="grid-container row">
<!-- grid items -->
</div>
</div>
<template id="tmpl_grid_item">
<div class="grid-item-wrapper col-xs-3">
<div class="grid-item">
<div class="item-picture">
<img src="http://lorempixel.com/350/200/food/" style="width: 100%;" />
</div>
<div class="item-desc">
Lorem Ipsum
</div>
</div>
</div>
</template>
If you are willing to use absolute positioning and CSS3, there is a way.
HTML:
<div class="grid">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
CSS:
.grid{
position: absolute;
width: auto;
left: 50%;
-ms-transform: translateX(-50%); /* IE 9 */
-webkit-transform: translateX(-50%); /* Safari */
transform: translateX(-50%);
}
.item{
width: 50px;
height: 50px;
background: #fff;
float: left;
margin: 20px;
}
Here is a working fiddle. Hope it helps!
Just so that the code is out there in case it's useful, you can get the same behavior as F. Versehgi's answer without absolute positioning. This uses flexbox (so requires IE11, but any other browser should be fine) and some media queries (to account for the Bootstrap responsive container).
Note: You'll want to view the JSFiddle or CodePen link below, because the Stack Snippet is not working properly, for some reason:
JSFiddle example
CodePen example
$(document).ready(function() {
function fillGrid() {
var $gridContainer = $('.grid-container');
var htmlGridItem = $('#tmpl_grid_item').html();
$gridContainer.empty();
for (var i = 0; i < 20; i++) {
var $gridItem = $(htmlGridItem);
$gridContainer.append($gridItem);
}
};
fillGrid();
});
.container {
background-color: #2B3643;
}
.container * {
box-sizing: content-box;
}
.grid-container {
padding-top: 30px;
padding-bottom: 0px;
display: flex;
flex-wrap: wrap;
margin: 0px auto;
}
.grid-item-wrapper {
width: 200px;
margin-bottom: 15px;
}
.grid-item {
margin-bottom: 15px;
}
.grid-item > .item-desc {
padding: 8px;
background-color: #333333;
color: #CFCFCF;
}
body {
padding-top: 60px;
}
#media (min-width: 762px) and (max-width: 991px) {
.grid-item-wrapper:nth-child(3n+1) {
margin-left: 15px;
}
}
#media (min-width: 992px) {
.grid-item-wrapper:nth-child(4n+1) {
margin-left: 9px;
}
}
#media (min-width: 1200px) {
.grid-item-wrapper:nth-child(4n+1) {
margin-left: 109px;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<div class="container">
<div class="grid-container row">
<!-- grid items -->
</div>
</div>
<template id="tmpl_grid_item">
<div class="grid-item-wrapper col-xs-3">
<div class="grid-item">
<div class="item-picture">
<img src="http://lorempixel.com/350/200/food/" style="width: 100%;" />
</div>
<div class="item-desc">
Lorem Ipsum
</div>
</div>
</div>
</template>
I've been searching online for an answer and can't really find a solution. I'm trying to display an image and then directly below have a colored block (that is attached to the bottom of the image) for a caption on the image.
Below are my CSS code and HTML for the page.
I have this css code:
/* SECTIONS */
.section {
clear: both;
padding: 0px;
margin: 0px;
}
/* COLUMN SETUP */
.col {
display: block;
float:left;
margin: 1% 0 1% 5.0%;
}
.col:first-child { margin-left: 0; }
/* GROUPING */
.group:before,
.group:after { content:""; display:table; }
.group:after { clear:both;}
.group { zoom:1; /* For IE 6/7 */ }
/* GRID OF FOUR */
.span_4_of_4 {
width: 100%;
}
.span_3_of_4 {
width: 73.75%;
}
.span_2_of_4 {
width: 47.5%;
}
.span_1_of_4 {
width: 21.25%;
}
/* GO FULL WIDTH BELOW 480 PIXELS */
#media only screen and (max-width: 480px) {
.col { margin: 1% 0 1% 0%; }
.span_1_of_4, .span_2_of_4, .span_3_of_4, .span_4_of_4 { width: 100%; }
}
/***** HTML CODE: *****/
<div class="section group">
<div class="col span_1_of_4">
<img src="XXX" style="border-width: 1px; border-style: solid; width: 190px; height: 255px;" /></a>
<br />
TEXT HERE
</div>
</div>
.img-wrapper {
background: #888;
border-width: 1px;
border-style: solid;
}
.img-wrapper img {
width: 100%;
padding-bottom: 50px;
}
<div class="section group">
<div class="col span_1_of_4">
<div class="img-wrapper">
<img src="xxx">
<br>
TEXT HERE
</div>
</div>
</div>
Wrap the image and the caption in the same div, and give that div a background color.
Here's a simple example:
<div id="wrapper">
<img src="XXX" style="width: 190px; height: 255px;" />
Text
</div>
#wrapper {
background: #ccc;
display: inline-block;
}
#wrapper a {
text-align: center;
display: block;
padding: 10px;
}
http://jsfiddle.net/eo9wfx5c/1/