简体   繁体   English

拉伸背景图像以占据 div 的整个高度

[英]Stretch background image to occupy full height of div

I've divided screen to 2 parts and want to have same height for both the divs.我已将屏幕分为 2 部分,并希望两个 div 具有相同的高度。

What I want is left side div should have same height and should occupy the height same as right part.我想要的是左侧 div 应该具有相同的高度,并且应该占据与右侧相同的高度。

When I see this screen in mobile format it is not showing proper.当我以移动格式看到此屏幕时,它显示不正确。

I tried using height 100% but not working.我尝试使用高度 100% 但不起作用。 What am I missing over here?我在这里错过了什么?

This is what I've tried.这是我试过的。 Link to codepen代码笔链接

 #main_header_div{ color: white; position: absolute; width: 100%; height: inherit; top: 0; background-color: rgba(152, 38, 38, 0.7); color:white; } #div_1_text { margin-top: 15%; margin-left: 15%; color: white; } #div_2_text { margin-top: 5%; margin-left: 15%; color: white; } #div_3_text { margin-left: 15%; color: white; } #div_4_button { margin-left: 15%; color: white; }
 <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"> </head> <body> <div class="row"> <div class="col-md-6" style="padding-right: 0; padding-left: 0;"> <div class="jumbotron jumbotron-fluid" style="height:100%; background : url('https://live.staticflickr.com/65535/50566935741_ba2c76c194_b.jpg');"> <div id="main_header_div"> <h3 id="div_1_text">Image Taken From Flickr !</h3> <p id="div_2_text">For DEMO</p> <p id="div_3_text">TEXT 3</p> <button id="div_4_button" type="button" class="btn btn-outline-secondary">BUTTON</button> </div> </div> </div> <div class="col-md-6" style="padding-right: 0; padding-left: 0;"> <div style="width:100%;"> <img class="image-responsive" src="https://live.staticflickr.com/65535/50566935741_ba2c76c194_b.jpg" /> </div> </div> </div> </body> </html>

I found this (I cheat a little by given a fix size to the div : myDiv , who has the background-image because I think that background-image doesn't have size):我发现了这个(我通过给div一个固定大小作弊: myDiv ,谁有背景图像,因为我认为背景图像没有大小):

 .myDiv{ height: 680px; /*manual check to get image height*/ } #main_header_div{ color: white; position: absolute; width: 100%; height: inherit; top: 0; background-color: rgba(152, 38, 38, 0.7); } #div_1_text { margin-top: 15%; margin-left: 15%; color: white; } #div_2_text { margin-top: 5%; margin-left: 15%; color: white; } #div_3_text { margin-left: 15%; color: white; } #div_4_button { margin-left: 15%; color: white; }
 <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"> </head> <body> <div class="row"> <div class="col-md-6" style="padding-right: 0; padding-left: 0;"> <div class="jumbotron jumbotron-fluid myDiv" style="background : url('https://live.staticflickr.com/65535/50566935741_ba2c76c194_b.jpg');"> <div id="main_header_div"> <h3 id="div_1_text">Image Taken From Flickr !</h3> <p id="div_2_text">For DEMO</p> <p id="div_3_text">TEXT 3</p> <button id="div_4_button" type="button" class="btn btn-outline-secondary">BUTTON</button> </div> </div> </div> <div class="col-md-6" style="padding-right: 0; padding-left: 0;"> <div style="width:100%;"> <img class="image-responsive" src="https://live.staticflickr.com/65535/50566935741_ba2c76c194_b.jpg" /> </div> </div> </div> </body> </html>

jQuery<div> 背景图像全尺寸拉伸</div><div id="text_translate"><p>基本上我要做的是用纯 HTML、CSS 和 jQuery 重新创建这个站点。</p><p> 目前该网站在搜索结果中的表现不太好,显然是因为它是 Flash,所以这就是我要解决的问题。</p><p> 我正在寻找的东西非常复杂,但我很乐意为所需的任何单独部件提供解决方案,并且我会弄清楚如何将它们放在一起。 我在互联网上到处搜索,并打电话找到任何接近我想要的东西。</p><p> 这就是我需要的。 主要是我担心的图像DIV...</p><ul><li> 我有两个 DIV,一个将保存图像,另一个将保存其下方的链接。 顶部 DIV 的高度为 70%,第二个为 30%。</li><li> 70% 高度顶部 DIV 中的图像应拉伸到<strong>至少填充</strong>DIV。 我的意思是图像周围不应该有空白,但显然图像也需要保持其纵横比。</li><li> 如果可能的话,我希望一些图像能够在这个 DIV 中旋转,具有简单的淡入淡出效果,可能是从 XML 文件加载的(但不一定)。</li></ul><p> 这是在我头上还是很容易做到?</p><p> 谢谢你提供的所有帮助。</p></div> - jQuery <div> background image full size stretch

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery<div> 背景图像全尺寸拉伸</div><div id="text_translate"><p>基本上我要做的是用纯 HTML、CSS 和 jQuery 重新创建这个站点。</p><p> 目前该网站在搜索结果中的表现不太好,显然是因为它是 Flash,所以这就是我要解决的问题。</p><p> 我正在寻找的东西非常复杂,但我很乐意为所需的任何单独部件提供解决方案,并且我会弄清楚如何将它们放在一起。 我在互联网上到处搜索,并打电话找到任何接近我想要的东西。</p><p> 这就是我需要的。 主要是我担心的图像DIV...</p><ul><li> 我有两个 DIV,一个将保存图像,另一个将保存其下方的链接。 顶部 DIV 的高度为 70%,第二个为 30%。</li><li> 70% 高度顶部 DIV 中的图像应拉伸到<strong>至少填充</strong>DIV。 我的意思是图像周围不应该有空白,但显然图像也需要保持其纵横比。</li><li> 如果可能的话,我希望一些图像能够在这个 DIV 中旋转,具有简单的淡入淡出效果,可能是从 XML 文件加载的(但不一定)。</li></ul><p> 这是在我头上还是很容易做到?</p><p> 谢谢你提供的所有帮助。</p></div> - jQuery <div> background image full size stretch 背景图像伸展Div的100%高度 - Background Image Stretch 100% Height of Div 拉伸div背景图片的宽度并设置高度 - Stretch width of div background image with set height div内的“拉伸”背景图片-100%的高度 - 'Stretch' background image within a div - 100% height 在div上拉伸图像背景或在div中拉伸完整背景图像 - stretch image background on a div or full backgound image in a div 背景颜色无法拉伸div的整个高度 - background color doesn't stretch full height of div 如何拉伸图像以覆盖div的整个宽度和高度? (使用Flexbox) - How to stretch an image to cover full width and height of the div? (Using Flexbox) 如何制作 <div> 占满 <td> - How to make a <div> occupy the full height of <td> 如何放置不拉伸div高度的背景图像? - How to place a background image that does not stretch the height of a div? 浏览器上的 Div 背景图像全高 - Div background image full height on browser
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM