Centering an element inside of a DIV using HTML/CSS -
i working on periodic table, , although got mass , number placed want them to, element symbol won't budge. tried everything: converting <p>
<span>
<div>
, using display: block
, setting margin: 0 auto
, using text-align: center
, still won't budge.
here's html:
<div id = "a1" class="element alkalimetal"> <p> <span id = "anumber">118</span> <span id = "amass">9.008</span> </p> <br> <div id = "symbol">h</div> </div> <div id = "a2" class = "element noblegas"> </div>
here's css:
#anumber{ font-family:arvo; top: 0.1em; position:relative; vertical-align:super; font-size:1.5em; float:left; padding-left:0.2em; } #symbol{ width: 5em; font-family: avenircondensed; font-size: 5em; text-align:center; margin: 0 auto; } #amass{ font-family:avenirnext; top: 0.1em; position:relative; vertical-align:super; font-size:1.5em; float:right; padding-right:0.2em } .element{ border: 1px solid black; border-radius: 3px; height: 8em; width: 8em; float: left; }
p.s.: table designed mobile want avoid using position:absolute
or fixed margin widths.
change #symbol
rule following:
#symbol{ /* width: 5em; remove */ font-family: avenircondensed; font-size: 5em; text-align:center; /* margin: 0 auto; remove */ }
your width causing symbol spill on div sitting in, breaking flow. margin: 0 auto
no longer needed after that.
also, side note, should using more classes instead of id's. id's intended elements used once per page. can set #symbol
class .symbol
.amass
, anumber
. allow set css rules once , use them each element in table.
Comments
Post a Comment