简体   繁体   English

在图像旁边对齐垂直文本

[英]Align vertical text next to the image

I'm trying to create exactly like what is shown in the picture below. 我正在尝试完全按照下图所示创建内容。 So far, it's not looking good for me. 到目前为止,对我来说还不好。

在此处输入图片说明

Here's the JSFiddle: https://jsfiddle.net/6o3nz6g9/ 这是JSFiddle: https ://jsfiddle.net/6o3nz6g9/

HTML: HTML:

<h1>This is Sparta!</h1>
<div class="container">
<div class="row">
    <div class="col-xs-4">
        <div class="services__text">Title Text Here</div>
        <img src="https://image.ibb.co/hccDVF/sample.jpg" class="img-responsive" alt=""/>
    </div>
    <div class="col-xs-4">
        <div class="services__text">Title Text Here</div>
        <img src="https://image.ibb.co/hccDVF/sample.jpg" class="img-responsive" alt=""/>
    </div>
  <div class="col-xs-4">
        <div class="services__text">Title Text Here</div>
        <img src="https://image.ibb.co/hccDVF/sample.jpg" class="img-responsive" alt=""/>
    </div>
</div>
</div>

CSS: CSS:

.services__text {
    -ms-transform: rotate(-90deg);
    -moz-transform: rotate(-90deg);
    -webkit-transform: rotate(-90deg);
    transform: rotate(-90deg);
    -ms-transform-origin: right top 0;
    -moz-transform-origin: right top 0;
    -webkit-transform-origin: right top 0;
    transform-origin: right top 0;
    padding: 10px;
    float: left;
}

How do I do to get this desired effect? 我该如何取得理想的效果? FYI: I'm working on Bootstrap framework. 仅供参考:我正在研究Bootstrap框架。

You can change positioning of .services__text and then using translate align that before image . 您可以更改.services__text位置,然后使用translate align image之前的位置。

 .services__text { position: absolute; left: 0; top: 0; transform: rotate(-90deg) translate(-40%, -200%); } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <h1>This is Sparta!</h1> <div class="container"> <div class="row"> <div class="col-xs-4"> <div class="services__text">Title Text Here</div> <img src="https://image.ibb.co/hccDVF/sample.jpg" class="img-responsive" alt="" /> </div> <div class="col-xs-4"> <div class="services__text">Title Text Here</div> <img src="https://image.ibb.co/hccDVF/sample.jpg" class="img-responsive" alt="" /> </div> <div class="col-xs-4"> <div class="services__text">Title Text Here</div> <img src="https://image.ibb.co/hccDVF/sample.jpg" class="img-responsive" alt="" /> </div> </div> </div> 

Hey Champ, You may solve your problem with following CSS 嗨,冠军,您可以通过以下CSS解决您的问题

 .services__text { position: absolute; text-align: right; -moz-transform: rotate(-90deg) translate(-100%, -100%); -webkit-transform: rotate(-90deg) translate(-100%, -100%); -o-transform: rotate(-90deg) translate(-100%, -100%); -ms-transform: rotate(-90deg) translate(-100%, -100%); transform: rotate(-90deg) translate(-100%, -100%); -ms-transform-origin: left top; -webkit-transform-origin: left top; transform-origin: left top; } 
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" /> <h1>This is Sparta!</h1> <div class="container"> <div class="row"> <div class="col-xs-4"> <div class="services__text">Title Text Here</div> <img src="https://image.ibb.co/hccDVF/sample.jpg" class="img-responsive" alt="" /> </div> <div class="col-xs-4"> <div class="services__text">Title Text Here</div> <img src="https://image.ibb.co/hccDVF/sample.jpg" class="img-responsive" alt="" /> </div> <div class="col-xs-4"> <div class="services__text">Title Text Here</div> <img src="https://image.ibb.co/hccDVF/sample.jpg" class="img-responsive" alt="" /> </div> </div> </div> 

Add following css properties in your code for class .service_text 在代码中为类.service_text添加以下CSS属性

top:20px;  left:-126px;  position:absolute;

And add a class to your class="col-xs-4" as class="col-xs-4 parent" And for parent add following css. 并将一个类作为class="col-xs-4 parent"添加到您的class="col-xs-4" ,并为parent添加以下CSS。 position: relative; padding-left: 8px;

This will give exactly same result. 这将给出完全相同的结果。 And if you want further explanation i would love to help you on that 如果您想进一步解释,我很乐意为您提供帮助

This method will work with any length of text (so long as it's a single line). 此方法适用于任何长度的文本(只要是一行)。

.services__text {
    position:absolute;
    transform: rotate(-90deg) translate(-100%);
    transform-origin: left top;
    width:100%;
    left:-8px;
    text-align:right;
}
  • translate(-100%) moves the elements new position -100% of its width to its left (down). translate(-100%)将元素的新位置移动到其宽度的100%左(下)。
  • width:100%; gives your title room to expand. 让您的标题空间扩大。 This the elements height . 这个元素的高度
  • text-align:right; pushes the text to the top of the image 将文本推到图像顶部
  • position:absolute; & left:-8px; left:-8px; pushes the text to the outside of the image (possibly overlapping other elements) 将文本推到图像的外部(可能与其他元素重叠)

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

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