2016-05-04 10 views
-1

Wenn die Seite ausgezoomt ist, wie kann ich die Webseite und den gesamten Inhalt verkleinern? Dies ist vor dem Herauszoomen. Diese This is before zooming out ist nach Auszoomen After zooming outWie verkleinern Sie die gesamte Seite, wenn sie ausgezoomt ist?

Wie Mitte der Seite zu schrumpfen, während Auszoomen?

-Code im mit ist

<title>Demo</title> 
<head>This is a demo</head> 
<style> 
#my-div{ 

    margin-left: auto; 
    margin-right: auto; 

    width: 80%; 
    height: 50%; 
} 
#nav 
{ 
background-color: red; 
float: left; 
width: 200px; 
position:relative; 

} 

#detail 
{ 
background-color: green; 
float : right; 
width: 800px; 
position:relative; 
} 

div.testDetail 
{ 
margin-top:10px; 
margin-left:20px; 
margin-right:20px; 
margin-bottom:10px; 
} 

#container 
{ 
width:1000px; 
position:relative; 
} 
</style> 

<hr> 
<body style="background-color:blue";> 


<div id="my-div"> 
<div id="container"> 
<div id="nav"> 
    <ul>Tests</ul> 
</div> 
<div id="detail"> 
    <div class="testDetail"> 
     <image style="float:right;margin:5px;" src="test1.jpg" width="50px" height="50px"/> 
     <image style="float:right;margin:5px;" src="test2.jpg" width="50px" height="50px"/> 
     <image style="float:right;margin:5px;" src="test3.jpg" width="50px" height="50px"/> 
     <image style="float:right;margin:5px;" src="test4.jpg" width="50px" height="50px"/> 
     <h3>Title</h3> 
     <p>Testing</p> 
    </div> 
    </div> 
    <hr> 
</div> 
</div> 
<body> 
+0

Bitte Beispielcode angeben. Sie könnten wahrscheinlich "margin: auto" hinzufügen, um sicherzustellen, dass der Inhalt zentriert ist. – phpheini

+0

bieten Code Beispiel, und was Sie bisher versucht haben. – LorDex

+0

ja, ich habe diesen Beispielcode –

Antwort

1

Vielleicht können Sie Codebeispiel teilen?

Sie können versuchen, CSS-Eigenschaft zu verwenden:

margin:0 auto; um Ihren Blockes zum Zentrum (vielleicht Körper in Ihrem Fall).

Grüße.

[Bearbeiten]

Zuerst haben Sie Fehler in Ihrem HTML:

  1. schließen Body-Tag richtig
  2. entfernen ';' in offenen Body-Tag
  3. Wrap-Code mit HTML-Tag
  4. hinzufügen Doctype (html5 in meinem Code verwendet wird)
  5. Put-Stil innerhalb head-Tag
  6. put Titel innerhalb head-Tag
  7. entfernen Textknoten in head-Tag

Bitte auch einrücken.

[Bearbeiten]

Hier Code funktioniert nach Korrekturen, verwende ich Prozent statt Pixelabmessung, genießen:

<!doctype html> 
<html lang="en"> 
    <head> 
     <meta charset="UTF-8"> 
     <title>Demo</title> 
     <style> 
      body{ 
       margin: 0 auto; 
       width: 100%; 
      } 

      #my-div{ 
       margin: 0 auto; 
       width: 80%; 
       height: 50%; 
      } 

      #nav 
      { 
       background-color: red; 
       float: left; 
       width: 20%; 
       position:relative; 

      } 

      #detail 
      { 
       background-color: green; 
       float : right; 
       width: 80% 
       position:relative; 
      } 

      div.testDetail 
      { 
       margin-top:10px; 
       margin-left:20px; 
       margin-right:20px; 
       margin-bottom:10px; 
      } 

      #container 
      { 
       width:auto; 
       position:relative; 
      } 
     </style> 
    </head> 
    <body style="background-color:blue"> 
     <div id="my-div"> 
      <div id="container"> 
       <div id="nav"> 
        <ul>Tests</ul> 
       </div> 
       <div id="detail"> 
        <div class="testDetail"> 
         <image style="float:right;margin:5px;" src="test1.jpg" width="50px" height="50px"/> 
         <image style="float:right;margin:5px;" src="test2.jpg" width="50px" height="50px"/> 
         <image style="float:right;margin:5px;" src="test3.jpg" width="50px" height="50px"/> 
         <image style="float:right;margin:5px;" src="test4.jpg" width="50px" height="50px"/> 
         <h3>Title</h3> 
         <p>Testing</p> 
        </div> 
       </div> 
       <hr> 
      </div> 
     </div> 
    </body> 
</html> 
+0

ja geteilt ich habe diesen Code geteilt –

0

Sie Bootstrap-Framework in CSS verwenden sollten

1

Hier ist Ihre Lösung: https://jsfiddle.net/xkzomtvd/2/

Halten Sie die ganze Seite in main div und wenden Klasse auf diese fo r Beispiel:

alle Inhalte hier

geben Stil zu dieser Klasse:

.wrapper {

margin:0 auto; 
max-width:400px; /* required width fixed or percentage */ 
background:red; 

}

0

Sie die Seite tatsächlich Zentrierung, es ist nur nicht klar, jetzt sofort. Der Grund ist die Breite von 80% in Ihrem # my-div-Element, während alle ihre untergeordneten Elemente in einem 1000px-Container sind.

Dies wird Ihr Problem lösen:

#my-div{ 
    width: 1000px; 
} 

Sie max-width alternativ verwenden könnte, aber für Ihr Beispiel, gibt es wirklich keinen Grund zu.

Verwandte Themen