?
Solved

Why this small css codes has problem on tablet?

Posted on 2016-08-28
3
Medium Priority
?
147 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

764 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