简体   繁体   English

如何以响应方式使下面的文本位于框的中央?

[英]How to make the below text in the center of the box in responsive way?

Here is the Problem.. I want to vertically Align the text.. 这是问题。.我要垂直对齐文本..

Here is my Code on jsfiddle.. https://jsfiddle.net/AliRaza610/c5gs3Lnn/3/ I want the text block in the middle in responsive grid.. In this example if I change the size the text is no longer in center.. I had tried.. 这是我对的jsfiddle ..代码https://jsfiddle.net/AliRaza610/c5gs3Lnn/3/我想在响应网格中间的文本块。在这个例子中,如果我改变大小的文本不再中心..我尝试过..

display:table-cell;
vertically-align: middle;

and other solution that I found on other question but none of them work for me.. 和我在其他问题上发现的其他解决方案,但没有一个对我有用。

in your fiddle: change text-right to text-center (i guess that is what you are asking) 在您的小提琴中:将text-right更改为text-center(我想这就是您要的内容)

<div class="col-md-4 col-sm-6 col-xs-6 text-center">
    <h1>Lorem Ipsum</h1>
    <h4>Is Simply Dummy</h4> ........

I would add display: flex; align-items: center 我会添加display: flex; align-items: center display: flex; align-items: center to the parent that wraps those cells, then remove the margin-top from the h1 display: flex; align-items: center以包裹这些单元格的父级为display: flex; align-items: center ,然后从h1移除margin-top

 .hp-laptop-deal { border: 3px solid #eaeaea; box-sizing: border-box; margin-top: 2em; margin-bottom: 2em; display: flex; align-items: center; } .hp-laptop-deal h1 { text-transform: uppercase; font-weight: 900; font-size: 2.5em; margin-top: 0; } .hp-laptop-deal h4 { text-transform: uppercase; font-size: 1.5em; letter-spacing: -2px; } .hp-laptop-deal p { font-size: 0.85em; font-weight: 600; text-transform: uppercase; } @media (max-width:768px) { .hp-laptop-deal img { margin-top: 1em; } .hp-laptop-deal h1 { font-size: 1.25em; } .hp-laptop-deal h4 { margin-top: 0.75em; font-size: 1em; letter-spacing: 0px; line-height: 0%; } .hp-laptop-deal p { line-height: 100%; font-weight: normal; font-size: 0.75em; } } 
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <div class="row hp-laptop-deal"> <div class="col-md-8 col-sm-6 col-xs-6"> <img src="https://s14.postimg.org/ydjwm4xc1/first-fold-hp-laptop.jpg" alt="" class="img-responsive"> </div> <div class="col-md-4 col-sm-6 col-xs-6 text-right"> <h1>Lorem Ipsum</h1> <h4>Is Simply Dummy</h4> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod </p> </div> </div> 

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

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