Solved

Why this small css codes has problem on tablet?

Posted on 2016-08-28
3
105 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
3 Comments
 
LVL 7

Assisted Solution

by:Jason
Jason earned 250 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 250 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now