Divide in circles with responsive layout

Asked

Viewed 1,790 times

4

I’m trying to make a page that contains div in circles and which fit one below the other when the layout decrease, for example, to cell phone sizes. With the common size I would like them to be 4 side-by-side and when decreasing they are below each other. I read something about media queries and I’m trying to implement, but in case anyone knows and could help me with something.

I can’t leave a little space between the div.

Follow the code I’m currently using:

.center-content {
  border: solid 1px #000;
  width: 100%;
}

.center-content div {
  border-radius: 50%;
  display: table-cell;
  vertical-align: middle;
  text-align: center;
  width: 100px;
  height: 100px;
  background-color: #229922;
}
<div class="center-content">
  <div>Texto</div>
  <div>Texto</div>
  <div>Texto</div>
  <div>Texto</div>
  <br/>
  <div>Texto</div>
  <div>Texto</div>
  <div>Texto</div>
  <div>Texto</div>
</div>

1 answer

7


I was able to find two alternatives:

  1. Using inline-block
  2. Using inline-flex

Using inline-block

To have more coverage you can use the display inline-block thus:

.master {
	border: solid 1px #000;
	max-width: 500px;
    font-size: 0;
}

.master div {
    border-radius: 50%;
    display: inline-block;
    text-align: center;
    margin: 10px;
    width: 100px;
    line-height: 100px;
    background-color: #229922;
    font-size: 40px;
}

body{
    color: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button onclick="$('.master').width($('.master').width()-25)">Clique para reduzir largura em 25px</button>
<button onclick="$('.master').width($('.master').width()+25)">Clique para reduzir largura em 25px</button>
<div class="master">
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
    <div>7</div>
    <div>8</div>
</div>

    jsFiddle: It’s easier to resize with the mouse

Using inline-flex

If you have no restrictions on using some more modern CSS like inline-flex, can do so:

.master {
	border: solid 1px #000;
	max-width: 500px;
    font-size: 0;
}

.master div {
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 10px;
    width: 100px;
    height: 100px;
    background-color: #229922;
    font-size: 40px;
}


body{
    color: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button onclick="$('.master').width($('.master').width()-25)">Clique para reduzir largura em 25px</button>
<button onclick="$('.master').width($('.master').width()+25)">Clique para reduzir largura em 25px</button>
<div class="master">
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
    <div>7</div>
    <div>8</div>
</div>

    jsFiddle: It’s easier to resize with the mouse

  • I didn’t know this inline-flex... Works very well on IE10+, however none of this module Flexible Box Layout works on IE9... has some parallel of this?

  • It does, but then I’m pretty sure you’ll have to mess with the HTML structure.

  • Well, anyway it worked great for the rest... worth the best answer. VLW

  • 1

    @Marco I updated the answer with another alternative, which uses inline-block. I was wrong, there will be no need to change the structure to use something better known CSS.

  • I have my doubts about that display:inline-flex applied to children. In these flexbox, usually who receives the rule is the parent element. For example, .master { display: inline-flex; flex-flow: row wrap } - Fiddle.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.