auto space between horizontal divs in CSS

后端 未结 4 504
北海茫月
北海茫月 2021-02-08 03:36

I\'ve searched a lot but I was not lucky to find a solution to what I am after!

Here is the issue: I\'ve created a master div (width 100%) and within it there are severa

4条回答
  •  醉梦人生
    2021-02-08 04:11

    First and foremost, you cannot use the same ID more than once per HTML page.

    Secondly, you are on the right track. Just use a margin-right on every element, then proceed to add a psuedo-class of last-child and set margin to 0.

    http://jsfiddle.net/EAkLb/1/

    To make it work that way for any amount of divs, it would be best practice to still establish a percentage that makes sense. (ie 25% for 4, 33% for 3, 16.6% for 6, etc)


    EDIT:

    This here would be a much better way to do it (try resizing the window):

    http://jsfiddle.net/EAkLb/5/

提交回复
热议问题