how to scale background-image proportionally with container in CSS with - html

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%;

Related

3 columns image layout with image text

I need three columns of image layout with image text like this picture
its responsive, like below picture no border no background color, image text background color like this required, I'm new to css/html
I need three columns of image layout with image text like this picture
its responsive, like below picture no border no background color, image text background color like this required, I'm new to css/html
* {
box-sizing: border-box;
}
/* Create three equal columns that floats next to each other */
.column {
float: left;
width: 33.33%;
padding: 10px;
height: 300px; /* Should be removed. Only for demonstration */
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
.figure {
border: thin #c0c0c0 solid;
display: flex;
flex-flow: column;
padding: 5px;
max-width: 220px;
margin: auto;
position: relative;
}
.imgdiv {
max-width: 220px;
max-height: 150px;
}
.figcaption {
background-color: pink;
color: #fff;
font: italic smaller sans-serif;
padding: 3px;
text-align: center;
}
/* Responsive layout - makes the three columns stack on top of each other instead of next to each other */
#media screen and (max-width: 700px) {
.column {
width: 100%;
}
}
<h2>Responsive Three Column Layout</h2>
<p>Resize the browser window to see the responsive effect (the columns will stack on top of each other instead of floating next to each other, when the screen is less than 600px wide).</p>
<div class="row">
<div class="column" style="">
<figure>
<img class="column" src="image1.jpg" style="width:100%;height:100%;">
<figcaption>Register here</figcaption>
</figure>
</div>
<div class="column" style="background-color:#bbb;">
<h3>image 2</h3>
<p>Info 2</p>
</div>
<div class="column" style="background-color:#ccc;">
<h3>Publications</h3>
<p>Info 3</p>
</div>
</div>
Use flex and flex-direction
.row {
display: flex;
flex-direction: row;
justify-content: center;
align-items: flex-end;
}
.column {
padding: 10px;
box-sizing: border-box;
}
img {
max-width: 100%;
}
.caption {
background-color: purple;
color: white;
/* padding: 0.1rem; */
}
.caption h3,
.caption p {
padding: 0.5rem;
margin: 0;
}
/* Responsive layout - makes the three columns stack on top of each other instead of next to each other */
#media screen and (max-width: 700px) {
.row {
flex-direction: column;
}
}
<h2>Responsive Three Column Layout</h2>
<p>Resize the browser window to see the responsive effect (the columns will stack on top of each other instead of floating next to each other, when the screen is less than 600px wide).</p>
<div class="row">
<div class="column">
<div class="image">
<img src="https://homepages.cae.wisc.edu/~ece533/images/arctichare.png" alt="arctichare">
</div>
<div class="caption">
<h3>image 1</h3>
<p>Info 1</p>
</div>
</div>
<div class="column">
<div class="image">
<img src="https://homepages.cae.wisc.edu/~ece533/images/airplane.png" alt="airplane">
</div>
<div class="caption">
<h3>image 2</h3>
<p>Info 2</p>
</div>
</div>
<div class="column">
<div class="image">
<img src="https://homepages.cae.wisc.edu/~ece533/images/baboon.png" alt="baboon">
</div>
<div class="caption">
<h3>Publications</h3>
<p>Info 3</p>
</div>
</div>

Responsive Card Menu Content Overflow

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.

4 responsive divs are not showing properly on tab and mobile

I am trying to create 4 responsive divs for homepage; tried to decreae padding and margin of div not working.divs should be responsive on mobile devices they shpuld move below each one ; two divs appear on tabs; 4 divs on desktop and one div on mobile
i have tried following HTML:
<div class="flex-container">
<div class="flex-item">
<div class="flex-item-inner">
<div class="homepage-div homepage-div-shadow">
<img class="homepage-div-icon"/>
<h2>Heading</h2>
<h6>Sub-Heading</h6>
<p>This is responsive paragraph. Text would not move out of div as below .</p>
<button class="bttn">Practice Now</button>
</div>
</div>
</div>
<div class="flex-item">
<div class="flex-item-inner">
<div class="homepage-div homepage-div-shadow">
<img class="homepage-div-icon"/>
<h2>Heading</h2>
<h6>Sub-Heading</h6>
<p>This is responsive paragraph. Text would not move out of div as below .</p>
<button class="bttn">Practice Now</button>
</div>
</div>
</div>
<div class="flex-item">
<div class="flex-item-inner">
<div class="homepage-div homepage-div-shadow">
<img class="homepage-div-icon"/>
<h2>Heading</h2>
<h6>Sub-Heading</h6>
<p>This is responsive paragraph. Text would not move out of div as below .</p>
<button class="bttn">Practice Now</button>
</div>
</div>
</div>
<div class="flex-item">
<div class="flex-item-inner">
<div class="homepage-div homepage-div-shadow">
<img class="homepage-div-icon"/>
<h2>Heading</h2>
<h6>Sub-Heading</h6>
<p>This is responsive paragraph. Text would not move out of div as below .</p>
<button class="bttn">Practice Now</button>
</div>
</div>
</div>
</div>
here is css divs are not showing properly on tab and mobile devices and i want to decreae the padding and margin:
.homepage-div-shadow
{
padding: 20px;
box-shadow: 2px 2px 8px 1px #cccccc;
border: solid 1px #cccccc;
border-radius: 2px;
}
.homepage-div-icon{
background-image: url("image.png");
width: 100px;
height: 100px;
}
.homepage-div a
{
text-decoration: none;
color: white;
font-size: 16px;
}
.homepage-div h2{
font-size: 28px;
opacity: 0.90;
font-weight: 600;
margin: 5%;
margin-bottom: 6px;
}
.homepage-div h6{
font-size: 17px;
padding: 0px;
margin: 0px;
margin-bottom: 20px;
opacity: 0.6;
}
#media(min-width: 769px) {
.flex-container {
display: flex;
flex-wrap: wrap;
}
.flex-container .flex-item {
flex: 1 0 50%;
}
}
#media (min-width: 1024px) {
.flex-container .flex-item {
flex: 1 0 25%;
}
}
.flex-item-inner {
padding: 25px;
margin: 20px;
background-color: white;
}
Here is the demo link: testfellow
Hope the solution below helps. I have just tried to mimic the scenario where there are a certain number of div s. And as per your question and requirement, have:
1. Followed mobile-first approach.
2. For mobile devices, each div should come in separate lines.
3. For tabs (at your breakpoint: 769px and above), two divs should come in a line.
4. For desktops (at your breakpoint: 1024px and above), four divs should come in a line.
*,
*::before,
*::after {
box-sizing: border-box;
}
body {
margin: 0;
background-color: #2980b9;
}
.flex {
max-width: 80%;
}
.flex-item {
background-color: #ffffff;
padding: 5em;
border: 1px solid black;
margin: 2% auto;
width: 25%;
}
#media(min-width: 769px) {
.flex {
display: flex;
flex-wrap: wrap;
}
.flex-item {
width: 50%;
}
}
#media(min-width: 1024px) {
.flex {
display: flex;
flex-wrap: wrap;
}
.flex-item {
width: 25%;
}
}
<div class="flex">
<div class="flex-item"></div>
<div class="flex-item "></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item "></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
</div>

How do I fix the css to have two columns on small screens?

I have two sections of my site, the menu down the left and the content on the right. On small screens I need the menu to be at the top, with the content centered in the middle.
After some issues, I was able to place the content next to the menu on large screens, but it's done pushing it to the left- meaning that on the smaller windows it does the same.
I've tried floats, changing pixels to and from %'s, aligning floats to left and to the right, clearing floats, changing widths and heights of them both, and changing display to inline-block and inline. (There are more things, but I can't remember.)
The only thing that almost works is the margin-left:30% for the main content.
My question:
What code do I need to change to have the content beside the menu on larger screens, but underneath on smaller ones-without it being pushed to one side?
(I removed the content so it just shows the layout in it's base form.)
<link rel="stylesheet" href="test_css.css">
</head>
<body>
<!--menu below-->
<div class="menu">
<ul class="sidenav">
<li><h3>menu:</h3></li>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</div>
<!--End of the menu.-->
<!--header-->
<div class="header">
<br />
<h1>Header</h1>
<a></a>
<p class="hr">____________________________________</p>
</div>
<!--end of header section-->
<div class="main">
<h2>Main content</h2>
<h2>Main content</h2>
<a></a>
<p class="hr">____________________________________</p>
<h1>Main content</h1>
<h2>Main content</h2>
<h2>Main content</h2>
<p class="hr">____________________________________</p>
</div>
<!--footer content below-->
<div id="footer">
<h4>Staff:</h4>
<h5>1</h5>
<h5>2</h5>
<h5>3</h5>
<h6>Last updated: --/--/----</h6>
</div>
<!--end of footer content-->
</body>
And the css:
/* background and font face for web page-!important! */
body {
font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
width: 90%;
margin: 0 auto;
background-color:#47807E;
background-image: url('Home_background.png');
background-position:top;
background-repeat:repeat-x;
text-align: center;
}
.responsive {
width:100%;
height: auto;
}
ul{
width: 30%;
border: 2px solid black;
}
/* formatting for content areas */
div.header {
margin-left: 30%;
width: 63%;
padding:0;
}
div.main {
margin-left:30%;
width: 63%;
padding:0;
}
div.footer {
width: 30%;
float: right;
margin: 10px;
text-align: center;
}
/* styling for font and images */
/* side navigation testing, need to fix formatting. */
ul.sidenav {
list-style-type: none;
margin: 0;
padding: 0;
float:left;
width:25%;
background-colour: #ccffff;
position: fixed;
height: 100%;
overflow: auto;
padding:0%;
}
ul.sidenav li a {
display: block;
color: #000;
padding: 8px 16px;
text-decoration: none;
background-color: #ccffff;
}
ul.sidenav li a.active {
background-color: #003333;
color:white;
}
ul.sidenav li a:hover:not(.active){
background-color:#003333;
color: white;
}
#media screen and (max-width:900px) {
ul.sidenav {
width: 100%;
height: auto;
position: relative;
display: inline-block;
}
}
ul.sidenav li a {
float: inline-block;
padding: 10px;
}
div.content {margin-left: 0;}
#media screen and (max-width: 400px) {
ul.sidenav li a{
text-align: center;
float: none;
}
}
What I'm hoping for:
Larger window: Navigation menu on the left, content on the right.
Smaller window: Menu on the top, content centered beneath.
I think you already done the responsive task for smaller devices just add below css in #media screen and (max-width:900px) media query for minor tweaks.
div.header,
div.main {
margin-left: 0;
width: 100%;
}
Also make sure you add viewport meta in your page head if not just add below code in you page head. Try this i hope it'll help you out. Thanks
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
/* background and font face for web page-!important! */
body {
font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
width: 90%;
margin: 0 auto;
background-color:#47807E;
background-image: url('Home_background.png');
background-position:top;
background-repeat:repeat-x;
text-align: center;
}
.responsive {
width:100%;
height: auto;
}
ul{
width: 30%;
border: 2px solid black;
}
/* formatting for content areas */
div.header {
margin-left: 30%;
width: 63%;
padding:0;
}
div.main {
margin-left:30%;
width: 63%;
padding:0;
}
div.footer {
width: 30%;
float: right;
margin: 10px;
text-align: center;
}
/* styling for font and images */
/* side navigation testing, need to fix formatting. */
ul.sidenav {
list-style-type: none;
margin: 0;
padding: 0;
float:left;
width:25%;
background-colour: #ccffff;
position: fixed;
height: 100%;
overflow: auto;
padding:0%;
}
ul.sidenav li a {
display: block;
color: #000;
padding: 8px 16px;
text-decoration: none;
background-color: #ccffff;
}
ul.sidenav li a.active {
background-color: #003333;
color:white;
}
ul.sidenav li a:hover:not(.active){
background-color:#003333;
color: white;
}
#media screen and (max-width:900px) {
ul.sidenav {
width: 100%;
height: auto;
position: relative;
display: inline-block;
}
div.header,
div.main {
margin-left: 0;
width: 100%;
}
}
ul.sidenav li a {
float: inline-block;
padding: 10px;
}
div.content {margin-left: 0;}
#media screen and (max-width: 400px) {
ul.sidenav li a{
text-align: center;
float: none;
}
}
<!--menu below-->
<div class="menu">
<ul class="sidenav">
<li><h3>menu:</h3></li>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</div>
<!--End of the menu.-->
<!--header-->
<div class="header">
<br />
<h1>Header</h1>
<a></a>
<p class="hr">____________________________________</p>
</div>
<!--end of header section-->
<div class="main">
<h2>Main content</h2>
<h2>Main content</h2>
<a></a>
<p class="hr">____________________________________</p>
<h1>Main content</h1>
<h2>Main content</h2>
<h2>Main content</h2>
<p class="hr">____________________________________</p>
</div>
<!--footer content below-->
<div id="footer">
<h4>Staff:</h4>
<h5>1</h5>
<h5>2</h5>
<h5>3</h5>
<h6>Last updated: --/--/----</h6>
</div>
<!--end of footer content-->
So basically, what you need to achieve that is to wrap the whole document into a single div wrapper.
Here I added a div element with id of #main. And wrapped the main content into a div with classname of .content. The structure would look like this.
<div id="main">
<div class="menu">
<!-- other codes -->
</div>
<div class="content">
<!-- other codes -->
</div>
</div>
and the styling for the root div
#main {
width: 100%;
height: 100vh; // take up the whole viewport height
overflow: hidden; // remove the scrollbar for overflow items
display: flex;
}
and the styling for the content and menu div
.content {
width: 75%;
height: 100%;
overflow-y: scroll; // add the vertical scroll bar for content
}
.menu {
display: fixed;
left: 0;
width: 25%;
height: 100vh;
}
and this is what it will look like.
* {
box-sizing: border-box;
}
body {
font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
width: 100%;
margin: 0 auto;
background-color:#47807E;
background-image: url('Home_background.png');
background-position:top;
background-repeat:repeat-x;
text-align: center;
}
#main {
width: 100%;
height: 100vh;
overflow: hidden;
display: flex;
}
.menu {
display: fixed;
left: 0;
width: 25%;
height: 100vh;
}
.content {
width: 75%;
height: 100%;
overflow-y: scroll;
}
.responsive {
width:100%;
height: auto;
}
ul{
width: 30%;
border: 2px solid black;
}
/* formatting for content areas */
.header {
padding:0;
}
.main {
padding:0;
}
.footer {
width: 30%;
float: right;
margin: 10px;
text-align: center;
}
/* styling for font and images */
/* side navigation testing, need to fix formatting. */
.sidenav {
list-style-type: none;
margin: 0;
padding: 0;
float:left;
width:25%;
background-colour: #ccffff;
position: fixed;
height: 100%;
overflow: auto;
padding:0%;
}
.sidenav li a {
display: block;
color: #000;
padding: 8px 16px;
text-decoration: none;
background-color: #ccffff;
}
.sidenav li a.active {
background-color: #003333;
color:white;
}
.sidenav li a:hover:not(.active){
background-color:#003333;
color: white;
}
#media screen and (max-width:800px) {
#main {
display: block;
height: auto;
}
.menu {
width: 100%;
height: 80px;
}
.content {
width: 100%;
overflow-y: hidden;
}
.sidenav {
width: 100%;
position: relative;
}
.sidenav li {
display: inline-block;
}
}
#media screen and (max-width: 400px) {
.sidenav li a{
text-align: center;
float: none;
}
}
<div id="main">
<div class="menu">
<ul class="sidenav">
<li><h3>menu:</h3></li>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>
</div>
<!--End of the menu.-->
<div class="content">
<!--header-->
<div class="header">
<br />
<h1>Header</h1>
<a></a>
<p class="hr">____________________________________</p>
</div>
<!--end of header section-->
<div class="main">
<h2>Main content</h2>
<h2>Main content</h2>
<a></a>
<p class="hr">____________________________________</p>
<h1>Main content</h1>
<h2>Main content</h2>
<h2>Main content</h2>
<p class="hr">____________________________________</p>
</div>
<!--footer content below-->
<div id="footer">
<h4>Staff:</h4>
<h5>1</h5>
<h5>2</h5>
<h5>3</h5>
<h6>Last updated: --/--/----</h6>
</div>
</div>
</div>

CSS and html layout

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.