2016-04-22 11 views
-1

Ich versuche, Bilder als Hintergrund hinzuzufügen, und ich muss Text auf beiden schreiben. Das Problem, mit dem ich konfrontiert bin, ist die Lücke s/w zwei Bilder. Ich weiß nicht, warum es mir eine Lücke zeigt.Zwei Bilder nebeneinander und Text darauf

<div class='imgcontainer'> 
    <div id="first"> <h4 > SYRIAN CRISIS </h4> 
     <p > We are organizing a conference in April 2016 on 
      water and humanitarian aspects of the Syrian crisis. 
      Click <a href="projectc.html">here</a> to learn about the crisis and our 
      conference.</p></div> 
    <div id="second"><h2>SMALLHOLDER</h2><h3> AGRICULTURE</h3> 
     <p>We are organizing a workshop in April 2016 on smallholder irrigation in Sub-Saharan Africa. Click here 
      to learn about the challenge of agriculture in the 
      region and our workshop.</p> 
    </div> 
    <div id="clear"></div> 
</div> 






#first { 
    width: 680px; 
    background: url('../images/banner-img1.jpg'); 
    float: left; 
    background-repeat: no-repeat; 
    height: 440px; 
    margin: auto; 
} 
#second { 
    width: 650px; 
    float: right; 
    background: url('../images/banner-img2.jpg'); 
    height: 440px; 
    margin: auto; 
    background-repeat: no-repeat; 

} 
+2

Sie schwebte die divs links und rechts. Wenn Ihr Bildschirm größer ist als die Summe der Breiten dieser Divs, erhalten Sie eine Lücke. –

+0

Darf ich wissen, wie ich das beheben kann? – sahil

+0

Ja, versuchen Sie entweder schweben beide links, oder die Anzeige jedes Div in Inline-Block setzen –

Antwort

1

Ich glaube, Ihr Bildschirm ist breiter als 680px + 650px = 1330px

Erste div nach links ausgerichtet ist, zweite auf der rechten Seite, haben beide Breiten festgelegt .. wenn Ihr Browser Breite>1330px Sie werden eine Lücke haben zwischen diesen

+0

Wenn ich mehr px packe, dann geht ein Bild nach unten. – sahil

+0

was soll ich tun, um es dann zu beheben? Ja, ich gab Container der Website zu1350px – sahil

+0

Verwenden Sie Prozent anstelle von Pixeln –

0

DEMO

CSS divs:

.imgcontainer { 
    position: relative; 
} 

.right, 
.left { 
    width: 50%; 
    position: absolute; 
} 

.right { 
    right: 0; 
} 

.left { 
    left: 0; 
} 

#first { 
    width: 50%; 
    position: absolute; 
    background: url('../images/banner-img1.jpg'); 
    left: 0; 
} 

#second { 
    width: 50%; 
    position: absolute; 
    background: url('../images/banner-img2.jpg'); 
    right: 0; 
} 

HTML:

<div class='imgcontainer'> 
    <div id="first"> 
    <h4> SYRIAN CRISIS </h4> 
    <p> We are organizing a conference in April 2016 on water and humanitarian aspects of the Syrian crisis. Click <a href="projectc.html">here</a> to learn about the crisis and our conference. 
    </p> 
    </div> 
    <div id="second"> 
    <h2>SMALLHOLDER</h2> 
    <h3> AGRICULTURE</h3> 
    <p>We are organizing a workshop in April 2016 on smallholder irrigation in Sub-Saharan Africa. Click here to learn about the challenge of agriculture in the region and our workshop.</p> 
    </div> 
    <div id="clear"></div> 
</div> 
+0

hat nicht für mich funktioniert. Problem auf der gesamten Website verursachen – sahil

+0

Haben Sie die Geige gesehen? Es funktioniert. –

Verwandte Themen