This question already has answers here:
Flexbox: center horizontally and vertically
(14 answers)
Vertical Align Center in Bootstrap 4 [duplicate]
(20 answers)
Bootstrap Center Vertical and Horizontal Alignment
(17 answers)
How to center a "position: absolute" element
(31 answers)
How can I vertically align elements in a div?
(28 answers)
Closed 2 years ago.
This is my first post. Just as the title says, I am not able to center content inside of a div. Here is my code:
.coupon {
border-style: dashed;
border-color: black;
min-height: 350px;
}
.fineprint {
font-size: 11px;
position: absolute;
bottom: 25px;
display: table-cell;
vertical-align: bottom;
text-align: center;
}
.couponcontent {
position: absolute;
top: 40%;
bottom: 60%;
display: table-cell;
vertical-align: middle;
text-align: center;
}
.scissors {
font-size: 48px;
color: #ed1a24;
position: absolute;
top: 25px;
display: table-cell;
vertical-align: top;
text-align: center;
}
<!-- Coupon Boxes -->
<div class="col-md-4 col-sm-6">
<div class="feature boxed feature-s6">
<div class="fbox-content center coupon">
<span class="scissors"><i class="fa fa-scissors"></i></span>
<div class="couponcontent">
<h2>middle center</h2>
<p>middle center</p>
</div>
<p class="fineprint">bottom center</p>
</div>
</div>
</div>
<!-- End Coupon box -->
Can someone help me center this content inside of the div? It is currently aligned left. Thanks!
You need remove position: absolute and change display from table-cell to block.
.coupon {
border-style: dashed;
border-color: black;
min-height: 350px;
}
.fineprint {
font-size: 11px;
bottom: 25px;
display: block;
vertical-align: bottom;
text-align: center;
}
.couponcontent {
display: block;
vertical-align: middle;
text-align: center;
}
.scissors {
font-size: 48px;
color: #ed1a24;
top: 25px;
display: block;
vertical-align: top;
text-align: center;
}
<!-- Coupon Boxes -->
<div class="col-md-4 col-sm-6">
<div class="feature boxed feature-s6">
<div class="fbox-content center coupon">
<span class="scissors"><i class="fa fa-scissors"></i></span>
<div class="couponcontent">
<h2>middle center</h2>
<p>middle center</p>
</div>
<p class="fineprint">bottom center</p>
</div>
</div>
</div>
<!-- End Coupon box -->
try to simplify your CSS as much as possible otherwise, there will be clashes and things like text-align:center won't work. https://www.w3schools.com/ is a great source when it comes to CSS.
.main{text-align:center}
.coupon {
border-style: dashed;
border-color: black;
min-height: 350px;
}
.couponcontent {
position: absolute;
top: 40%;
bottom: 60%;
}
.scissors {
font-size: 48px;
color: #ed1a24;
position: absolute;
top: 25px;
display: table-cell;
vertical-align: top;
text-align: center;
}
<div class='main'>
<div class="coupon">
<span class="scissors"><i class="fa fa-scissors"></i></span>
<h2>middle center</h2>
<p>middle center</p>
</div>
<p >bottom center</p>
</div>
Related
This question already has answers here:
How can I vertically center a div element for all browsers using CSS?
(48 answers)
Flexbox: center horizontally and vertically
(14 answers)
Closed 7 months ago.
Could someone explain what the problem is in the code? No matter what I do, even taking out all the styles I can't align in the middle.
.Div1 {
vertical-align: middle;
height: 100%;
width:100%;
position: relative;
min-height: 100px;
background: linear-gradient(180deg, rgba(0,113,142,1) 0%, rgba(119,111,111,0.8855917366946778) 80%);
}
.Div2 {
position: absolute;
top:75px;
bottom: 0;
text-align: center;
font-size: 12px;
}
<div class="Div1">
<p>I-BS</p>
<div class="Div2">
<p>
<font size="auto"> <strong>CRONOGRAMA CLUSTER; &nbs; EMBARCAÇÃO&;   ;SAÍDA </strong>
</font>
</p>
</div>
</div>
I would recommend using flex instead by replacing
vertical-align: middle;
with
display: flex;
align-items: center;
.Div1 {
display: flex;
align-items: center;
height: 100%;
width:100%;
position: relative;
min-height: 100px;
background: linear-gradient(180deg, rgba(0,113,142,1) 0%, rgba(119,111,111,0.8855917366946778) 80%);
}
.Div2 {
position: absolute;
top:75px;
bottom: 0;
text-align: center;
font-size: 12px;
}
<div class="Div1">
<p>I-BS</p>
<div class="Div2">
<p>
<font size="auto"> <strong>CRONOGRAMA CLUSTER; &nbs; EMBARCAÇÃO&;   ;SAÍDA </strong>
</font>
</p>
</div>
</div>
This question already has answers here:
Vertical Align Center in Bootstrap 4 [duplicate]
(20 answers)
Bootstrap Center Vertical and Horizontal Alignment
(17 answers)
Closed 4 years ago.
Im Trying to vertically align (center) the the following card deck:
<div class="container-fluid">
<div class="card-deck d-flex justify-content-center">
<div class="col-xl-2">
<div class="card d-flex>
....
</div>
</div>
</div>
</div>
Currently looks like this:
I tried with my-auto, align-items-center, justify-content-center... but it doesn't work, what is missing?
Thanks for the help!
you can vertical align any element using position: absolute;
like ,
HTML
<div class="parent">
<div class="element">I'm always<br/>In<br>Center</div>
</div>
CSS
.parent {
height: 100%;
}
.element {
position:absolute;
top:50%;
left: 0;
transform: translateY(-50%);
}
.parent {
height: 100%;
}
.element {
position:absolute;
top: 50%;
left: 0;
transform: translateY(-50%);
}
<div class="parent">
<div class="element">I'm always<br/>In<br>Center</div>
</div>
OR
using display: table-cell;
HTML
<div class="container">
<div class="content">I'm always<br/>In<br>Center</div>
</div>
CSS
html, body {
width: 100%;
height: 100%;
display: table;
}
.container {
display: table-cell;
text-align: center;
vertical-align: middle;
}
.content {
background-color: #dddddd;
display: inline-block;
text-align: center;
padding: 5px;
width:200px;
}
LIVE SNIPPET
html, body {
width: 100%;
height: 100%;
display: table;
}
.container {
display: table-cell;
text-align: center;
vertical-align: middle;
}
.content {
background-color: #dddddd;
display: inline-block;
text-align: center;
padding: 5px;
width:200px;
}
<div class="container">
<div class="content">I'm always<br/>In<br>Center</div>
</div>
This question already has answers here:
Vertically align text next to an image?
(26 answers)
Closed 4 years ago.
I am trying to align the icons and text within the boxes here:
I can't seem to get the "Store Locator" and icon to align horizontally.
Can anyone please help me achieve this?
My html:
<div id="container">
<div id="phone" class="block">Phone</div>
<div id="chat" class="block">Live Chat</div>
<div id="email" class="block">Email</div>
<div id="store-locator" class="block">
<span class="store"></span> Store Locator <--- problem line
</div>
</div>
Try to use display:inline-flex here
#container {
text-align: center;
max-width: 960px;
margin: 0 auto;
}
.block {
width: 300px;
height: 120px;
margin: 10px;
display: inline-flex;
background: #3f3f3f;
border-radius: 5px;
font-size: 22px;
align-items: center;
justify-content: center;
}
#phone {
color: yellow;
}
#chat {
color: green;
}
#email {
color: white;
}
#store-locator {
color: grey;
}
.store {
background: url(http://s1.archerssleepcentre.co.uk/i/sprite-2015.svg) no-repeat center left;
background-position: -432px 2px;
position: relative;
right: 10px;
background-size: 1800% auto;
height: 32px;
width: 32px;
display: inline-block;
}
<div id="container">
<div id="phone" class="block">Phone</div>
<div id="chat" class="block">Live Chat</div>
<div id="email" class="block">Email</div>
<div id="store-locator" class="block">
<span class="store"></span> Store Locator
</div>
</div>
I am trying to align the text inside a div in center of the page and also text start from left side. But getting a problem as role1, role2 text is showing in center of Role(r) text i want that all the text should right aligned but in center of the page.
.home-role-access-text {
text-align: center;
height: 20px;
width: 250px;
position: absolute;
top: 60%;
left: 50%;
margin-left: -125px;
font-size: 20px;
color: #026890;
}
<div class="home-role-access-text" data-ng-show="alarmsCounter <= 0">
<div>
<div data-ng-hide="assignedRoles.length<=0">
<div style="padding-bottom: 10px;"><b>Role(r)</div>
<div style="font-size:11px;font-weight: 100;display: inline-block; text-align: left" data-ng-repeat="role in assignedRoles">Role1 </div>
<div style="font-size:11px;font-weight: 100;display: inline-block; text-align: left" data-ng-repeat="role in assignedRoles">Role3 </div>
</div>
</div>
</div>
Change display in the child divs of <div class="roles"> to block instead of inline-block.
I have included a jsfiddle as well. I had to change the CSS for .home-role-access-textto get all text to start on the left and stay within it's container. I suggest using display: flex because it's better at centering a block of content. https://jsfiddle.net/Luxz8eff/
.home-role-access-text {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
font-size: 20px;
color: #026890;
}
<div class="home-role-access-text" data-ng-show="alarmsCounter <= 0">
<div>
<div data-ng-hide="assignedRoles.length<=0">
<div style="padding-bottom: 10px;"><b>Role(r)</b></div>
<div style="font-size:11px;font-weight: 100;display: block; text-align: left" data-ng-repeat="role in assignedRoles">Role1 </div>
<div style="font-size:11px;font-weight: 100;display: block; text-align: left" data-ng-repeat="role in assignedRoles">Role3 </div>
</div>
Going by your image it seems you want all text left aligned inside a div that is right aligned of the center.
Based on that, you can float the container right with all text aligned left.
.home-role-access-text {
border: 1px solid black;
text-align: left;
height: 20px;
width: 250px;
position: absolute;
top: 60%;
left: 50%;
margin-left: -125px;
font-size: 20px;
color: #026890;
}
.roles {
float:right
}
<div class="home-role-access-text" data-ng-show="alarmsCounter <= 0">
<div>
<div data-ng-hide="assignedRoles.length<=0" class="roles">
<div style="padding-bottom: 10px;"><b>Role(r)</b></div>
<div style="font-size:11px;font-weight: 100;display: block; text-align: left;" data-ng-repeat="role in assignedRoles">Role1 </div>
<div style="font-size:11px;font-weight: 100;display: block; text-align: left;" data-ng-repeat="role in assignedRoles">Role3 </div>
</div>
</div>
</div>
The black border in the example is only added to show the div is still centered with right aligned text - You can off course, remove it :)
This question already has answers here:
Align inline-block DIVs to top of container element
(5 answers)
Why is this inline-block element pushed downward?
(8 answers)
Closed 3 years ago.
https://jsfiddle.net/2L9mznzu/
There are two empty text button, how to align them into a row?
.button {
display: inline-block;
width: 80px;
height: 30px;
line-height: 30px;
background: gray;
margin: 0 4px;
text-align: center;
}
<div class="button">
</div>
<div class="button">Button
</div>
<div class="button">
</div>
Use vertical-align: top property to your .button.
The vertical-align CSS property specifies the vertical alignment of an
inline or table-cell box.
Source: MDN
See demo below:
.button {
display: inline-block;
vertical-align: top;
width: 80px;
height: 30px;
line-height: 30px;
background: gray;
margin: 0 4px;
text-align: center;
}
<div class="button">
</div>
<div class="button">Button
</div>
<div class="button">
</div>
just add vertical-align: middle;
.button {
display: inline-block;
width: 80px;
height: 30px;
line-height: 30px;
background: gray;
margin: 0 4px;
text-align: center;
vertical-align: middle;
}
You can wrap them inside a container div and use display:flex; this way they will always be aligned to the vertical center of the container div.
.button {
display: inline-block;
width: 80px;
height: 30px;
line-height: 30px;
background: gray;
margin: 0 4px;
text-align: center;
}
.container{
display:flex;
flex-direction:row;
align-items:center;
}
<div class="container"><div class="button">
</div>
<div class="button">Button
</div>
<div class="button">
</div>
</div>