简体   繁体   English

文字和背景图片上方的按钮

[英]Text and button on top of background image

I am trying to add text and a button on top of a background image I cannot figure out the CSS for the margins and positions on liquid page.If you can steer me in the right direction or help. 我正在尝试在背景图片上方添​​加文本和按钮,因此我无法弄清楚CSS在液体页面上的边距和位置。如果您可以引导我正确的方向或提供帮助。 Thank you! 谢谢!

 .feature_home{ margin:? position:? } .feature_image{ margin:? position:? } .feature_text{ margin:? position:? } .feature_button{ margin:? position:? } 
 <div class="feature_home"> <img class="feature_image" alt="Thanks For your guys help" src="images/xyz.com"> <p class="feature_text">I really appreciate your guys help!</p> <a class="feature_button" href="/xyz-101/">Thank You</a> </div> </div> 

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x background Image               x                
x                   Text Here:   X
x                   Text Here:   x                             
x                                x
x                   Button Here: x  
x                                x
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

It wont let me ad an image until I get 10 reputations to post image. 在获得10个声誉发布图像之前,它不会让我做广告。

You can just get rid of <img> and use background-image style on .feature_home and give it a position:relative; 您可以摆脱<img>并在.feature_home上使用background-image样式,并为其指定一个position:relative; so you can position feature_home and feature_button like you want it. 因此您可以根据需要feature_homefeature_button

Here you have HTML code: 这里有HTML代码:

<div class="feature_home" style="background-image:url(image);">
   <p class="feature_text">I really appreciate your guys help!</p>
   <a class="feature_button" href="/xyz-101/">Thank You</a>
</div>

And here is CSS: 这是CSS:

.feature_home{
    width:300px;
    height:200px;
    position:relative;
    display:block;
    background-position:center center;
    background-size:100%;
}
.feature_text{
    position:absolute;
    right:2px;
    bottom:15px;
}
.feature_button{
    right:2px;
    bottom:2px;
    position:absolute;
}

All the values are for example :) 所有值都是例如:)

http://jsfiddle.net/cjtdhcLr/ http://jsfiddle.net/cjtdhcLr/

Is this what you are looking for? 这是你想要的?

 .feature_home{ position: relative; display: table-cell; vertical-align: bottom; text-align: right; width: 350px; /* image width */ height: 150px; /* image height */ } .feature_image{ position: absolute; top: 0; left: 0; z-index: -1; } 
 <div class="feature_home"> <img class="feature_image" alt="Thanks For your guys help" src="http://placehold.it/350x150"> <p class="feature_text">I really appreciate your guys help!</p> <a class="feature_button" href="/xyz-101/">Thank You</a> </div> 

http://jsfiddle.net/7zvL5zto/2/ http://jsfiddle.net/7zvL5zto/2/

Here is something that will work, and instead of the red background choose your image 这是可行的方法,请选择红色图像而不是红色背景

 .feature_home { width:400px; background:red; float:left; padding:15px } p { text-align:right; } a { float:left; text-align:right; width:100%; } 
 <div class="feature_home"> <p class="feature_text">I really appreciate your guys help!</p> <a class="feature_button" href="/xyz-101/">Thank You</a> </div> 

<style>
.feature_home{
background-image:url("http://2.bp.blogspot.com/-biBlhcDYdZI/ULjLQeeCwzI/AAAAAAAAAmo/T9M9YTcMeWY/s400/BackgroundPanel.pngg");
background-repeat:no-repeat;
padding-left:25px;
padding-right:25px;
height:200px;
width:321px;
position:absolute;
  }
.feature_button{
color:white;
position:absolute;
right:30px;
  }
</style>

<div class="feature_home">
<p class="feature_text">I really appreciate your guys help!</p>
<a class="feature_button" href="/xyz-101/">Thank You</a>
</div>
</div>

Use position:absolute; 使用位置:绝对; http://www.w3schools.com/css/css_positioning.asp http://www.w3schools.com/css/css_positioning.asp

Absolute Positioning An absolute position element is positioned relative to the first parent element that has a position other than static. 绝对位置绝对位置元素是相对于具有非静态位置的第一个父元素放置的。 If no such element is found, the containing block is : 如果找不到这样的元素,则包含的块为:

This should be enough to get you started. 这应该足以让您入门。 I would not use an actual img. 我不会使用实际的img。 You would be better assigning the image as the background of your feature_home div. 您最好将图像分配为feature_home div的背景。 See the css background-image. 参见css背景图片。

if you have to use the img then you will need to use z-index to position the elements in layers with the image set below all of the other items. 如果必须使用img,则需要使用z-index将元素放置在图像设置在所有其他项目下面的图层中。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM