2017-10-27 3 views
-1

Ich versuche parallax scrolling und alles funktioniert gut. Aber was ich will, ist, dass die Hintergrundbilder die gesamte Breite der Seite (wie in Rand zu Rand) verwenden, aber es ist ein kleiner Rand links auf beiden Seiten des Hintergrunds.Wie Hintergrundbildbreite als Rand zu Rand eingestellt werden

Hier ist mein Code:

.container{ 
 
\t max-width: 100%; 
 
\t margin: 0 auto; 
 
\t background: aqua; 
 
\t font-size: 24px; 
 
\t padding: 25px; 
 
} 
 
.parallax{ 
 
\t width: 100%; 
 
\t background: url('Baradari.jpg') no-repeat center; 
 
\t background-size: cover; 
 
\t background-attachment: fixed; 
 
\t height: 500px; 
 
} 
 
.parallax2{ 
 
\t width: 100%; 
 
\t background: url('rumi-darwaza.jpg') no-repeat center; 
 
\t background-size: cover; 
 
\t background-attachment: fixed; 
 
\t height: 500px; 
 
} 
 
.parallax3{ 
 
\t width: 100%; 
 
\t background: url('rumi-darwaza.jpg') no-repeat center; 
 
\t background-size: cover; 
 
\t background-attachment: fixed; 
 
\t height: 500px; 
 
}
<!DOCTYPE html> 
 
<html> 
 
\t <head> 
 
\t \t <meta charset="utf-8"> 
 
\t \t <title>Parallax</title> 
 
\t \t <link rel="stylesheet" href="style.css"> 
 
\t </head> 
 
\t <body> 
 
\t \t <div class="container"> 
 
\t \t \t <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
 
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 
 
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. 
 
It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> 
 
\t \t </div> 
 
\t \t <div class="parallax"> 
 

 
\t \t </div> 
 
\t \t <div class="container"> 
 
\t \t \t <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
 
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 
 
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. 
 
It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> 
 
\t \t </div> 
 
\t \t <div class="parallax2"> 
 

 
\t \t </div> 
 
\t \t <div class="container"> 
 
\t \t <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
 
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 
 
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. 
 
It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> 
 
\t \t </div> 
 
\t \t <div class="parallax3"> 
 

 
\t \t </div> 
 
\t \t <div class="container"> 
 
\t \t \t <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
 
\t Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 
 
\t It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. 
 
\t It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p> 
 
\t \t </div> 
 
\t </body> 
 
</html>

versuchte ich position: absolute; und left: 0px; in allen Parallaxe Klassen einstellen, aber es würde alle Bilder machen zusammen kommen und die schriftlichen Teil versteckt wird. bitte helfen!

Antwort

1
body { margin:0; } 

sollte Ihr Problem beheben

1

Jedes HTML-Element einige Standard-Marge hat. Versuchen Sie, alle Ränder zuerst auf 0 zu setzen.

*{ margin: 0px;} 

Sie können auch versuchen, 0 Ränder nur für HTML- oder Body-Tags festzulegen. Bitte überprüfen CSS Standardwerte hier Referenz:

https://www.w3schools.com/cssref/css_default_values.asp

1

Der Body-Tag hat den 8px einen Standard-Marge mit ihm verbunden ist. Sie müssen diesen Rand mit dem Code in Dirks Antwort auf 0 setzen. Tatsächlich hat jedes Element einen Standardrand und eine Standardfüllung, die damit verbunden sind. Um sicher zu gehen, dass Sie die totale Kontrolle über den Rand und das Padding jedes Elements haben, verwenden Sie den globalen Selektor * und setzen den Rand und den Abstand jedes Elements gleich 0 am oberen Rand Ihrer CSS-Datei.

* { 
    margin: 0; 
    padding: 0; 
}