0

I have multiple slides using the jQuery slidemaster plug in, I want the text to always be centered, vertically and horizontally but I am having trouble vertically centering the text.

I have tried using margin: 0 auto; and vertical-align: middle; but it doesn't seem to be working, maybe I am using them on the wrong elements.

http://codepen.io/anon/pen/eBMoBq

.ms-slide p, .ms-slide h1 {
    color: white !important;
    text-align: center;
    margin: 0;
}
.ms-slide {
  background: rgb(213, 28, 41); 
  width: 1266px; 
  height: 138.109px; 
  left: 5084px;
}
 <div id="masterslider-md" class="master-slider ms-skin-default">
    <div class="ms-slide" style="background: #590056;">
 <div class="slide-content">
       <h1>10,795</h1><p>some text about number</p>
 </div>
    </div>
</div>
Ashish Bahl
  • 1,406
  • 1
  • 12
  • 25
user2953989
  • 2,121
  • 8
  • 28
  • 45

5 Answers5

1

With flexbox layout:

.ms-slide p, .ms-slide h1 {
    color: white !important;
    text-align: center;
    margin: 0;
}
.ms-slide {
  background: rgb(213, 28, 41); 
  width: 1266px; 
  height: 138.109px; 
  left: 5084px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.slide-content {
  flex: 0 1;
}
<div id="masterslider-md" class="master-slider ms-skin-default">
    <div class="ms-slide" style="background: #590056;">
 <div class="slide-content">
       <h1>10,795</h1><p>some text about number</p>
 </div>
    </div>
</div>
Sandro
  • 663
  • 3
  • 10
0

set the display of parent element (.ms-slide) in to table and of child element (.slide-content) to table cell , then set vertical-align:middle for the child.

.ms-slide p, .ms-slide h1 {
    color: white !important;
    text-align: center;
    margin: 0;
}
.ms-slide {
  background: rgb(213, 28, 41); 
  width: 1266px; 
  height: 138.109px; 
  left: 5084px;
  display:table;
}
.slide-content{
  display:table-cell;
  vertical-align:middle;
  }
<div id="masterslider-md" class="master-slider ms-skin-default">
    <div class="ms-slide" style="background: #590056;">
 <div class="slide-content">
       <h1>10,795</h1><p>some text about number</p>
 </div>
    </div>
</div>
Dream Hunter - hashADH
  • 3,206
  • 2
  • 23
  • 47
0

Keep it short and simple :)

.ms-slide {
  background: rgb(213, 28, 41); 
  width: 1266px; 
  height: 138.109px; 
  left: 5084px;
  text-align: center;
}

.ms-slide p, .ms-slide h1 {
  color: white;
  position: relative;
  top: 50%;
  transform: translateY(-50%);
  margin: 0 auto;
}
<div id="masterslider-md" class="master-slider ms-skin-default">
    <div class="ms-slide" style="background: #590056;">
       <h1>10,795</h1><p>some text about number</p>
    </div>
</div>
Martin P.
  • 284
  • 1
  • 11
0

Try the old simple CSS positioning way which works across all browsers:

.ms-slide {
  background: rgb(213, 28, 41);
  width: 1266px;
  height: 138.109px;
  position: relative;
}
.slide-content {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    width: 300px;
    height: 50px;
    text-align: center;
    color: #fff;
    margin: auto;
    font-size: 12px;
}
h1,
p {
  margin: 0;
}
<div id="masterslider-md" class="master-slider ms-skin-default">
  <div class="ms-slide" style="background: #590056;">
    <div class="slide-content">
      <h1>10,795</h1>
      <p>some text about number</p>
    </div>
  </div>
</div>
nashcheez
  • 4,717
  • 1
  • 22
  • 50
0

simply do with this vertical-align:middle property, just try with this snippet

.ms-slide p, .ms-slide h1 {
    color: white !important;
    text-align: center;
    margin: 0;
 
}
.ms-slide {
  background: rgb(213, 28, 41); 
  width: 1266px; 
  height: 138.109px; 
  left: 5084px;
  display:table;
  
}
.slide-content{
    display: table-cell;
    vertical-align: middle;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Try file</title>
</head>
<body>
 <div id="masterslider-md" class="master-slider ms-skin-default">
    <div class="ms-slide" style="background: #590056;">
 <div class="slide-content">
       <h1>10,795</h1><p>some text about number</p>
 </div>
    </div>
</div>
</body>
</html>
Jishnu V S
  • 7,465
  • 6
  • 24
  • 55