2017-03-08 110 views
1

如何使.welcome-content-wrap类拉伸以适应其内容并仍保持我给出的透明样式?垂直拉伸div以适合内容

我明白,你通常不会添加背景图片像我有但就是为什么我做它像我有一个理由

.welcome-section{ 
 
\t position: relative; 
 
} 
 

 
.welcome-background{ 
 
\t max-width: 100%; 
 
\t display: block; 
 
\t height: auto; 
 
} 
 

 
.welcome-content-wrap{ 
 
\t position: absolute; 
 
\t top:10%; 
 
\t left: 0; 
 
\t right: 0; 
 
\t bottom: 10%; 
 
\t margin: 0 auto; 
 
\t max-width: 800px; 
 
\t background: rgb(0, 0, 0); 
 
\t background: rgba(0, 0, 0, 0.7); 
 
\t text-align: center; 
 
} 
 

 
.welcome-content-wrap img{ 
 
\t display: block; 
 
\t width: 50%; 
 
\t margin: 50px auto; 
 
} 
 

 
.welcome-content-wrap p{ 
 
\t color: #fff; 
 
\t margin: 25px; 
 
} 
 

 
.text-style{ 
 
\t font-family: outstanding; 
 
\t font-size: 0.75em; 
 
}
<div class="welcome-section"> 
 
\t <img class="welcome-background" src="images/menuBackground.jpg"> 
 
\t <div class="welcome-content-wrap"> 
 
\t \t <img src="images/welcomeTransparent.png"> 
 
\t 
 
\t \t <p> 
 
\t \t \t <span class="text-style">WELCOME</span> to Popsie's of Bramhope a modern, local<br> 
 
\t \t \t Yorkshire fish and chip shop. At Popsie's all our food is hand<br> prepared by Popsie's Dad in the shop's kitchen every day. 
 
\t \t </p> 
 
\t \t <p>All our fish is sourced from sustainable sources.</p> 
 
\t \t <p> 
 
\t \t \t We cook fish to order so that it isn't left to dry out under lights,<br> 
 
\t \t \t like in too many chip shops. 
 
\t \t </p> 
 
\t \t <p>Our potatoes are from local Yorkshire & Lincolnshire farms and<br> we pride ourselves on using the best and freshest ingredients.</p> 
 
\t 
 
\t \t <img id="image-m" src="images/shutterstock_164403170.jpg"> 
 
\t \t <img id="image-l" src="images/National-federation-of-fish-logo.png"> 
 
\t \t <img id="image-r" src="images/CSSMSClogo.png"> 
 
\t </div> 
 
</div>

回答

1

尝试在支架卸下max-width: 800px从您的css文件的.welcome-content-wrap类。

1

宽度:100%;

但是你也有一个最大宽度,你可能想要检查,如果这是阻止它。

2

我不完全知道你打算与absolute定位做的,但我认为你没有意味着horizontally - 因为这是已经覆盖 - 但vertically来代替。

如果我是对的,这可能是你在找什么? https://jsfiddle.net/tpfqk0v7/

我改变的是top:10%bottom: 10%,而是切换到margins

旁注:我刚添加的背景,使其更容易看到的实际变化。随着一切都是透明的,没有看到背景图像,这是有点困难;)

如果你真的意味着x轴/水平包装,那当然只是忽略我的答案。

+0

原始代码有'max-width:800px'。在查看比这更大的元素时,元素不会“水平拉伸”,因此完全可能他*实际上意味着水平*。如果您对这个问题不确定,或者认为OP出错,您应该对该问题发表评论,并要求澄清,而不是在您的答案中进行猜测。我不是说你不正确,我只是建议从OP得到澄清。 – justinw

+0

事情是,在有50个声望之前不能评论,所以怎么问? – Lichtbringer

+1

如果您无法评论,并且您对问题中的某些内容不确定,那么您可能不应提交潜在的低质量答案。 – justinw