html - Expand elements to width of div -


i have 27 hyperlink elements in container div. hyperlinks alphabet letters this:

a | b | c | d | e | f | g | h | | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z | all

the div width of page. right now, have class on anchor tags sets left , right padding 3px, have spacing in between pipes. problem letters float left , left bunch of white space right of letters. how achieve spacing letters (i.e. padding), letters expand width of container div? thinking padding dynamic in such way set based on width of container div.

<style type="text/css"> .container { width:100%; } .alphabetlinks { padding: 0px 3px; } </style>  <html> <div class="container"> <a class="alphabetlinks">a</a> | <a class="alphabetlinks">b</a> | </html> 

update: solution must support ie9 , above.

option 1 - modern browsers

  • you can use flexbox that

.container {    display: flex  }  {    flex: 1;    position:relative;    text-align:center  }  a::after {    content: "|";    position: absolute;    right:0  }  a:last-of-type::after {    content: ""  }
<div class="container">    <a class="alphabetlinks">a</a>    <a class="alphabetlinks">b</a>    <a class="alphabetlinks">c</a>    <a class="alphabetlinks">d</a>    <a class="alphabetlinks">e</a>    <a class="alphabetlinks">f</a>    <a class="alphabetlinks">g</a>    <a class="alphabetlinks">h</a>    <a class="alphabetlinks">i</a>    <a class="alphabetlinks">j</a>    <a class="alphabetlinks">k</a>    <a class="alphabetlinks">l</a>    <a class="alphabetlinks">m</a>    <a class="alphabetlinks">n</a>    <a class="alphabetlinks">o</a>    <a class="alphabetlinks">p</a>    <a class="alphabetlinks">q</a>    <a class="alphabetlinks">r</a>    <a class="alphabetlinks">s</a>    <a class="alphabetlinks">t</a>    <a class="alphabetlinks">u</a>    <a class="alphabetlinks">v</a>    <a class="alphabetlinks">y</a>    <a class="alphabetlinks">z</a>    <a class="alphabetlinks">all</a>  </div>

option 2 - fallback older browsers

  • you can use css tables that

.container {    display: table;    width:100%  }  {    display:table-cell;    position:relative;    text-align:center  }  a:after {    content: "|";    position: absolute;    right:0  }  a:last-child:after {    content: ""  }
<div class="container">    <a class="alphabetlinks">a</a>    <a class="alphabetlinks">b</a>    <a class="alphabetlinks">c</a>    <a class="alphabetlinks">d</a>    <a class="alphabetlinks">e</a>    <a class="alphabetlinks">f</a>    <a class="alphabetlinks">g</a>    <a class="alphabetlinks">h</a>    <a class="alphabetlinks">i</a>    <a class="alphabetlinks">j</a>    <a class="alphabetlinks">k</a>    <a class="alphabetlinks">l</a>    <a class="alphabetlinks">m</a>    <a class="alphabetlinks">n</a>    <a class="alphabetlinks">o</a>    <a class="alphabetlinks">p</a>    <a class="alphabetlinks">q</a>    <a class="alphabetlinks">r</a>    <a class="alphabetlinks">s</a>    <a class="alphabetlinks">t</a>    <a class="alphabetlinks">u</a>    <a class="alphabetlinks">v</a>    <a class="alphabetlinks">y</a>    <a class="alphabetlinks">z</a>    <a class="alphabetlinks">all</a>  </div>


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo