我之前发现过与此相关的问题,但我似乎无法找到任何有助于解决问题的解决方案。当浏览器宽度为718px或更低时,正在创建网页右侧的空白区域,随着浏览器大小变小,它变得越来越大......我该如何解决这个问题?
此代码可在此网站上找到:http://www.dimatteos.com.au/cucina/cucinamobile.html
@charset "utf-8";
/* CSS Document */
body {
margin: 0;
padding: 0;
background-color: black;
overflow-x: hidden;
}
#container {
width: 100%;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
}
#logo {
top: -20px;
display: inline-block;
position: relative;
margin: 0 auto;
margin-top: 30px;
width: 250px;
}
#newwhiteline {
position: relative;
width: 100%;
height: 4px;
background-color: white;
top: -40px;
z-index: -1;
}
#whiteline {
position: relative;
width: 100%;
height: 4px;
background-color: white;
}
a.logo {
display: block;
text-align: center;
margin: auto;
width: 350px;
}
.firstlist {
position: relative;
left: -17px;
margin-top: -23px;
text-align: center;
}
ul {
list-style-type: none;
}
li.list1 {
display: inline;
padding: 9px;
font-family: Arial;
font-size: 14px;
}
#underline {
position: relative;
width: 100%;
height: 4px;
background-color: white;
margin-top: 0px;
z-index: -1;
}
a.list {
text-decoration: none;
color: white;
}
a.list:hover {
background-color: white;
color: black;
padding-top: 3px;
padding-bottom: 3px;
}
a.cucinaclass {
text-decoration: none;
color: white;
}
a.cucinaclass:hover {
background-color: none;
}
span.cucina {
background-color: white;
color: black;
padding-top: 5px;
padding-bottom: 4px;
}
@font-face {
font-family: matteosfont;
src: url(../fonts/riesling.ttf);
}
@font-face {
font-family: cooperfont;
src: url(../fonts/fbsbltc.ttf);
}
#whitebox {
position: relative;
width: 100%;
height: 40px;
background-color: black;
top: 20px;
border-radius: 5px;
}
.headercucina {
position: absolute;
color: white;
font-family: 'Oswald', sans-serif;
font-size: 31px;
left: 25px;
top: -5px;
}
#underline2 {
position: relative;
background-color: white;
width: 100%;
height: 4px;
top: 26px;
}
#images {
position: relative;
}
#brekkie {
border: 5px solid white;
width: 90%;
display: block;
margin-left: auto;
margin-right: auto;
margin-top: 20px;
}
.lunchbox {
margin-top: 20px;
border: 5px solid white;
width: 90%;
display: block;
margin-left: auto;
margin-right: auto;
}
.dinnerbox {
margin-top: 20px;
border: 5px solid white;
width: 90%;
display: block;
margin-left: auto;
margin-right: auto;
}
.drinksbox {
margin-top: 20px;
border: 5px solid white;
width: 90%;
display: block;
margin-left: auto;
margin-right: auto;
}
.secondlist2 {
position: relative;
z-index: 6;
font-family: Arial;
padding-bottom: 10px;
margin-right: 30px;
}
span.coopert {
color: white;
font-family: cooperfont;
font-size: 16px;
}
span.coopertt {
color: white;
font-size: 16px;
}
#fb2 {
width: 35px;
}
#insta2 {
width: 35px;
}
#agfg2 {
width: 35px;
}
li.listtt {
display: inline;
padding: 5px;
font-family: Arial;
font-size: 15px;
}
.homebaby:hover {
background-color: transparent;
}
.instababy:hover {
background-color: transparent;
}
.agfgbaby:hover {
background-color: transparent;
}
span.coopert:hover {
color: black;
background-color: white;
padding-top: 4px;
padding-bottom: 3px;
}
a {
text-decoration: none;
}
.lunchbox:hover {
border: 5px solid #F4EF7F;
}
.dinnerbox:hover {
border: 5px solid #F4EF7F;
/*#F4EF7F Credit Riley Pettigrew*/
}
.drinksbox:hover {
border: 5px solid #F4EF7F;
}
#brekkie:hover {
border: 5px solid #F4EF7F;
}
#homer {
background-color: white;
padding-top: 5px;
padding-bottom: 4px;
color: black;
}
.firstlistt {
position: relative;
font-family: Arial;
padding-top: 5px;
padding-bottom: 10px;
margin-right: 30px;
}
@font-face {
font-family: cooperfont;
src: url(fonts/fbsbltc.ttf);
}
span.coopert {
color: white;
font-family: cooperfont;
}
span.coopertt {
color: white;
}
@media only screen and (max-width: 370px) {
#logo {
width: 200px;
}
}
@media only screen and (max-width: 320px) {
span.main {
font-size: 35px;
}
#header {
margin-top: 10px;
}
}
a.cooper {
font-family: cooperfont;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>di Matteos - Cucina</title>
<link href="cucinamobilestylesheet.css" rel="stylesheet" type="text/css" />
<link href="../images/fatty.ico" rel="icon" type="image/x-icon" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1, width = device-width, user-scalable = no">
<meta name="apple-mobile-web-app-capable" content="yes" />
</head>
<body>
<div id="container">
<div id="whiteline"></div>
<a class="logo" href="http://www.dimatteos.com.au">
<img id="logo" src="../images/diMatteos2.png" />
</a>
<div id="newwhiteline"></div>
<ul class="firstlist">
<a class="list" href="http://www.dimatteos.com.au">
<li class="list1"><strong>HOME</li></a>
<a class = "list" href = "http://www.dimatteos.com.au/cucina"><li class = "list1" id = "homer">CUCINA</span></li></a>
<a class = "list" href = "http://www.dimatteos.com.au/espresso"><li class = "list1">ESPRESSO</strong>
</li>
</a>
<a class="list" href="http://www.dimatteos.com.au/functions">
<li class="list1"><strong>FUNCTIONS</li></a>
<a class = "list" href = "http://www.dimatteos.com.au/gallery"><li class = "list1">GALLERY</li></a>
<a class = "list" href = "http://www.dimatteos.com.au/contact"><li class = "list1">CONTACT</strong>
</li>
</a>
</ul>
<div id="underline"></div>
<div id="whitebox">
<div class="headercucina"><strong><a class = "cucinaclass" href = "http://www.dimatteos.com.au/cucina">CUCINA</a></strong>
</div>
</div>
<div id="underline2"></div>
<div id="images">
<img class="blackempty" src="../images/black.png" />
<a href="http://www.dimatteos.com.au/cucina/breakfast">
<img class="breakfastbox" id="brekkie" src="../images/breakfastboxbb.png" />
</a>
<a href="http://www.dimatteos.com.au/cucina/lunch">
<img class="lunchbox" src="../images/lunchboxbb.png" />
</a>
<a href="http://www.dimatteos.com.au/cucina/dinner">
<img class="dinnerbox" src="../images/dinnerbox.png" />
</a>
<a href="http://www.dimatteos.com.au/cucina/drinks">
<img class="drinksbox" src="../images/drinksbox.png" />
</a>
</div>
<center>
<ul class="firstlistt">
<a class="homebaby" href="http://www.facebook.com/matteosforries" target="_blank">
<li class="listtt">
<img id="fb2" src="../images/facebookcircle.png" />
</li>
</a>
<a class="instababy" href="http://www.instagram.com/dimatteosforries" target="_blank">
<li class="listtt">
<img id="insta2" src="../images/instagramcircle.png" />
</li>
</a>
<a class="agfgbaby" href="http://www.agfg.com.au/guide/45328/nsw/central-coast-nsw/central-coast-nsw/forresters-beach/restaurants-dining/di-matteos" target="_blank">
<li class="listtt">
<img id="agfg2" src="../images/agfgcircle.png" />
</strong>
</li>
</a>
</ul>
</center>
<center>
<ul class="secondlist2">
<li class="bar2"><span class="coopertt">Website by </span><a class="cooper" href="http://www.coopertimewell.com" target="_blank"><span class = "coopert">CooperTimewell.com</span></li></a>
</ul>
</center>
<!--
DON'T TOUCH THIS DIV !-->
</div>
</body>
</html>
答案 0 :(得分:0)
将此添加到您的CSS中。
CSS
body{
overflow-x:hidden;
}
这将删除空格。
答案 1 :(得分:0)
好的,在查看您的实际网站后,这张图片(在您的#images
div内)导致空间向右移动:
<img class="blackempty" src="../images/black.png">
我不确定该图像的用途是什么,但它导致了问题,我确信无论如何都有比使用图像更好的解决方案。
答案 2 :(得分:0)
好的,我终于找到了答案。
谢谢ralph.m发现问题的一半 - 它涉及&#34; blackempty&#34; img类只需要删除。
然而,由于班级&#34; .headercucina&#34; ...在CSS文档中,它被告知要向左移动25px,这仍然有一点点黑色空间消失了......这个正在创造黑色空间。要解决此问题,您只需更改左:25px到margin-left:25px
:)