Darlyn
Darlyn

Reputation: 4940

vertically and horizontally align text

I know there are a lot of questions about vertically and horizontally aligning text but I have tried everything and nothing seems to work.

I have CSS and HTML structure as follows

* {
  margin:0;
  padding:0;
}
article {
  display:inline-table;
  width:190px;
  height:260px;
  border:1px solid black;
  background-color: rgb(255, 253, 233);
  position:relative;
  margin-left:20px;
  margin-top:20px;
}
ul {
  display: block;
  margin-left: auto;
  margin-right: auto;

  list-style-type:none;
  width:170px;
  height:240px;


}

ul li {

  position:relative;
  padding-top:20px;
  color: #8C460E;
  font-size:10.666667px;
  width:100%;
  height:auto;

  font-family: Tahoma, Verdana, Arial;
  border-bottom:1px dashed black;
  text-align:center;

}
<article>
  <ul>
    <li><span>PRÍPRAVA DOKUMENTÁCIE PODĽA NOVÉHO ZÁKONA O POĽOVNÍCTVE:</span></li>
    <li><span>k uznávaniu poľovného revíru</span></li>
    <li><span>k zhromaždeniu vlastníkov poľovných pozemkov</span></li>
    <li><span>k zmene hranice poľovného revíru</span></li>
    <li><span>k zmluve vlastníkov spoločného poľovného revíru</span></li>
    <li style="border:0px"><span>k zmluve o užívaní poľovného revíru</span></li>
  </ul>
</article>

and I am trying to align the text both , vertically and horizontally. I tried everything from w3.org to answers here but nothing is working .What is the right way to achieve my goal?

Demo

Upvotes: 0

Views: 71

Answers (3)

sonam gupta
sonam gupta

Reputation: 785

Try using the padding instead of padding-top as:

ul li{
    padding: 6px,0;
}

Replace your padding-top with this in ul li css.

Upvotes: 0

user4563161
user4563161

Reputation:

Just change padding-top:20px to padding: 10px 0; & remove your set heights.

* {
  margin: 0;
  padding: 0;
}
article {
  display: inline-table;
  width: 190px;
  border: 1px solid black;
  background-color: rgb(255, 253, 233);
  position: relative;
  margin-left: 20px;
  margin-top: 20px;
}
ul {
  display: block;
  margin-left: auto;
  margin-right: auto;
  list-style-type: none;
  width: 170px;
}
ul li {
  position: relative;
  padding: 10px 0;
  color: #8C460E;
  font-size: 10.666667px;
  width: 100%;
  height: auto;
  font-family: Tahoma, Verdana, Arial;
  border-bottom: 1px dashed black;
  text-align: center;
}
<article>
  <ul>
    <li><span>PRÍPRAVA DOKUMENTÁCIE PODĽA NOVÉHO ZÁKONA O POĽOVNÍCTVE:</span>
    </li>
    <li><span>k uznávaniu poľovného revíru</span>
    </li>
    <li><span>k zhromaždeniu vlastníkov poľovných pozemkov</span>
    </li>
    <li><span>k zmene hranice poľovného revíru</span>
    </li>
    <li><span>k zmluve vlastníkov spoločného poľovného revíru</span>
    </li>
    <li style="border:0px"><span>k zmluve o užívaní poľovného revíru</span>
    </li>
  </ul>
</article>

Upvotes: 1

G.L.P
G.L.P

Reputation: 7207

Try like this: Demo

ul li {        
    position:relative;
    padding:8px 0; / * changed padding top value to this */
    color: #8C460E;
    font-size:10.666667px;
    width:100%;
    height:auto;        
    font-family: Tahoma, Verdana, Arial;
    border-bottom:1px dashed black;
    text-align:center;       
}

Upvotes: 3

Related Questions