Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Why this small css codes has problem on tablet?

Posted on 2016-08-28
3
Medium Priority
?
164 Views
Last Modified: 2016-08-29
Hello;

I have this html and css codes,and want that  <div class="test"></div> be below of header div in middle,it is ok on desktop but in tablet in state of portrait the header div doesnot fit the screen and have horizontal scroll,please let me know that how can i fix it?
Thanks

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>test-tablet</title>
<style>
body {
	margin-left: auto;
	margin-top: 0px;
	margin-right: auto;
	margin-bottom: 0px;
	padding:0px;
}
.header{
	min-height:50px;
    width: 100%;
	background-color: #bb0700;
	margin-top: 0px;
	margin-right: auto;
	margin-left: auto;
	margin-bottom: 0px;
	-moz-box-sizing: border-box; 
    -webkit-box-sizing:border-box;
	box-sizing: border-box;
	}
 .test{
	height:35px;
    width: 1000px;
    background-color: red;
	padding: 0px;
	margin-top: 0px;
	margin-right: auto;
	margin-left: auto;
	margin-bottom: 0px; 
		 
 }
 </style>
</head>

<body>
<div class="header">
     </div>
<div class="test">
 </div>
</body>
</html>

Open in new window

0
Comment
Question by:MOSTAGHASSI
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 8

Assisted Solution

by:Jason
Jason earned 1000 total points
ID: 41774006
The width of test is causing the problem. It's too long for your tablet. I tried it on my phone and ran into the same problem.

.test{
    width: 1000px;
}

Open in new window


One way to fix it is to make the site responsive. For example: You could have a 1000px length for resolutions typically found on Desktops and something smaller (200px length) for mobile.

<style>
body {
	margin-left: auto;
	margin-top: 0px;
	margin-right: auto;
	margin-bottom: 0px;
	padding:0px;
}
.header{
	min-height:50px;
    width: 100%;
	background-color: #bb0700;
	margin-top: 0px;
	margin-right: auto;
	margin-left: auto;
	margin-bottom: 0px;
	-moz-box-sizing: border-box; 
    -webkit-box-sizing:border-box;
	box-sizing: border-box;
	}

/* For Desktop PCs */
@media screen and (max-width: 3840px) {
 .test{
	height:35px;
    width: 1000px;
    background-color: red;
	padding: 0px;
	margin-top: 0px;
	margin-right: auto;
	margin-left: auto;
	margin-bottom: 0px; 
		 
 }
}

/* Tablets and smartphones */
@media screen and (max-width: 800px) {
 .test{
	height:35px;
    width: 200px;
    background-color: red;
	padding: 0px;
	margin-top: 0px;
	margin-right: auto;
	margin-left: auto;
	margin-bottom: 0px; 
		 
 }
}
 </style>

Open in new window

0
 
LVL 9

Accepted Solution

by:
Brian Tao earned 1000 total points
ID: 41774232
Why don't just change the "width: 1000px" to "width: 80%"?
0
 

Expert Comment

by:Abdulla Nilam
ID: 41774302
Set width property responsively

 .test{
	height:35px;
width: 100%;
}

Open in new window


Check JSFiddle Preview
0

Featured Post

Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question