Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <body>
  <section>
    <div class="column card-style">
      <figure>
        <img src="https://raw.githubusercontent.com/ccania/playground/master/flexbox-cards-cactus/img/cact1.jpg" alt="cactus stock image">
      </figure>
      <div class="card-text">
        <h1>Sahara</h1>
        <p class="ellipsis">Cacti are native through most of the length of North and South America, from British Columbia and Alberta southward; the southernmost limit of their range extends far into Chile and Argentina. Mexico has the greatest number and variety of species.
          The only cacti possibly native to the Old World are members of the tropical genus Rhipsalis, occurring in East Africa, Madagascar, and Sri Lanka.
        </p>
      </div>
    </div>
    <div class="column card-style">
      <figure>
        <img src="https://raw.githubusercontent.com/ccania/playground/master/flexbox-cards-cactus/img/cact2.jpg" alt="cactus stock image">
      </figure>
      <div class="card-text">
        <h1>Mohave</h1>
        <p class="ellipsis">Cacti are succulent perennial plants. Although a few species inhabit tropical or subtropical areas, most live in and are well adapted to dry regions. Cacti generally have thick herbaceous or woody chlorophyll-containing stems. In most species
          leaves are either absent or greatly reduced, minimizing the amount of surface area from which water can be lost, and the stem has taken over the photosynthetic functions of the plant. Only the tropical genera Pereskia and Pereskopsis, both vines,
          have conventional-looking functional leaves, while the leaves of the Andean Maihuenia are rounded, not flattened. The root systems are generally thin, fibrous, and shallow, ranging widely to absorb superficial moisture.</p>
      </div>
    </div>
    <div class="column card-style">
      <figure>
        <img src="https://raw.githubusercontent.com/ccania/playground/master/flexbox-cards-cactus/img/cact3.jpg" alt="cactus stock image">
      </figure>
      <div class="card-text">
        <h1>Gobi</h1>
        <p class="ellipsis">Cacti vary greatly in size and general appearance, from buttonlike peyote (Lophophora) and low clumps of prickly pear (Opuntia) and hedgehog cactus (Echinocereus) to the upright columns of barrel cacti (Ferocactus and Echinocactus) and the imposing
          saguaro (Carnegiea gigantea). Most cacti grow in the ground, but several tropical species—including leaf cactus (Epiphyllum), Rhipsalis, and Schlumbergera—are epiphytes, growing on other plants; others live on hard substrates such as rocks,
          while yet others climb far up trees. Epiphytic species tend to have thin, almost leaflike flattened stems. The appearance of the plant varies also according to whether the stem surface is smooth or ornamented with protruding tubercles, ridges,
          or grooves.</p>
      </div>

    </div>
    <div class="column card-style">
      <figure>
        <img src="https://raw.githubusercontent.com/ccania/playground/master/flexbox-cards-cactus/img/cact4.jpg" alt="cactus stock image">
      </figure>
      <div class="card-text">
        <h1>Negev</h1>
        <p class="ellipsis">Cacti are widely cultivated as ornamentals. In addition, various species, notably prickly pears and chollas (both Opuntia), are cultivated as food. In South America species of Opuntia, Cereus, and others are used as living fences, and wood from
          columnar cacti is used as fuel in some desert regions. Barrel cacti (Echinocactus and Ferocactus) are a source of water in emergencies. Peyote, from Lophophora williamsii, has been used ceremonially since pre-Columbian times for its hallucinogenic
          properties.</p>
      </div>
    </div>
  </section>
  <script src="js/truncate.js"></script>
</body>
              
            
!

CSS

              
                body {
  font-family: Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: dimgray;
}

section {
  display: flex;
  flex-flow: row wrap;
}

P {
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 16px;
}

H1 {
  font-family: "IBM Plex Sans", sans-serif;
  font-weight: 100;
  text-transform: uppercase;
  font-size: 28px;
}

figure {
  margin: 0px;
}

figure img {
  width: 100%;
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;
}

figure img:hover {
  opacity: 0.6;
  transition: all .3s linear;
}
.column {
  box-sizing: border-box;
  flex: 1 100%;
  justify-content: space-evenly;
  margin: 20px;
}
.card-style {
  border-radius: 12px;
  border-image-slice: 1;
  box-shadow: 0px 1px 2px 0px rgba(0, 0, 0, 0.4);
  transition: all 0.25s linear;
}
.card-style:hover {
  box-shadow: -1px 10px 29px 0px rgba(0, 0, 0, 0.8);
}

.card-text {
  padding: 20px;
}

@media (min-width: 500px) {
  .column {
      flex: 0 0 calc(100%/2 - 40px);
  }
}

@media (min-width: 900px) {
    .column {
      flex: 0 0 calc(100%/4 - 40px);
  }
}
              
            
!

JS

              
                /**
 * Created by ccania.
 */
var para = document.querySelectorAll(".ellipsis");

for (var i = 0; i < para.length; i++) {
    var paraTxt = para[i].innerHTML;

    if (paraTxt.length > 200) {

        var newPara = document.createElement("p"); //create new paragraph element
        newPara.className = "ellipsis-trunc";
        var newParaTxt = document.createTextNode(paraTxt.substring(0,200)+"...");
        //create new text node

        newPara.appendChild(newParaTxt); //bind new text node to new element
        para[i].replaceWith(newPara);

    } else {
        console.log("I've got nothing");
    }

}




              
            
!
999px

Console