【问题标题】:HTML Website Going Crazy when Zoomed outHTML 网站在缩小时变得疯狂
【发布时间】:2017-10-15 06:50:30
【问题描述】:

我不知道为什么,但是当我缩小我的网站时,代码似乎崩溃了,整个事情看起来很恶心。我已经检查了这个问题的其他答案,但没有一个解决方案真正适合我的代码。

body {
	background-image: url(gradient.png);
	background-repeat: no-repeat;
	background-size: cover;
}

h1.heading {
	color: #046289;
	font-size: 50px;
	margin-top: 100px;
	text-align: center;
	font-family: 'Poppins', sans-serif;
} 

p.heading {
	color: #046289;
	font-family: 'Poppins', sans-serif;
	font-size: 20.8px;
	font-weight: 600;
	position: relative;
	margin-left: 70px;
	top: 60px;
}

p.heading1 {
	color: #046289;
	font-family: 'Poppins', sans-serif;
	font-weight: 400;
	position: relative;
	margin-left: 70px;
	top: 50px;
}

img.aml {
	width:280px;
	height:280px;
	position: absolute;
	margin-left: 360px;
	bottom: 30px;

}

iframe.livevid {
	position: absolute;
	margin-left: 840px;
}

p.vid {
	color: #046289;
	font-family: 'Poppins', sans-serif;
	font-size: 20.8px;
	font-weight: 600;
	position: absolute;
	margin-left: 840px;
	top: 313px;
}

p.vid1 {
	color: #046289;
	font-family: 'Poppins', sans-serif;
	font-weight: 400;
	position: absolute;
	margin-left: 840px;
	top: 363px;
}

a {
	text-decoration: none;
}

p a:link {
	color: #4204a5;
}

p a:visited {
	color: #4204a5;
}

p a:hover {
	color: #71a3f2;
}

/*
BELOW - NAVIGATION BAR
*/

ul {
	list-style-type: none;
	margin: 0;
	padding: 0;
	overflow: hidden;
	width: 100%;	
}

li {
	float: left;
}

.spacefornav {
	margin-left: 462px;
}

li a:hover {
	color: #71a3f2;
}

div.nav {
	color: #046289;
}

li a {
	display: inline-block;
	color: #046289;
	text-align: center;
	padding: 8px 10px;
	text-decoration: none;
	font-family: 'Poppins'; sans-serif;
	margin: 0px 20px;
	font-weight: 500;
	cursor: pointer;
}
<!DOCTYPE html>
<html lang="en-US">
<head>
	<title>Childish Gambino</title>
	<meta charset="UTF-8">
	<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
	<link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700&amp;subset=devanagari,latin-ext" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
	<h1 class="heading">CHILDISH GAMBINO</h1>
		<ul>
		<div class="nav">
				<li class="spacefornav"><a href="home.html">Home</a></li>
				<li><a href="about.html">About</a></li>
				<li><a href="music.html">Music</a></li>
				<li><a href="contact.html">Contact</a></li>
		</div>
		</ul>
	<p class="heading">"AWAKEN MY LOVE!"</p>
	<p class="heading1">
	Childish Gambino's latest
	<br>
	and freshest album is
	<br>
	AVAILABLE NOW on <a href="https://itunes.apple.com/us/album/awaken-my-love/id1173655524" target="_blank">iTunes</a>,
	<br>
	<a href="https://play.spotify.com/album/4xnq1L6P551Qcb9gBXNMK7" target="_blank">Spotify</a> and <a href="https://play.google.com/store/music/album?id=Bc3g3mmud6z3xm6todpsldagple&tid=song-Tdcdooebkcepkmj7amghovz2ncq&hl=en" target="_blank">Google Play Music</a>
	</p>
	<img src="images/awakenmylove.jpg" class="aml" title="'Awaken My Love!' album art" alt="'Awaken My Love' album art">
	<<iframe width="280" height="158" src="https://www.youtube.com/embed/6v7W513Wj3g?rel=0" frameborder="0" allowfullscreen class=livevid></iframe>
	<p class="vid">Watch Now!</p>
	<p class="vid1">Childish Gambino performing '3005'<br>live at Splendor In The Grass!</p>
</body>
</html>

【问题讨论】:

  • 到底是什么问题?
  • 如果你想满足缩放的需求(如果你考虑一下,这并不是真的必要),那么你不能使用像素作为宽度和大小,你必须使用百分比。要么创建一个容器div 并修复它的宽度
  • 或者,我建议使用 CSS 框架,例如 Bootstrap 来满足您的需求。由于使用position : relative,您的网站“陷入困境”。
  • 那么我将如何创建一个带有 div 的容器来解决这个问题呢?抱歉,我是 html 新手 :(((

标签: javascript html css layout


【解决方案1】:

html, body{
    margin: 0px;
}
body{
    background-color: rgb(74, 107, 174);
    background-image: url("../images/bg.jpg");
    background-repeat: no-repeat;
    background-position: 50% 0%;
    background-size: 100%;
    width:100%;
    height:100%;
}

.inner-body{
    margin: 0px auto;
    width:960px;
    height:970px;
    background-color:rgba(255,255,255,0);
}

.login{
    text-align: center;
    margin-left: 641px;
    background-color: rgba(59,90,137,0.7);
    width: 315px;
    height:20px;
    padding-top:3px;
    padding-left:4px;
    word-spacing: 0.3px;
    letter-spacing:0.3px;
    color: white;
    font-family: Calibri;
    font-size:12.5px;
}

.menu-outer{
    margin-top:30px;
    background-color: rgba(10,30,50,0.8);
    padding:5px;
    height:60px;
}

.menu{
    border-style: solid;
    height:60px;
    border-width:0.5px;
    border-color: rgb(100,100,150);
    
}

.menu-image{
    position: absolute;
    margin-top:-50px;
    margin-left:18px;
    background-image: url("../images/logo.png");
    height: 150px;
    width:220px;
}

.menu-inner{
    margin-top:13px;
    height: 55px;
    margin-left: 234px;    
    color: rgb(164,211,241);
    font-family:Trebuchet MS;
    font-size:18.5px;
}

.zone-outer{
    background-color: rgba(26,30,50,0.9);
    height:632px;
}

.zone{
    margin-left: auto;
    margin-right: auto;
    border-bottom-style: solid;
    border-bottom-color: rgb(100,100,150);
    height: 625px;
    width:950px;
    border:1px solid;
    border-image: linear-gradient(to bottom,rgba(100,100,150,0),rgb(100,100,150) );
    border-image-slice: 1;
}

.mini-zones{ 
    float:left;
    margin-top:25px;
    margin-left:30px;
    width:280px;
    font-family:Trebuchet MS;
    color:white;
    line-height:22.9px;
}

.footer{
    text-align: center;
    margin-top:5px;    
    padding-top:10px;
    background-color: rgba(26,30,50,0.5);
    width:960px;
    height:35px;
    padding:0.1px;
    font-family:Trebuchet MS;
    font-size:14px;
    color:white;
}
ul.login{
    margin-right: 10px;
    background-color: rgba(59,90,137,0.1);
    display: inline;
    padding-left:0px;
    margin-left: 5px;
    color:white;
}


li.log{
    display:inline;
}

a:visited,a:link {
    color: rgb(164,211,241);
    text-decoration: none;
}

li:hover {
    background-color:rgb(73,103,129);
    text-decoration: none;
    color:white;
}

ul.menu-in{
    margin-top:0px;
    margin-left:50px;
    padding:4.5px 3.5px 0px 3.5px;
}
ul.menu-in li{
    display: inline;
    margin-left: auto;
    padding: 14px;
    border-radius: 4px;
}
ul.menu-in li+li:before{
    position: absolute;
    margin-left: -22px;
    content: "|";
    display: inline-block;
    padding-right: 7px;
    color: rgb(164,211,241);
    font-size: 20px;
    text-decoration: none;
}


ul.login li{
    display:inline;
}
ins{
    color:rgb(164,211,241);
}

.transperent{
        padding-left: 30px;
        padding-top:0.8px;
        background-color: rgba(0,0,0,0.3);
        height: 175px;
        color: white;
        font-family:Trebuchet MS;
        font-size: 42px;
        word-spacing:1px;
        letter-spacing:9px;
}

.contrast{
        filter: brightness(180%);
}
<!DOCTYPE html>
    <html>
        <head>
            <link rel="stylesheet" href="css\main-style.css">
            <link rel="stylesheet" href="css\home-page.css">
        </head>
        <body>
            <div class="inner-body">
                <div class="login">
                    <ul class="login">
                        <li>Request a Quote</li>
                        <li>&#9474;</li>
                        <li>Client Login</li>
                        <li>&#9474;</li>
                        <li>Vehicle Export Portal</li>
                    </ul>     
                </div>
                <div class="menu-outer">       
                    <div class="menu">
                        <div class="menu-image">
                        </div>
                        <div class="menu-inner">
                            <ul class="menu-in">
                                <li><a href="index.html">HOME</a></li>
                                <li><a href="https://www.w3schools.com">ABOUT FTZWS</a></li>
                                <li><a href="services.html">OUR SERVICES</a></li>
                                <li><a href="https://www.w3schools.com">OUR CLIENTS</a></li>
                                <li><a href="https://www.w3schools.com">CONTACT US</a></li>
                            </ul>
                        </div>                          
                    </div>
                </div>
                <div class="transperent">
                        <p>BRINGING TECHNOLOGY<br>AND OPERATIONAL EXCELLENCE.</Pre>
                </div>
                <div class="zone-outer">
                    <div class="zone">
                        <div class="mini-zones">
                            <img class="contrast" src="images/tile1.png">  
                            <p>Imagine an international gateway where good and merchandise flow across borders. Where countries lower taxes, reduce red tape, and eliminate road blocks. Where companies import goods and merchandise directly into a Free Trade Zone - and then ship products out duty free.</p>
                            <p>The Miami Free Trade Zone connects North America, Europe and Asia to Latin America and Caribbean via direct air and sea transportation links, plus rail and expressway. Operatred by FTZ World SERVICES, the 47-acre Zone (#372) saves companies money and time.</p>
                            <p><ins><a href="https://www.w3schools.com">More about Free Trade Zone ></a></ins></p>
                        </div>
                        <div class="mini-zones">
                            <img src="images/tile2.png"> 
                            <p>FTZ World Services is your ticket to the world. We're the licensed operator of the Miami Free Trade Zone, the "Gateway to the Americas." We process as much as $1 billion in goods from more than 70 countries each year.</p>
                            <p>A leader in free trade zone operations, FTZWS works magic behind the scenes, offering logistical and operational excellence. FTZWS's many services include technology, public warehousing, yard storage and on-site U.S. Customs. Other U.S. free trade zones also benefit from our technological support and operational consulting.</p>
                            <p><ins><a href="https://www.w3schools.com">Request a quote ></a></ins></p>  
                        </div>
                        <div class="mini-zones">
                            <img src="images/tile3.png">
                            <p>FTZ World Service has the unique advantage of being the licensed operator of the Miami Free Trade Zone. We offer state-of-the-art facilities and a stellar track record in zone management, plus technological support, warehousing, and storage. Because FTZWS understands U.S. Customs rules, we can use our software and logistical expertise to speed up your paperwork, remove road blocks, and get products to market cheaper and faster. We save companies across multiple industries thousands of dollars per month in fees. We'll give you less to manage and more dollars to keep in your pocket.</p>
                            <p><ins><a href="https://www.w3schools.com">More about what we offer ></a></ins></p> 
                        </div>
                    </div>
                </div>
                <div class="footer">
                        <p style="margin-top:10px">Copyright ©2014 FTZ World Services. All Rights Reserved. <ins>Contact Us</ins> | <ins>Request a Quote</ins></p>    
                </div>
            </div>
        </body>

从描述中,我了解到,当页面的宽度和高度发生更改时,如果这是您的问题,那么 div 会在其他 div 上重合或重叠,那么您最好首先了解绝对位置和相对位置以及宽度高度边距边框填充等以像素和百分比为单位有很多可用的网站,例如 w3schools 供您浏览。此外,请浏览以下链接 CSS - Percentages or Pixels?

Why shouldn't I use position:absolute for positioning everything?

下面的例子可以作为参考。

【讨论】:

  • 请为 ref 添加一些代码,以便用户了解如何解决问题。
  • 是的,请您对我的代码进行一些修改,以便我理解。我不太确定你在 :// 得到了什么
【解决方案2】:

你应该看看Div Tags

body {
  background-image: url(gradient.png);
  background-repeat: no-repeat;
  background-size: cover;
}

.wrapper {
  position: absolute;
  height: 500px;
  width: 1000px;
}

h1.heading {
  color: #046289;
  font-size: 50px;
  margin-top: 100px;
  text-align: center;
  font-family: 'Poppins', sans-serif;
}

p.heading {
  color: #046289;
  font-family: 'Poppins', sans-serif;
  font-size: 20.8px;
  font-weight: 600;
  position: relative;
  margin-left: 70px;
  top: 60px;
}

p.heading1 {
  color: #046289;
  font-family: 'Poppins', sans-serif;
  font-weight: 400;
  position: relative;
  margin-left: 70px;
  top: 50px;
}

img.aml {
  width: 280px;
  height: 280px;
  position: absolute;
  margin-left: 360px;
  bottom: 30px;
}

iframe.livevid {
  position: absolute;
  margin-left: 840px;
}

p.vid {
  color: #046289;
  font-family: 'Poppins', sans-serif;
  font-size: 20.8px;
  font-weight: 600;
  position: absolute;
  margin-left: 840px;
  top: 313px;
}

p.vid1 {
  color: #046289;
  font-family: 'Poppins', sans-serif;
  font-weight: 400;
  position: absolute;
  margin-left: 840px;
  top: 363px;
}

a {
  text-decoration: none;
}

p a:link {
  color: #4204a5;
}

p a:visited {
  color: #4204a5;
}

p a:hover {
  color: #71a3f2;
}


/*
BELOW - NAVIGATION BAR
*/

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  width: 100%;
}

li {
  float: left;
}

.spacefornav {
  margin-left: 462px;
}

li a:hover {
  color: #71a3f2;
}

div.nav {
  color: #046289;
}

li a {
  display: inline-block;
  color: #046289;
  text-align: center;
  padding: 8px 10px;
  text-decoration: none;
  font-family: 'Poppins';
  sans-serif;
  margin: 0px 20px;
  font-weight: 500;
  cursor: pointer;
}
<!DOCTYPE html>
<html lang="en-US">

<head>
  <title>Childish Gambino</title>
  <meta charset="UTF-8">
  <meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
  <link href="https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700&amp;subset=devanagari,latin-ext" rel="stylesheet">
  <link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>

<body>
  <div class="wrapper">
    <h1 class="heading">CHILDISH GAMBINO</h1>
    <ul>
      <div class="nav">
        <li class="spacefornav"><a href="home.html">Home</a></li>
        <li><a href="about.html">About</a></li>
        <li><a href="music.html">Music</a></li>
        <li><a href="contact.html">Contact</a></li>
      </div>
    </ul>
    <p class="heading">"AWAKEN MY LOVE!"</p>
    <p class="heading1">
      Childish Gambino's latest
      <br> and freshest album is
      <br> AVAILABLE NOW on <a href="https://itunes.apple.com/us/album/awaken-my-love/id1173655524" target="_blank">iTunes</a>,
      <br>
      <a href="https://play.spotify.com/album/4xnq1L6P551Qcb9gBXNMK7" target="_blank">Spotify</a> and <a href="https://play.google.com/store/music/album?id=Bc3g3mmud6z3xm6todpsldagple&tid=song-Tdcdooebkcepkmj7amghovz2ncq&hl=en" target="_blank">Google Play Music</a>
    </p>
    <img src="images/awakenmylove.jpg" class="aml" title="'Awaken My Love!' album art" alt="'Awaken My Love' album art">
    <<iframe width="280" height="158" src="https://www.youtube.com/embed/6v7W513Wj3g?rel=0" frameborder="0" allowfullscreen class=livevid></iframe>
      <p class="vid">Watch Now!</p>
      <p class="vid1">Childish Gambino performing '3005'<br>live at Splendor In The Grass!</p>
  </div>
</body>

</html>

刚刚添加了一个固定的包装器。 (A Div) 并给它一个固定的大小。 (不推荐)

.wrapper {
  position: absolute;
  height: 500px;
  width: 1000px;
}

您可能想了解 div 标签,然后将 div 标签添加到您的内容中。

【讨论】:

  • 那我下次做网站应该怎么做。我哪里做错了?
  • Div 标签为您的 HTML 代码提供了一个“锚”,供 CSS 规则使用。一个常见的例子可能是#RightColumn div。
    这里有一些内容
【解决方案3】:

我假设您希望您的网站通过声音来适应多种不同的屏幕尺寸。使用媒体查询。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-08
    • 2021-02-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多