-4

I want my html content to be center aligned, while maintaining the column structure of id game-inst please feel free to edit my css code, waiting for your help, thanks

enter image description here

#score-container {
  display: block;
  width: 100%;
  height: 100%;
  text-align: center;
  background-color: #1B2631;
  color: #ffffff;

}

.key {
  width: 40%;
  display: inline-block;
}

.instruction {
  display: inline-block;
  width: 40%;
  text-align: left;
}

#my-score,
#high-score,
#game-inst {
  font-size: 1.25em;
  padding: 0px 10px;
  line-height: 1;
}
<div id="score-container">
  <div id="game-inst">
    <div class="key">Key 4:</div>
    <div class="instruction">Move UP</div>
    <div class="key">Key 6:</div>
    <div class="instruction">Move DOWN</div>
    <div class="key">Key 5:</div>
    <div class="instruction">PLAY/PAUSE</div>
  </div>
  <p id="my-score">123</p>
  <p id="high-score">786</p>
</div>
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Tarun Mahashwari
  • 338
  • 1
  • 10
  • 19
  • Hey there Tarun. You might be able to get a quicker answer to your question by referencing some of the other similar questions that have been asked here in the past! [Center element within a `
    ` element](https://stackoverflow.com/questions/6810031/css-center-element-within-a-div-element), [How to center an element horizontally and vertically?](https://stackoverflow.com/questions/19461521/how-to-center-an-element-horizontally-and-vertically), [Center a div horizontally and vertically](https://stackoverflow.com/questions/14123999/center-a-div-horizontally-and-vertically), etc.
    – Tyler Roper Aug 01 '18 at 16:37
  • If you are trying to delete the question please ask about that on meta rather than defacing the question. – Jason Aller Aug 19 '18 at 21:00

1 Answers1

-1

I believe this is what you want.

#score-container {
  top: 100px;
  display: block;
  position: relative;
  left: 0;
  width: 100%;
  height: 100%;
  text-align: center;
  z-index: 10;
}

.key {
  width: 30%;
  display: inline-block;
  float: left;
}

.instruction {
  width: 70%;
  display: inline-block;
  float: left;
}

#score-box {
  position: relative;
  width: 300px;
  margin-left: auto;
  margin-right: auto;
  padding: 0;
}

#game-inst:after {
  content: ".";
  visibility: hidden;
  display: block;
  height: 0;
  clear: both;
}

#my-score,
#high-score,
#game-inst {
  font-size: 1.25em;
  padding: 0px 10px;
  line-height: 1;
  text-align: left;
}

#score-box p {
  width: 42%;
  display: inline-block;
  text-align: left;
  border: solid 1px silver;
}
<div id="score-container">
<div id="score-box">
  <div id="game-inst">
    <div class="key">Key 4:</div>
    <div class="instruction">Move UP</div>
    <div class="key">Key 6:</div>
    <div class="instruction">Move DOWN</div>
    <div class="key">Key 5:</div>
    <div class="instruction">PLAY/PAUSE</div>
  </div>
  <p id="my-score">123</p>
  <p id="high-score">786</p>
</div>
</div>

Note the changes in .key, .instruction, #game-inst and the addition of #game-inst:after

#game-inst:after {
  content: ".";
  visibility: hidden;
  display: block;
  height: 0;
  clear: both;
}

Which clears the floats added to the key and instruction classes.

critical_error
  • 6,306
  • 3
  • 14
  • 16