0

so my problem is that I can not order elements that are cards in row. I want to put 3 cards in one row so that my page will look more lovely. In the presented code down from this text you can see that I am using divs for containers for the cards. Also I am using box-sizing: border-box, position: relative and display: inline-block. But for some reason the inline-block is not working and I do not know why... Have been stucked for a couple of days wondering how to do it and where I am doing something wrong with the inline-block.

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.cards_container {
  margin: 0 auto;
  padding: 0 150px;
  margin-top: 50px;
  width: auto;
  font-size: 0;
  min-height: auto;
  margin-left: auto;
  margin-right: auto;
  max-width: 2000px;
}

.card {
  -webkit-box-sizing: border-box;
  /* Safari/Chrome, other WebKit */
  -moz-box-sizing: border-box;
  /* Firefox, other Gecko */
  box-sizing: border-box;
  /* Opera/IE 8+ */
  position: relative;
  display: inline-block;
  background: white;
  width: 30%;
  height: auto;
  margin: 0 1%;
  margin-bottom: 2%;
  border-radius: 10px;
  border-style: solid;
  border-color: rgb(90, 16, 141);
}

.card:hover {
  cursor: pointer;
  transform: scale(1.05);
  transition: all 0.5s ease;
}

.card_image {
  -webkit-box-sizing: border-box;
  /* Safari/Chrome, other WebKit */
  -moz-box-sizing: border-box;
  /* Firefox, other Gecko */
  box-sizing: border-box;
  /* Opera/IE 8+ */
  height: 320px;
  width: 100%;
  object-fit: contain;
  border-top-left-radius: 7px;
  border-top-right-radius: 7px;
}

.card_title_p {
  -webkit-box-sizing: border-box;
  /* Safari/Chrome, other WebKit */
  -moz-box-sizing: border-box;
  /* Firefox, other Gecko */
  box-sizing: border-box;
  /* Opera/IE 8+ */
  padding: 0;
  margin: 0;
  text-align: center;
  font-size: 19px;
  padding: 10px;
  padding-bottom: 0;
  height: 32px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: context-menu;
}

.card_p {
  -webkit-box-sizing: border-box;
  /* Safari/Chrome, other WebKit */
  -moz-box-sizing: border-box;
  /* Firefox, other Gecko */
  box-sizing: border-box;
  /* Opera/IE 8+ */
  padding: 0;
  margin: 0;
  font-size: 16px;
  padding: 10px;
  height: 140px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 7;
  -webkit-box-orient: vertical;
  text-overflow: ellipsis;
  cursor: context-menu;
}

.card_info {
  -webkit-box-sizing: border-box;
  /* Safari/Chrome, other WebKit */
  -moz-box-sizing: border-box;
  /* Firefox, other Gecko */
  box-sizing: border-box;
  /* Opera/IE 8+ */
  text-align: center;
  font-size: 19px;
  color: rgb(118, 16, 141);
  padding: 7px;
  margin: 10px;
  background-color: rgb(238, 231, 243);
  border-radius: 10px;
  cursor: pointer;
}

.card_info:hover {
  transition: 0.25s;
  color: rgb(238, 231, 243);
  background-color: rgb(118, 16, 141);
}
<div class="cards_container">
  <div class="card">
    <img src="siteimages/CS3W.jfif" class="card_image">
    <p class="card_title_p"><b>HiKu (CS3W)</b></p>
    <div class="card_p">Model: CS3W<br> Cell type: Mono-crystalline<br> Power range: 430~455 W<br> Max. system Voltage: 1400V<br> Connector type: T4 or H4 UTX or MC4-EVO2</div>
    <div class="card_info" onclick="window.location.assign('ugabuga.html');">Learn more</div>
  </div>
</div>
depperm
  • 10,606
  • 4
  • 43
  • 67
  • I suggest using [flexbox](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox) to control the layout. If you add `display: flex;` to the `.cards_container`, the default layout will arrange its children in a row. – Sarah Jan 05 '23 at 18:52
  • FYI, you don't need vendor prefixes for `box-sizing`. See https://caniuse.com/?search=box-sizing. – isherwood Jan 05 '23 at 18:57

3 Answers3

0

For this situation I would recommend you to use display flex, let me show you:

.card {
   display: flex;
   align-items: center;
}

Display flex will put everything in one row, and then align-items will center them in the vertical axis. I hope this helps

0

you only have 1 div with class card. add others and inline-block works fine

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.cards_container {
  margin: 0 auto;
  padding: 0 150px;
  margin-top: 50px;
  width: auto;
  font-size: 0;
  min-height: auto;
  margin-left: auto;
  margin-right: auto;
  max-width: 2000px;
}

.card {
  -webkit-box-sizing: border-box;
  /* Safari/Chrome, other WebKit */
  -moz-box-sizing: border-box;
  /* Firefox, other Gecko */
  box-sizing: border-box;
  /* Opera/IE 8+ */
  position: relative;
  display: inline-block;
  background: white;
  width: 30%;
  height: auto;
  margin: 0 1%;
  margin-bottom: 2%;
  border-radius: 10px;
  border-style: solid;
  border-color: rgb(90, 16, 141);
}

.card:hover {
  cursor: pointer;
  transform: scale(1.05);
  transition: all 0.5s ease;
}

.card_image {
  -webkit-box-sizing: border-box;
  /* Safari/Chrome, other WebKit */
  -moz-box-sizing: border-box;
  /* Firefox, other Gecko */
  box-sizing: border-box;
  /* Opera/IE 8+ */
  height: 320px;
  width: 100%;
  object-fit: contain;
  border-top-left-radius: 7px;
  border-top-right-radius: 7px;
}

.card_title_p {
  -webkit-box-sizing: border-box;
  /* Safari/Chrome, other WebKit */
  -moz-box-sizing: border-box;
  /* Firefox, other Gecko */
  box-sizing: border-box;
  /* Opera/IE 8+ */
  padding: 0;
  margin: 0;
  text-align: center;
  font-size: 19px;
  padding: 10px;
  padding-bottom: 0;
  height: 32px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: context-menu;
}

.card_p {
  -webkit-box-sizing: border-box;
  /* Safari/Chrome, other WebKit */
  -moz-box-sizing: border-box;
  /* Firefox, other Gecko */
  box-sizing: border-box;
  /* Opera/IE 8+ */
  padding: 0;
  margin: 0;
  font-size: 16px;
  padding: 10px;
  height: 140px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 7;
  -webkit-box-orient: vertical;
  text-overflow: ellipsis;
  cursor: context-menu;
}

.card_info {
  -webkit-box-sizing: border-box;
  /* Safari/Chrome, other WebKit */
  -moz-box-sizing: border-box;
  /* Firefox, other Gecko */
  box-sizing: border-box;
  /* Opera/IE 8+ */
  text-align: center;
  font-size: 19px;
  color: rgb(118, 16, 141);
  padding: 7px;
  margin: 10px;
  background-color: rgb(238, 231, 243);
  border-radius: 10px;
  cursor: pointer;
}

.card_info:hover {
  transition: 0.25s;
  color: rgb(238, 231, 243);
  background-color: rgb(118, 16, 141);
}
<div class="cards_container">
  <div class="card">
    <img src="siteimages/CS3W.jfif" class="card_image">
    <p class="card_title_p"><b>HiKu (CS3W)</b></p>
    <div class="card_p">Model: CS3W<br> Cell type: Mono-crystalline<br> Power range: 430~455 W<br> Max. system Voltage: 1400V<br> Connector type: T4 or H4 UTX or MC4-EVO2</div>
    <div class="card_info" onclick="window.location.assign('ugabuga.html');">Learn more</div>
  </div>
  <div class="card">
    <img src="siteimages/CS3W.jfif" class="card_image">
    <p class="card_title_p"><b>HiKu (CS3W)</b></p>
    <div class="card_p">Model: CS3W<br> Cell type: Mono-crystalline<br> Power range: 430~455 W<br> Max. system Voltage: 1400V<br> Connector type: T4 or H4 UTX or MC4-EVO2</div>
    <div class="card_info" onclick="window.location.assign('ugabuga.html');">Learn more</div>
  </div>
  <div class="card">
    <img src="siteimages/CS3W.jfif" class="card_image">
    <p class="card_title_p"><b>HiKu (CS3W)</b></p>
    <div class="card_p">Model: CS3W<br> Cell type: Mono-crystalline<br> Power range: 430~455 W<br> Max. system Voltage: 1400V<br> Connector type: T4 or H4 UTX or MC4-EVO2</div>
    <div class="card_info" onclick="window.location.assign('ugabuga.html');">Learn more</div>
  </div>
</div>
DCR
  • 14,737
  • 12
  • 52
  • 115
-1

why don\t you wrap the cards in a div and display the div as flex? e.g

<div class="container">
    <div class="card"></div>
    <div class="card"></div>
    <div class="card"></div>
</div>

<style>
 .container:{
    display: 'flex',
    flexDirection: 'row',
    justify-content: 'space-between',
    align-items: 'center',
  }
</style>
kelvin torver
  • 49
  • 1
  • 7