简体   繁体   English

<a>在div中</a>垂直对齐<a>文本</a>

[英]Vertically Align <a> text inside a div

I am having trouble vertically aligning the 's text inside a div. 我在div中垂直对齐的文本时遇到麻烦。

This is what I have. 这就是我所拥有的。 I need to center "Next" inside the blue box: 我需要将“下一步”居中在蓝色框中:

 @import url(http://fonts.googleapis.com/css?family=Muli); /*Makes the little side arrow*/ .open { position: fixed; width: 100px; height: 40px; left: 50%; top: -1000px; margin-left: -80px; margin-top: -30px; border: 1px solid #ccc; background-color: #fff; border-radius: 6px; padding: 10px 30px; color: #444; transition: all ease-out 0.6s; } .open:hover { border: 1px solid #aaa; box-shadow: 0 0 8px #ccc inset; transition: all ease-out 0.6s; } .tutorial-box { position: fixed; width: 400px; height: 238px; top: 75px; background-color: #F3F3F3; border-radius: 6px; box-shadow: 0px 0px 24px rgba(0, 0, 0, 0.4); } .slider-turn p, .tutorial-box h1{ margin-left: 10px; } .tutorial-box:before { content: ''; position: absolute; left: -14px; top: 28px; border-style: solid; border-width: 10px 14px 10px 0; border-color: rgba(0, 0, 0, 0) #f3f3f3 rgba(0, 0, 0, 0) rgba(0, 0, 0, 0); } .tutorial-box p { width: 350px; font-size: 16px; color: #a8aab2; font-weight: 400; line-height: 28px; float: left; margin: 0; } .tutorial-box .bottom { display: -webkit-box; display: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: flex; width: 100%; bottom: 0; position: absolute; } .tutorial-box .bottom .btn-2 { flex: 3; -webkit-flex: 3; -ms-flex: 3; width: 100%; height: 54px; background-color: #373942; border-bottom-left-radius: 6px; display: flex; } .tutorial-box .bottom span { flex: 1; -webkit-flex: 1; -ms-flex: 1; line-height: 54px; color: #fff; margin-left: 25px; font-size: 18px; } .next { text-decoration: none; display: inline-block; vertical-align: middle; text-align: center; flex: 1; background-color: #6cb5f3; border: 0; margin: 0; padding: 0; text-transform: uppercase; color: #fff; font-weight: bold; border-bottom-right-radius: 6px; cursor: pointer; transition: all .3s; } .next:hover { text-decoration: none; background-color: #6BA5D6; transition: all .3s; } .next:active { text-decoration: none; background-color: #5F8AAF; } .slider-tutorial-box { width: 350px; margin: 0 25px; overflow: hidden; } .slider-turn { width: 10000px; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <!-- TUTORIAL --> <div class="tutorial-box"> <h1>Welcome</h1> <span class="close"></span> <div class="slider-container"> <div class="slider-turn"> <p> Here, under the Company tab, is where you will do most of the company managment.<br> </p> </div> </div> <div class="bottom"> <div class="btn-2"> <span>Step 2/?</span> </div> <a href="/tutorial/3" class="allowedLink next">Next</a> </div> </div> 

Please let me know how I can center the text vertically to the center of the div. 请让我知道如何将文本垂直居中到div的中心。

Thank you very much. 非常感谢你。 Let me know if I wasn't clear enough. 让我知道我是否还不够清楚。

the simplest and possibly most easy way would be to add the 'center' and '/center' tag before and after the text you want, and after each letter use '/br' to move to the next line. 最简单,也可能是最简单的方法是在所需文本的前后添加“ center”和“ / center”标签,并在每个字母之后使用“ / br”移至下一行。 this will add some bulk, but would be considerably easier than other methods. 这会增加一些体积,但比其他方法容易得多。

<center>
    'letter'</br>'next letter'</br>'next letter'</br>
</center>

repeating the letter and break for all letters 重复字母并中断所有字母

alternatively, you could also add "div" tags around the "a" tag. 或者,您也可以在“ a”标签周围添加“ div”标签。 you would have to modify the 'height' and 'width' to make it vertical for you. 您将需要修改“高度”和“宽度”以使其垂直。 I would use px for this and not '%' or 'em'. 我会为此使用px而不是'%'或'em'。 add this to them: 添加到他们:

<div style="height: /* modify this */100px; width: /* and this*/20px;">
    <a href="/tutorial/3" class="allowedLink next">Next</a>
</div>

this may not be AS compatible cross platform though. 但是,这可能不是与AS兼容的跨平台。

Seems like you already did that for .tutorial-box .bottom span so, do the same thing for .next 似乎您已经对.tutorial-box .bottom span执行了此操作,所以对.next执行相同的操作

.next{
  line-height: 54px;
}

Like this: 像这样:

.next { position: relative; top: 50%; transform: translateY(-50%); }

A nice trick that works both vertically and horizontally. 一个很好的技巧,可以在水平和垂直方向上工作。

对齐内部的图像和文本<div>水平和垂直</div><div id="text_translate"><p>我想水平和垂直对齐 div 内的图像和文本。 我的代码:</p><pre> &lt;div style="white-space:nowrap" (click)="sidenav.toggle()"&gt; &lt;img alt='image' style="margin-top: 1vw;display: inline;" width="25" height="35" src="../assets/menu-white-18dp.svg"&gt; &lt;span style="display:inline; white-space:nowrap;" &gt; KRON&lt;/span&gt; &lt;/div&gt;</pre><p> 目前它看起来像这样: <a href="https://i.stack.imgur.com/VP0Ld.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VP0Ld.png" alt="在此处输入图像描述"></a></p><p> 我希望“KRON”与图像对齐。 我做错了什么?</p></div> - Align image and text inside <div> horizontally and vertically

暂无
暂无

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

相关问题 使用CSS在div内垂直对齐文本 - Align text vertically inside div with CSS 垂直对齐div内的两行文本 - Vertically align two lines of text inside a div 如何将文字与图片中的图片垂直对齐<div> - How to align text vertically with an image inside a <div> div内的文本可以垂直和水平对齐 - Text inside a div to align both vertically and horizontally 文本不会垂直对齐内部Div无关紧要什么 - Text Will NOT Vertically Align Inside Div No Matter What 垂直对齐Div内的图像和文本 - Vertically Align Image and Text Inside a Div 将文本与div中的图像垂直对齐 - Vertically align a text with an image inside a div 对齐内部的图像和文本<div>水平和垂直</div><div id="text_translate"><p>我想水平和垂直对齐 div 内的图像和文本。 我的代码:</p><pre> &lt;div style="white-space:nowrap" (click)="sidenav.toggle()"&gt; &lt;img alt='image' style="margin-top: 1vw;display: inline;" width="25" height="35" src="../assets/menu-white-18dp.svg"&gt; &lt;span style="display:inline; white-space:nowrap;" &gt; KRON&lt;/span&gt; &lt;/div&gt;</pre><p> 目前它看起来像这样: <a href="https://i.stack.imgur.com/VP0Ld.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VP0Ld.png" alt="在此处输入图像描述"></a></p><p> 我希望“KRON”与图像对齐。 我做错了什么?</p></div> - Align image and text inside <div> horizontally and vertically 将div与文本垂直对齐 - Align div vertically with text 将div与文本垂直对齐 - Vertically align div with text
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM