Divs看起来不错,但是一旦加载了图像URL,它就不会停留在div中。这与溢出有关吗?我的印象是图像是100%会拉伸到指定的高度和宽度的divs
-------------------------------------------
-------------------------------------------
-------------------------------------------
-------------------------------------------
-------------------------------------------
-------------------------------------------
.sec3head {
padding-top: 50px;
padding-bottom: 50px;
width: 100%;
height: 240px;
text-align: center;
border: px solid red;
background: rgba(0, 0, 0, 0.5);
color: #FFF;
border-radius: 10px;
}
.sec3head4 {
/* pic */
display: inline-block;
width: 30%;
height: 200px;
text-align: center;
border: 1px solid red;
color: #FFF;
border-radius: 5px;
}
.sec3head5 {
/* text */
display: inline-block;
width: 60%;
height: 200px;
align-content: start;
text-align: center;
border: px solid red;
background: rgba(0, 0, 0, 0.5);
color: #FFF;
border-radius: 10px;
}
<div class="sec3head">
<div class="sec3head4">
<img src="images/" alt="alt text" height="100%" width="100%" />
</div>
<!--sec3headt4-->
<div class="sec3head5">
text
</div>
<!--sec3headt5-->
</div>
<!--sec3head-->
<div class="sec3head">
<div class="sec3head5">
text
</div>
<!--sec3headt5-->
<div class="sec3head4">
<img src="images/" alt="alt text" height="100%" width="100%" />
</div>
<!--sec3headt4-->
</div>
<!--sec3head-->
<div class="sec3head">
<div class="sec3head4">
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxAQEA8QDRAPEA8PDw8PDw8QDw8ODw0PFREXFxURFRUYHSggGBolGxUVITEhJSkrLi8vFx82ODMsNygtLisBCgoKBQUFDgUFDisZExkrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrK//AABEIALcBEwMBIgACEQEDEQH/xAAbAAEAAgMBAQAAAAAAAAAAAAAAAgMBBAUGB//EADcQAAIBAwIEBAUCBQMFAAAAAAABAgMEERIhBTFBUQYiYXETMoGRoRRSByNCYnIWseEkM8Hw8f/EABQBAQAAAAAAAAAAAAAAAAAAAAD/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEA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AAAAAAAAAAAAAAAAAMMAADBkAYwMAZAhNFM4lk5FUpAUVImpVRt1p7GjUmBW4iMQTggMMiyciACm8NHfta2uKfVbM8/g2bS50Sz0fP2A7oIwkmk1umSAAAAAAAAAAAAAAAAAAAAAAABgAAAAAAEJRJmGBrzpvuimVKXdfk3JIpkBqVKb7mpOCRv1DTqICqMS5RFOBOSA15orLKhBAYYMtGEBfZXrpvD3i+nb1R26NWM1mLyjzrRinVnTeqD910f0A9MDnWfFYT2n5Jevyv6nRTAAAAAAAAAAAAAAAAAGGwAAAAAAAAAAAAjIokABRVNeUQAJwRioZAGpMjgADMiCAAyGjAAqqUiy3vKlLk8x/a90AB17HikKr04cZ/te6+jN8AAAAAAA/9k="
alt="alt text" height="100%" width="100%" />
</div>
<!--sec3headt4-->
<div class="sec3head5">
text
</div>
<!--sec3headt5-->
</div>
<!--sec3head-->
答案 0 :(得分:0)
您只缺少一点CSS。
您需要使用if
。
vertical-align属性会影响 内联级元素生成的框的线框。
顶部
将对齐的子树的顶部与行框的顶部对齐。
https://www.w3.org/wiki/CSS/Properties/vertical-align
一面不要在图像的高度和宽度上都使用100%。添加实际图像尺寸,然后使用css将高度和宽度更改为100%。
还要阅读有关div定位以及何时使用display inline-block和何时使用css表的信息。
除了使用需要文字环绕的图片外,请勿使用float来放置其他任何内容。不是为了元素。
vertical-align:top;
.sec3head {
padding-top: 50px;
padding-bottom: 50px;
width: 100%;
height: 240px;
text-align: center;
border: px solid red;
background: rgba(0, 0, 0, 0.5);
color: #FFF;
border-radius: 10px;
}
.sec3head4 {
/* pic */
display: inline-block;
width: 30%;
height: 200px;
text-align: center;
border: 1px solid red;
color: #FFF;
border-radius: 5px;
vertical-align:top;
}
.sec3head5 {
/* text */
display: inline-block;
width: 60%;
height: 200px;
align-content: start;
text-align: center;
border: px solid red;
background: rgba(0, 0, 0, 0.5);
color: #FFF;
border-radius: 10px;
vertical-align:top;
}
答案 1 :(得分:-2)
您应该使用float: right;
或float: left;
放置DOM块元素。
.sec3head {
padding-top: 50px;
padding-bottom: 50px;
width: 100%;
height: 240px;
text-align: center;
border: px solid red;
background: rgba(0, 0, 0, 0.5);
color: #FFF;
border-radius: 10px;
}
.sec3head4 {
/* pic */
display: inline-block;
width: 30%;
height: 200px;
text-align: center;
border: 1px solid red;
color: #FFF;
border-radius: 5px;
}
.sec3head5 {
/* text */
display: inline-block;
width: 60%;
height: 200px;
float: right;
align-content: start;
text-align: center;
border: px solid red;
background: rgba(0, 0, 0, 0.5);
color: #FFF;
border-radius: 10px;
}
<div class="sec3head">
<div class="sec3head4">
<img src="images/" alt="alt text" height="100%" width="100%" />
</div>
<!--sec3headt4-->
<div class="sec3head5">
text
</div>
<!--sec3headt5-->
</div>
<!--sec3head-->
<div class="sec3head">
<div class="sec3head5">
text
</div>
<!--sec3headt5-->
<div class="sec3head4">
<img src="images/" alt="alt text" height="100%" width="100%" />
</div>
<!--sec3headt4-->
</div>
<!--sec3head-->
<div class="sec3head">
<div class="sec3head4">
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxAQEA8QDRAPEA8PDw8PDw8QDw8ODw0PFREXFxURFRUYHSggGBolGxUVITEhJSkrLi8vFx82ODMsNygtLisBCgoKBQUFDgUFDisZExkrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrK//AABEIALcBEwMBIgACEQEDEQH/xAAbAAEAAgMBAQAAAAAAAAAAAAAAAgMBBAUGB//EADcQAAIBAwIEBAUCBQMFAAAAAAABAgMEERIhBTFBUQYiYXETMoGRoRRSByNCYnIWseEkM8Hw8f/EABQBAQAAAAAAAAAAAAAAAAAAAAD/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwD7iAAAAAABsDyXiK1cpPG0nLGy+Zep0eE8N+HFb/8AP1NbxTV+HocM5nOKk9vIlvt7/wDk7tm8wj/igLKccEzBkAAAAAAwRZIxICtgACOCEixkJAUzKplsimowKJkME5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AAAAAAAAAAAABgAAAAAAEJRJmGBrzpvuimVKXdfk3JIpkBqVKb7mpOCRv1DTqICqMS5RFOBOSA15orLKhBAYYMtGEBfZXrpvD3i+nb1R26NWM1mLyjzrRinVnTeqD910f0A9MDnWfFYT2n5Jevyv6nRTAAAAAAAAAAAAAAAAAGGwAAAAAAAAAAAAjIokABRVNeUQAJwRioZAGpMjgADMiCAAyGjAAqqUiy3vKlLk8x/a90AB17HikKr04cZ/te6+jN8AAAAAAA/9k="
alt="alt text" height="100%" width="100%" />
</div>
<!--sec3headt4-->
<div class="sec3head5">
text
</div>
<!--sec3headt5-->
</div>
<!--sec3head-->