简体   繁体   English

<a>引导栏中的垂直</a>居中<a>标签文本和图像</a>

[英]center <a> tag text and image vertical in Bootstrap column

I have a Bootstrap row with some columns. 我有一些列的Bootstrap行。 In the columns I've added a span tag with text and an image between <'a'> and <'/a'>. 在各列中,我在<'a'>和<'/ a'>之间添加了带有文本和图像的span标签。 I need the text to vertical align with the image, now it's always placed to the top of the column. 我需要使文本与图像垂直对齐,现在它始终位于列的顶部。 I tried vertical-align: middle but no luck. 我尝试了垂直对齐:中等但没有运气。

<div class="row">
<div class="container">
    <div class="col-md-2 col-md-offset-5">
        <a href="http://www.xxxx.xxx" target="_blank">
            <span style="float: left; vertical-align: middle;">Powered by</span>
            <img src="@Url.Content("~/Content/images/xxxxxxxx.gif")" alt="Powered by " class="img-responsive "/>
        </a>
    </div>
</div>

Anyone got a clue? 有人知道了吗?

I recently tried to achieve the same thing, position a span vertically and horizontally inside an image of unknown height and width inside a thumbnail button link. 我最近尝试实现相同的目的,在缩略图按钮链接内高度和宽度未知的图像内垂直和水平放置跨度。 This might be helpful for you or others who struggle. 这可能对您或其他挣扎的人有所帮助。

jsfiddle demo jsfiddle演示

 .thumbnail:before { content: ''; display: inline-block; height: 100%; vertical-align: middle; margin-right: -0.25em; } .centered { display: inline-block; vertical-align: middle; position: relative; } .centered > span.fa-play-circle-o{ position: absolute; top: 50%; margin-top: -0.5em; margin-left: -0.5em; opacity: 0.5; -webkit-transition: opacity 0.5s; transition: opacity 0.5s; } a.thumbnail:hover .centered span.fa-play-circle-o{ opacity: 1; } 
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/> <link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet"/> <div class="container"> <!-- inline color for visual debugging only --> <div class="row" style="background-color: aliceblue;"> <div class="col-xs-6" style="background-color:pink;"> <p class="text-center">text above</p> <a href="#" class="thumbnail btn btn-default"> <div class="centered"> <img class="img-responsive" src="http://placehold.it/600x200" /> <span class="fa fa-2x fa-play-circle-o"></span> </div> </a> <p class="text-center">larger text<br/>below</p> </div> </div> </div> 

Just use tag.. 只需使用标签即可。

<a href="#" target="_blank">

            <img src="@Url.Content("~/Content/images/xxxxxxxx.gif")" alt="Powered by " class="img-responsive "/>
            <div style="float: left; vertical-align: middle;">Powered by</div>
        </a>

You can also use span tag as i tried but just put span tag under the img tag and a href text will be under the image..if you have any other question then please let me know.. 您也可以像我尝试的那样使用span标签,但是只需将span标签放在img标签下,并且href文本将位于图像下..如果您还有其他问题,请告诉我。

hope it will work 希望它能工作

You can do this in two ways. 您可以通过两种方式执行此操作。

Using Absolute position 使用绝对位置

Using display:table 使用显示:表

USING ABSOLUTE POSITION 使用绝对位置

DESC: Give parent element {{position:relative}} and child(element to be centered) as DESC:将父元素{{position:relative}}和child(要居中的元素)设置为

{
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  -webkit-transform: translateY(-50%);
   -moz-transform: translateY(-50%);
}

USING TABLE BLOCK 使用表块

DESC: Give parent element as display:table;width:100% and second parent as display:table-cell;vertical-align:middle; DESC:将父元素指定为display:table; width:100%,将第二个父元素指定为display:table-cell; vertical-align:middle;

Note* : {table-row} should have some height greater than its content. 注意* :{table-row}的高度应大于其内容的高度。

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

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