简体   繁体   English

如何并排引导图像和文本,但是当屏幕较小时,文本会越过图像?

[英]How do I bootstrap an image and text side by side but when the screen is small the text goes over the image?

Basically, I want half the screen to be my image and the other half to have my text. 基本上,我希望屏幕的一半是我的图像,另一半是我的文本。 But if the screen is very small, I want the text to go over the image and the image and text shrink. 但是,如果屏幕很小,我希望文本覆盖图像,并且图像和文本缩小。 So far I have the big screen working, but when I go into small screen the text is still huge (making it go off the screen) and is still to the right of the image. 到目前为止,我已经可以使用大屏幕了,但是当我进入小屏幕时,文本仍然很大(使它离开屏幕)并且仍然在图像的右侧。

.html: html的:

<div class="container-fluid"> 
    <div class="row">
        <div class="col-xs-9 col-md-6">
            <img class="img-responsive" src="styles/pics/brainimg.png" alt="Brain Image" width="960" height="819">
        </div>
        <div class="col-xs-3 col-md-6">
            <div class="first"> 
                NAME HERE
            </div>
            <div class="second"> 
                DEVELOPER
            </div>
        </div>
    </div>
</div>

.css 的CSS

.first{
    font-family: Cinzel;
    color: black;
    font-size: 45px;
    font-weight: normal;
}

.second{
    font-family: Cinzel;
    color: black;
    font-size: 20px;
    font-weight: normal;
}

You could use media queries to get text over the image. 您可以使用媒体查询来获取图像上的文本。 Override position attribute as it is shown here How to position text over an image in css 如此处所示,覆盖位置属性如何在CSS中将文本放置在图像上

Also, there is no need to use col-xs-9 and col-xs-3. 另外,也不需要使用col-xs-9和col-xs-3。 You can use col-xs-12. 您可以使用col-xs-12。 Atleast col-xs-3 is not needed (col-xs-9 is a choice). 不需要Atleast col-xs-3(col-xs-9是一个选择)。

Something similar to this (not tested): 与此类似(未经测试):

<div class="container-fluid cntr"> 
    <div class="row">
        <div class="col-xs-12 col-md-6 image1">
            <img class="img-responsive" src="styles/pics/brainimg.png" alt="Brain Image" width="960" height="819">
        </div>
        <div class="col-xs-12 col-md-6 text1">
            <div class="first"> 
                NAME HERE
            </div>
            <div class="second"> 
                DEVELOPER
            </div>
        </div>
    </div>
</div>

@media screen and (max-width: 767px) {
.cntr {
  position: relative;
}
.image1 {
  position: absolute;
  left: 0;
  top: 0;
}
.text1 {
  position: absolute;
  color: white;
  font-size: 24px;
  font-weight: bold;
}
}

It's tricky to answer as you haven't specified what you mean by "too small" or how big your current image is. 回答是棘手的,因为您没有指定“太小”或当前图像的大小。 The smallest device is probably an old iPhone (320px). 最小的设备可能是旧的iPhone(320像素)。 The following works for 320px but not below as the margin-left here is in pixels (percentage would be ideal). 以下内容适用于320像素,但不能低于320像素,因为此处的左边距为像素(百分比是理想的)。 There is a jsbin here 有一个jsbin 这里

 .first { font-family: Cinzel; color: black; font-size: 45px; font-weight: normal; } .second { font-family: Cinzel; color: black; font-size: 20px; font-weight: normal; } @media screen and (max-width:320px) { .first { font-size: 16px; text-align: center; vertical-align: middle; left: 0!important; margin-left: -300px; color: white; } .second { font-size: 10px; text-align: center; vertical-align: middle; margin-left: -300px; color: white; } } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <div class="container-fluid"> <div class="row"> <div class="col-xs-9 col-md-6"> <img class="img-responsive" src="http://s3.amazonaws.com/digitaltrends-uploads-prod/2014/06/Brain.jpg" alt="Brain Image" width="960" height="819"> </div> <div class="col-xs-3 col-md-6"> <div class="first"> NAME HERE </div> <div class="second"> DEVELOPER </div> </div> </div> </div> 

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

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