k1op0ly
k1op0ly

Reputation: 1

How to position cards

My question is how to position these cards on my website?

https://i.sstatic.net/wsMlC.jpg

It would be easy if there isn't this half circles above them. I have tried to create parent class="cards" and class="card" for each of 3 cards. In css:

.cards { display: flex } 
.card { width: 33.33% }

And set relative position to my background and absolute position to my half-circles but I want to do it without absolute and relative positions if it's possible.

.cards {
  display: flex;
}

.card {
  width: 33.33%;
  color: #fff;
  text-align: center;
}

.card p {
  min-height: 80px;
  padding: 0 39px 0 39px;
}

.strategy--logo {
  position: absolute;
  top: 383px;
  left: 607px;
  width: 96px;
  height: 48px;
  background-color: #5a471b;
  border-top-right-radius: 48px;
  border-top-left-radius: 48px;
}

.strategy {
  margin-top: 135px;
  background-color: #5a471b;
}

.crop--marketing {
  margin-top: 135px;
  background-color: #9fa374;
}

.risk--mgmt {
  margin-top: 135px;
  background-color: #666;
}
<div class="cards">
  <div class="card">
    <div class="strategy">
      <div class="strategy--logo">
        <img src="css/images/strategy-logo.png" alt="" />
      </div>
      <!-- /.strategy-/-logo -->

      <h2>

      </h2>

      <p>

      </p>
    </div>
    <!-- /.crop-/-marketing -->
  </div>
  <!-- /.card -->

  <div class="card">
    <div class="crop--marketing">
      <img src="css/images/crop-logo.png" alt="" />

      <h2>

      </h2>

      <p>

      </p>
    </div>
    <!-- /.crop-/-marketing -->
  </div>
  <!-- /.card -->

  <div class="card">
    <div class="risk--mgmt">
      <img src="css/images/arrow-logo.png" alt="" />

      <h2>

      </h2>

      <p>

      </p>
    </div>
    <!-- /.risk-/-mgmt -->
  </div>
  <!-- /.card -->
</div>
<!-- /.cards -->

Now I'm using absolute and relative but is there another way? Because when I resize my web browser the circles go away random ...

Upvotes: 0

Views: 14292

Answers (2)

Mrigank Pawagi
Mrigank Pawagi

Reputation: 922

Are you trying to achieve this?

.card {
  displaY: block;
  float: left;
  width: 33.33%;
  text-align: center;
  color: white;
  font-family: 'Calibri';
}

.icon {
  width: 50px;
  height: 25px;
  /*half of width*/
  margin: auto;
  display: block;
  border-radius: 50px 50px 0 0;
}

.fa {
  margin-top: 10px;
}

.text {
  padding: 25px;
}

.strategy .text,
.strategy .icon {
  background-color: #5c471c;
}

.crop .text,
.crop .icon {
  background-color: #a0a175;
}

.risk .text,
.risk .icon {
  background-color: #666666;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet" />
<div class="card strategy">
  <div class="icon">
    <i class="fa fa-area-chart" aria-hidden="true"></i>
  </div>
  <div class="text">
    Our Strategy
  </div>
</div>
<div class="card crop">
  <div class="icon">
    <i class="fa fa-pagelines" aria-hidden="true"></i>
  </div>
  <div class="text">
    Crop Marketing
  </div>
</div>
<div class="card risk">
  <div class="icon">
    <i class="fa fa-arrow-down" aria-hidden="true"></i>
    <i class="fa fa-arrow-up" aria-hidden="true"></i>
  </div>
  <div class="text">
    Commodity Risk Management
  </div>
</div>

Upvotes: 1

Yuliya Ulanova
Yuliya Ulanova

Reputation: 23

Is the main problem that when you use position your layout changes its position elsewhere?

If so, to use position property is ok if you make a few changes:

CSS

.strategy--logo { 
    position: absolute; 

    /* Remove this top parameter, use transform instead */

    /* top:383px;  */

    /* Instead your value of a left use value of 50% and transform left 
    and right properties like it is changed below */

    /* left: 607px;  */
    left: 50%;
    transform: translate(-50%, -100%);        

    width: 96px; height: 48px; 
    background-color: #5a471b; 
    border-top-right-radius: 48px; 
    border-top-left-radius: 48px; 
}

.strategy { 

    /* add position relative to a parent of strategy-logo */

    position: relative; 

    margin-top: 135px; 
    background-color: #5a471b; 
}  

Then your code will stay in the same position even if you resize the screen.

Upvotes: 0

Related Questions