md-card growing bigger than the screen - layout
I hope someone can help me with this piece of code that I have been struggling with for the last couple of hours. I have a grid of cards with a somewhat responsive design. see this pen.My problem is that I do not understand why the 3rd and 4th cards don't fit the screen like the rest of them and instead their width gets increased a lot more than needed.
Just a heads up, I cannot use md-grid so if you can point me to what's wrong with the current code or element distribution I will really appreciate it.
<div ng-controller="MainCtrl" ng-cloak layout flex>
<!-- Some side content -->
<div id="sideContent" hide-xs flex-sm="33" flex-md="30" flex-lg="25" layout="column" class="md-whiteframe-z2" style="z-index: 55">
<p>Some side content</p>
<p>Lorem ipsum dolor sit amet, affert melius disputando ex his. Sit an unum disputando ullamcorper, his ne summo nostrud graecis. At modus nulla vidisse nam, pro et alienum iudicabit repudiandae, mei te dictas dignissim reprehendunt. Vivendum gloriatur
adversarium te nec, liber apeirian tractatos ad pri, choro latine voluptatibus eu est. Ne maluisset liberavisse eos, et luptatum referrentur per.</p>
<p>Lorem ipsum dolor sit amet, affert melius disputando ex his. Sit an unum disputando ullamcorper, his ne summo nostrud graecis. At modus nulla vidisse nam, pro et alienum iudicabit repudiandae, mei te dictas dignissim reprehendunt. Vivendum gloriatur
adversarium te nec, liber apeirian tractatos ad pri, choro latine voluptatibus eu est. Ne maluisset liberavisse eos, et luptatum referrentur per.</p>
<p>Lorem ipsum dolor sit amet, affert melius disputando ex his. Sit an unum disputando ullamcorper, his ne summo nostrud graecis. At modus nulla vidisse nam, pro et alienum iudicabit repudiandae, mei te dictas dignissim reprehendunt. Vivendum gloriatur
adversarium te nec, liber apeirian tractatos ad pri, choro latine voluptatibus eu est. Ne maluisset liberavisse eos, et luptatum referrentur per.</p>
</div>
<md-content style="z-index: 54; position: relative;" flex>
<div layout layout-wrap>
<!-- Custom sized card -->
<div layout flex="35" flex-md="100" flex-xs="100" flex-sm="100">
<md-card flex="noshrink" style="width:300px;height:700px;">
<md-toolbar class="md-hue-2">
<div class="md-toolbar-tools">
<h3><span>Card 1</span></h3>
</div>
</md-toolbar>
<md-card-content layout="column" layout-padding>Content in card 1</md-card-content>
<span flex></span>
<md-card-icon-actions layout>
<span flex></span>
<md-button aria-label="details">
<span>Details</span>
</md-button>
</md-card-icon-actions>
</md-card>
</div>
<div layout flex flex-md="100" flex-xs="100" flex-sm="100">
<div layout layout-wrap flex>
<!-- Card 2 -->
<md-card flex="noshrink" style="min-width:300px;">
<md-toolbar class="md-hue-2">
<div class="md-toolbar-tools">
<h3><span>Card 2</span></h3>
</div>
</md-toolbar>
<md-card-content layout="column" layout-padding>
Content in card 2
<md-select placeholder="{{data.currentSelected}}" ng-model="selection">
<md-option ng-value="$index" ng-repeat="text in data.options">{{text.text}}</md-option>
</md-select>
<span>Some random text<br />
More random text, with some more text</span>
</md-card-content>
<span flex></span>
<md-card-icon-actions layout>
<span flex></span>
<md-button aria-label="details">
<span>Details</span>
</md-button>
</md-card-icon-actions>
</md-card>
<!-- tabs -->
<md-card flex="noshrink" style="min-width:300px;">
<md-toolbar class="md-hue-2">
<div class="md-toolbar-tools">
<h3><span>Card 3</span></h3>
</div>
</md-toolbar>
<md-card-content layout="column" layout-padding>
<md-tabs md-selected="1" md-center-tabs flex>
<md-tab ng-repeat="tab in data.tabs">
<md-tab-label>{{tab.name}}</md-tab-label>
<md-tab-body>
<div style="padding-top:20px;">
<md-list-item class="md-2-line" ng-repeat="content in tab.content">
<img ng-attr-src="http://placehold.it/{{::content.image}}" class="md-avatar" />
<div class="md-list-item-text" layout="column">
<h3>{{::content.title}}</h3>
<p>{{::content.data}}</p>
</div>
<md-icon class="material-icons">
cached
<md-tooltip>Icon 1</md-tooltip>
</md-icon>
<span style="margin-left:5px;"></span>
<md-icon class="material-icons">
cached
<md-tooltip>Icon 2</md-tooltip>
</md-icon>
</md-list-item>
</div>
</md-tab-body>
</md-tab>
</md-tabs>
</md-card-content>
<span flex></span>
<md-card-icon-actions layout>
<span flex></span>
<md-button aria-label="details">
<span>Details</span>
</md-button>
</md-card-icon-actions>
</md-card>
</div>
</div>
</div>
<!-- Lorem -->
<div layout flex>
<div layout flex>
<md-card flex="noshrink" style="min-width:300px;">
<md-toolbar class="md-hue-2">
<div class="md-toolbar-tools">
<h3><span>Card 4</span></h3>
</div>
</md-toolbar>
<md-card-content layout="column" layout-padding>{{::data.lorem}}</md-card-content>
<span flex></span>
<md-card-icon-actions layout>
<span flex></span>
<md-button aria-label="details">
<span>Details</span>
</md-button>
</md-card-icon-actions>
</md-card>
</div>
</div>
<div layout layout-wrap>
<!-- Card 5 -->
<div layout flex>
<md-card flex="noshrink" style="width:300px;">
<md-toolbar class="md-hue-2">
<div class="md-toolbar-tools">
<h3><span>Card 5</span></h3>
</div>
</md-toolbar>
<md-card-content layout="column" layout-padding>
<div ng-repeat="content in data.content">{{::content}}</div>
</md-card-content>
<span flex></span>
<md-card-icon-actions layout>
<span flex></span>
<md-button aria-label="details">
<span>Details</span>
</md-button>
</md-card-icon-actions>
</md-card>
</div>
<div layout flex></div>
<!-- Card 6 -->
<div layout flex>
<md-card flex="noshrink" style="width:300px;">
<md-toolbar class="md-hue-2">
<div class="md-toolbar-tools">
<h3><span>Card 6</span></h3>
</div>
</md-toolbar>
<md-card-content layout="column" layout-padding>
<md-subheader class="md-no-sticky">Some addresses {{::data.addresses.expiry_date}}</md-subheader>
<md-list-item class="md-3-line" ng-repeat="address in data.addresses.address">
<md-button class="md-icon-button" href="http://maps.google.com/maps?q=255 Queens Avenue London ON Canada" target="_blank" md-autofocus>
<md-icon class="material-icons">place</md-icon>
<md-tooltip>Open address in Google map</md-tooltip>
</md-button>
<div class="md-list-item-text" layout="column">
<h3>{{::address.description}}</h3>
<p>{{::address.street}}</p>
<p>{{::address.city}}, {{::address.postal_code}}</p>
</div>
</md-list-item>
</md-card-content>
<span flex></span>
<md-card-icon-actions layout>
<span flex></span>
<md-button aria-label="details">
<span>Details</span>
</md-button>
</md-card-icon-actions>
</md-card>
</div>
</div>
</md-content>
</div>
Related
Symmetrically shrinking Tailwind cards
I have four cards aligned in flex raw. Each card has image and text respectively. The gap between each card is 24px (gap-6). However the image sizes of cards are not equal and when shrinks the proportion/symmetry is not maintained. Kindly, advice how can I fix this. Respective code is in playground: https://play.tailwindcss.com/BEc01nvdZj
Here's how I would approach it: First, we would set each card to take 1/4 of its container by applying w-1/4 to each card. We'll also use a responsive utility (md:) because we want each card to take the full width of the container when the screen is smaller than 768px: <div class="max-w-sm border bg-white md:w-1/4"> <img src="https://images.unsplash.com/photo-1605546290557-ff57ffe5abcc" alt="" class="h-[12.5rem] w-full object-cover" /> <div class="p-5"> <a href="#"> <h5 class="font-NotoSansGeo mb-2 text-lg font-bold leading-normal md:text-xl">Lorem, ipsum dolor.</h5> </a> <p class="mb-3 text-sm font-normal leading-normal text-gray-700 dark:text-gray-400">Lorem ipsum dolor sit amet consectetur adipisicing elit. Laborum asperiores expedita harum eius veritatis minus unde et minima aut numquam!.</p> </div> </div> Now that we have a fixed position for each card, we'll apply some classes to take care of the images width, height, and content. width: Each image should take the whole width of the container. Therefore we apply w-full. height: Each image should have a fixed height. This way, we can ensure that the height of each image will be identical. In this example, I set the height to be h-[12.5rem]. content (Docs): We want to make sure that each image will always cover the full size we set (full width and 12.5rem height). This is why we use the object-cover utility. This utility will make sure that the image will cover its container. We could also use object-fill but it will stretch the image quite a bit. <img src="https://images.unsplash.com/photo-1605546290557-ff57ffe5abcc" alt="" class="h-[12.5rem] w-full object-cover" /> Tailwind-play Full Code: <section class="container mx-auto my-4"> <div class="section-header"> <div class="section-title"><h1 class="font-BPGBannerCaps font-bold tracking-wide">Lorem, ipsum.</h1></div> <hr class="mb-4 h-px border-0 bg-gray-400 dark:bg-gray-700" /> </div> <div class="projects w-full md:flex md:gap-6"> <div class="max-w-sm border bg-white md:w-1/4"> <img src="https://images.unsplash.com/photo-1605546290557-ff57ffe5abcc" alt="" class="h-[12.5rem] w-full object-cover" /> <div class="p-5"> <a href="#"> <h5 class="font-NotoSansGeo mb-2 text-lg font-bold leading-normal md:text-xl">Lorem, ipsum dolor.</h5> </a> <p class="mb-3 text-sm font-normal leading-normal text-gray-700 dark:text-gray-400">Lorem ipsum dolor sit amet consectetur adipisicing elit. Laborum asperiores expedita harum eius veritatis minus unde et minima aut numquam!.</p> </div> </div> <div class="max-w-sm border bg-white md:w-1/4"> <img src="https://images.unsplash.com/photo-1526628953301-3e589a6a8b74" alt="" class="h-[12.5rem] w-full object-cover" /> <div class="p-5"> <a href="#"> <h5 class="font-NotoSansGeo mb-2 text-lg font-bold leading-normal md:text-xl">Lorem ipsum dolor sit amet consectetur.</h5> </a> <p class="mb-3 text-sm font-normal leading-normal text-gray-700 dark:text-gray-400">Lorem ipsum dolor sit amet consectetur adipisicing elit. Sed, repellat dolore. Reprehenderit, modi ullam placeat nam pariatur quas perspiciatis possimus porro ratione? Ad molestias perspiciatis iste ex unde neque enim repellendus sed fugiat consectetur? Voluptatem expedita eum voluptatum explicabo modi.</p> </div> </div> <div class="max-w-sm border bg-white md:w-1/4"> <img src="https://images.unsplash.com/photo-1635695604201-2b718204bccb" alt="" class="h-[12.5rem] w-full object-cover" /> <div class="p-5"> <a href="#"> <h5 class="font-NotoSansGeo mb-2 text-lg font-bold leading-normal md:text-xl">Lorem ipsum dolor sit amet consectetur adipisicing elit. Eum.</h5> </a> <p class="mb-3 text-sm font-normal leading-normal text-gray-700 dark:text-gray-400">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Soluta animi atque totam eos nam doloremque iusto qui odio officia doloribus saepe aspernatur dolore eligendi culpa, quos aliquam vel voluptatibus non!</p> </div> </div> <div class="max-w-sm border bg-white md:w-1/4"> <img src="https://images.unsplash.com/photo-1640545232493-9a9b5c88ede4" alt="" class="h-[12.5rem] w-full object-cover" /> <div class="p-5"> <a href="#"> <h5 class="font-NotoSansGeo mb-2 text-lg font-bold leading-normal md:text-xl">Lorem ipsum dolor sit amet consectetur adipisicing elit. Fugiat enim saepe ex. Temporibus, atque nihil.</h5> </a> <p class="mb-3 text-sm font-normal leading-normal text-gray-700 dark:text-gray-400">Lorem ipsum, dolor sit amet consectetur adipisicing elit. Repellendus velit voluptate, doloremque asperiores sapiente earum ut obcaecati ipsa necessitatibus itaque similique incidunt. Blanditiis modi nulla pariatur inventore soluta, quo similique quidem quasi perspiciatis nesciunt numquam rerum natus tenetur, consequatur nihil atque, beatae error itaque aspernatur iusto? Architecto vel ea cupiditate.</p> </div> </div> </div> </section>
Get content between html tags using grep
I have a html file which I am trying to get data from. The website is this https://www.tv2.no/nyheter. I am trying to get all the news article from the website. I do this wget -O news.html https://www.tv2.no/nyheter this creates a local file for me. Then I am trying to get all the articles having class article--nyheter. I try running this command tr '\n' ' ' < news.html | grep -E "^<article class="article-nyheter">.*$" but I did not got any result. The html structure is like this <body> <div> <article class="article column large-4 small-12"> hello </article> </div> <article class="article column large-4 small-12 article--nyheter"> <a class="article__link" href="/nyheter/14336304/"> <figure class="image image__responsive" style="padding-bottom:51.312%;"> <img class="image__img lazyload" itemprop="image" title="" alt="" src="data:image/gif;base64,R0lGODlhEAAJAIAAAP///wAAACH5BAEAAAAALAAAAAAQAAkAAAIKhI+py+0Po5yUFQA7" data-src="https://www.cdn.tv2.no/images/14336482.jpg?imageId=14336482&panox=0&panoy=0&panow=100&panoh=50.993377483444&heighty=0&heightx=0&heightw=100&heighth=100&width=344&height=177" data-srcset="https://www.cdn.tv2.no/images/14336482.jpg?imageId=14336482&panox=0&panoy=0&panow=100&panoh=50.993377483444&heighty=0&heightx=0&heightw=100&heighth=100&width=688&height=354&compression=92 2x,https://www.cdn.tv2.no/images/14336482.jpg?imageId=14336482&panox=0&panoy=0&panow=100&panoh=50.993377483444&heighty=0&heightx=0&heightw=100&heighth=100&width=516&height=265.5&compression=92 1.5x,https://www.cdn.tv2.no/images/14336482.jpg?imageId=14336482&panox=0&panoy=0&panow=100&panoh=50.993377483444&heighty=0&heightx=0&heightw=100&heighth=100&width=344&height=177&compression=92 1x"> </figure> <div class="article__content"> <h2 class="article__title t27 tm26">IEA: Mulig å nå 2-gradersmålet om løftene fra Glasgow holdes</h2> </div> </a> </article> <article class="article column large-4 small-12 article--nyheter"> <a class="article__link" href="/nyheter/14336420/"> <figure class="image image__responsive" style="padding-bottom:115.452%;"> <img class="image__img lazyload" itemprop="image" title="" alt="" src="data:image/gif;base64,R0lGODlhEAAJAIAAAP///wAAACH5BAEAAAAALAAAAAAQAAkAAAIKhI+py+0Po5yUFQA7" data-src="https://www.cdn.tv2.no/images/14336464.jpg?imageId=14336464&panox=0&panoy=0&panow=100&panoh=100&heighty=0&heightx=0&heightw=100&heighth=100&width=344&height=398" data-srcset="https://www.cdn.tv2.no/images/14336464.jpg?imageId=14336464&panox=0&panoy=0&panow=100&panoh=100&heighty=0&heightx=0&heightw=100&heighth=100&width=688&height=796&compression=92 2x,https://www.cdn.tv2.no/images/14336464.jpg?imageId=14336464&panox=0&panoy=0&panow=100&panoh=100&heighty=0&heightx=0&heightw=100&heighth=100&width=516&height=597&compression=92 1.5x,https://www.cdn.tv2.no/images/14336464.jpg?imageId=14336464&panox=0&panoy=0&panow=100&panoh=100&heighty=0&heightx=0&heightw=100&heighth=100&width=344&height=398&compression=92 1x"> </figure> <div class="article__content"> <h2 class="article__title t26 tm20">Italienske jegere stoppet på vei ut av landet med 2.027 nedfryste troster</h2> </div> </a> </article> sample output as both of the below articles contain class name article--nyheter <article class="article column large-4 small-12 article--nyheter"> <a class="article__link" href="/nyheter/14336420/"> <figure class="image image__responsive" style="padding-bottom:115.452%;"> <img class="image__img lazyload" itemprop="image" title="" alt="" src="data:image/gif;base64,R0lGODlhEAAJAIAAAP///wAAACH5BAEAAAAALAAAAAAQAAkAAAIKhI+py+0Po5yUFQA7" data-src="https://www.cdn.tv2.no/images/14336464.jpg?imageId=14336464&panox=0&panoy=0&panow=100&panoh=100&heighty=0&heightx=0&heightw=100&heighth=100&width=344&height=398" data-srcset="https://www.cdn.tv2.no/images/14336464.jpg?imageId=14336464&panox=0&panoy=0&panow=100&panoh=100&heighty=0&heightx=0&heightw=100&heighth=100&width=688&height=796&compression=92 2x,https://www.cdn.tv2.no/images/14336464.jpg?imageId=14336464&panox=0&panoy=0&panow=100&panoh=100&heighty=0&heightx=0&heightw=100&heighth=100&width=516&height=597&compression=92 1.5x,https://www.cdn.tv2.no/images/14336464.jpg?imageId=14336464&panox=0&panoy=0&panow=100&panoh=100&heighty=0&heightx=0&heightw=100&heighth=100&width=344&height=398&compression=92 1x"> </figure> <div class="article__content"> <h2 class="article__title t26 tm20">Italienske jegere stoppet på vei ut av landet med 2.027 nedfryste troster</h2> </div> </a> </article> <article class="article column large-4 small-12 article--nyheter"> <a class="article__link" href="/nyheter/14336304/"> <figure class="image image__responsive" style="padding-bottom:51.312%;"> <img class="image__img lazyload" itemprop="image" title="" alt="" src="data:image/gif;base64,R0lGODlhEAAJAIAAAP///wAAACH5BAEAAAAALAAAAAAQAAkAAAIKhI+py+0Po5yUFQA7" data-src="https://www.cdn.tv2.no/images/14336482.jpg?imageId=14336482&panox=0&panoy=0&panow=100&panoh=50.993377483444&heighty=0&heightx=0&heightw=100&heighth=100&width=344&height=177" data-srcset="https://www.cdn.tv2.no/images/14336482.jpg?imageId=14336482&panox=0&panoy=0&panow=100&panoh=50.993377483444&heighty=0&heightx=0&heightw=100&heighth=100&width=688&height=354&compression=92 2x,https://www.cdn.tv2.no/images/14336482.jpg?imageId=14336482&panox=0&panoy=0&panow=100&panoh=50.993377483444&heighty=0&heightx=0&heightw=100&heighth=100&width=516&height=265.5&compression=92 1.5x,https://www.cdn.tv2.no/images/14336482.jpg?imageId=14336482&panox=0&panoy=0&panow=100&panoh=50.993377483444&heighty=0&heightx=0&heightw=100&heighth=100&width=344&height=177&compression=92 1x"> </figure> <div class="article__content"> <h2 class="article__title t27 tm26">IEA: Mulig å nå 2-gradersmålet om løftene fra Glasgow holdes</h2> </div> </a> </article> I have to use grep, sed, curl, awk for this. Cannot use any other parser. So my expected output is to get all the articles tag having a specific class. I want everything inside those article tags.
Assumptions: there is some valid reason why a HTML-centric tool is not being used to parse out the desired sections input is formatted as in the question otherwise the proposed sed solution will likely not work correctly extract the <article> ... </article> pairs where the article class entry contains the string article--nyheter OP's expected output has the two article--nyheter sections listed in reverse order; for now I'm going to assume that was some sort of typo and that there are no requirements to sort the two sections One sed idea using ranges to to extract the desired data: sed -n '/<article class.*article--nyheter/,/<\/article>/p' news.html This generates: <article class="article column large-4 small-12 article--nyheter"> <a class="article__link" href="/nyheter/14336304/"> <figure class="image image__responsive" style="padding-bottom:51.312%;"> <img class="image__img lazyload" itemprop="image" title="" alt="" src="data:image/gif;base64,R0lGODlhEAAJAIAAAP///wAAACH5BAEAAAAALAAAAAAQAAkAAAIKhI+py+0Po5yUFQA7" data-src="https://www.cdn.tv2.no/images/14336482.jpg?imageId=14336482&panox=0&panoy=0&panow=100&panoh=50.993377483444&heighty=0&heightx=0&heightw=100&heighth=100&width=344&height=177" data-srcset="https://www.cdn.tv2.no/images/14336482.jpg?imageId=14336482&panox=0&panoy=0&panow=100&panoh=50.993377483444&heighty=0&heightx=0&heightw=100&heighth=100&width=688&height=354&compression=92 2x,https://www.cdn.tv2.no/images/14336482.jpg?imageId=14336482&panox=0&panoy=0&panow=100&panoh=50.993377483444&heighty=0&heightx=0&heightw=100&heighth=100&width=516&height=265.5&compression=92 1.5x,https://www.cdn.tv2.no/images/14336482.jpg?imageId=14336482&panox=0&panoy=0&panow=100&panoh=50.993377483444&heighty=0&heightx=0&heightw=100&heighth=100&width=344&height=177&compression=92 1x"> </figure> <div class="article__content"> <h2 class="article__title t27 tm26">IEA: Mulig å nå 2-gradersmålet om løftene fra Glasgow holdes</h2> </div> </a> </article> <article class="article column large-4 small-12 article--nyheter"> <a class="article__link" href="/nyheter/14336420/"> <figure class="image image__responsive" style="padding-bottom:115.452%;"> <img class="image__img lazyload" itemprop="image" title="" alt="" src="data:image/gif;base64,R0lGODlhEAAJAIAAAP///wAAACH5BAEAAAAALAAAAAAQAAkAAAIKhI+py+0Po5yUFQA7" data-src="https://www.cdn.tv2.no/images/14336464.jpg?imageId=14336464&panox=0&panoy=0&panow=100&panoh=100&heighty=0&heightx=0&heightw=100&heighth=100&width=344&height=398" data-srcset="https://www.cdn.tv2.no/images/14336464.jpg?imageId=14336464&panox=0&panoy=0&panow=100&panoh=100&heighty=0&heightx=0&heightw=100&heighth=100&width=688&height=796&compression=92 2x,https://www.cdn.tv2.no/images/14336464.jpg?imageId=14336464&panox=0&panoy=0&panow=100&panoh=100&heighty=0&heightx=0&heightw=100&heighth=100&width=516&height=597&compression=92 1.5x,https://www.cdn.tv2.no/images/14336464.jpg?imageId=14336464&panox=0&panoy=0&panow=100&panoh=100&heighty=0&heightx=0&heightw=100&heighth=100&width=344&height=398&compression=92 1x"> </figure> <div class="article__content"> <h2 class="article__title t26 tm20">Italienske jegere stoppet på vei ut av landet med 2.027 nedfryste troster</h2> </div> </a> </article> If the input data is not formatted as presented in the question (eg, carriage returns/linefeeds are missing) then this sed solution likely will not work; a more 'robust' parser would need to be built (eg, via awk) ...
ReferenceError: indexproduct is not defined
I'm getting reference error in every route like: "/","/product" even though that variable is not used on those routes.Although pages load fine with no errors in front but it shows error in terminal .Please help it i'm trying to figure out for days and not able to continue with my project app.js:` app.get("/", function(req, res){//landing page product.find({},function(error,indexproduct){ if (error) { console.log(error); }else{ res.render("index",{indexproduct:indexproduct}); } }); });` index.ejs: <% include partials/header %> <!-- Start slider --> <section id="aa-slider"> <div class="aa-slider-area"> <div id="sequence" class="seq"> <div class="seq-screen"> <ul class="seq-canvas"> <!-- single slide item --> <li> <div class="seq-model"> <img data-seq src="/img/slide8.jpg" alt="Men slide img" /> </div> <div class="seq-title"> <span data-seq>Save Up to 75% Off</span> <h2 data-seq>Men Collection</h2> <p data-seq>Best Place to Buy Awesome Men's Clothing</p> <a data-seq href="/category/men" class="aa-shop-now-btn aa-secondary-btn">SHOP NOW</a> </div> </li> <!-- single slide item --> <li> <div class="seq-model"> <img data-seq src="/img/slide10.jpg" alt="Wristwatch slide img" /> </div> <div class="seq-title"> <span data-seq>Save Up to 40% Off</span> <h2 data-seq>Kids Clothing Collection</h2> <p data-seq>Style your Kid's with latest Trends</p> <a data-seq href="/category/kid" class="aa-shop-now-btn aa-secondary-btn">SHOP NOW</a> </div> </li> <!-- single slide item --> <li> <div class="seq-model"> <img data-seq src="/img/slide4.jpg" alt="Women Jeans slide img" /> </div> <div class="seq-title"> <span data-seq>Save Up to 75% Off</span> <h2 data-seq>Women Dress Collection</h2> <p data-seq>Style your Own Life with our trendy cloths</p> <a data-seq href="/category/women" class="aa-shop-now-btn aa-secondary-btn">SHOP NOW</a> </div> </li> <!-- single slide item --> <!-- single slide item --> </ul> </div> <!-- slider navigation btn --> <fieldset class="seq-nav" aria-controls="sequence" aria-label="Slider buttons"> <a type="button" class="seq-prev" aria-label="Previous"><span class="fa fa-angle-left"></span></a> <a type="button" class="seq-next" aria-label="Next"><span class="fa fa-angle-right"></span></a> </fieldset> </div> </div> </section> <!-- / slider --> <!-- Start Promo section --> <section id="aa-promo"> <div class="container"> <div class="row"> <div class="col-md-12"> <div class="aa-promo-area"> <div class="row"> <!-- promo left --> <div class="col-md-5 no-padding"> <div class="aa-promo-left"> <div class="aa-promo-banner"> <img src="/img/slide5.jpg" alt="img"> <div class="aa-prom-content"> <span>75% Off</span> <h4>For Women</h4> </div> </div> </div> </div> <!-- promo right --> <div class="col-md-7 no-padding"> <div class="aa-promo-right"> <div class="aa-single-promo-right"> <div class="aa-promo-banner"> <img src="/img/slide6.jpg" alt="img"> <div class="aa-prom-content"> <span>Exclusive Item</span> <h4>For Men</h4> </div> </div> </div> <div class="aa-single-promo-right"> <div class="aa-promo-banner"> <img src="/img/slide3.jpg" alt="img"> <div class="aa-prom-content"> <span>Sale Off</span> <h4>On Every Ladies Dress</h4> </div> </div> </div> <div class="aa-single-promo-right"> <div class="aa-promo-banner"> <img src="/img/slide9.jpg" alt="img"> <div class="aa-prom-content"> <span>New Arrivals</span> <h4>For Kids</h4> </div> </div> </div> <div class="aa-single-promo-right"> <div class="aa-promo-banner"> <img src="/img/slide1.jpg" alt="img"> <div class="aa-prom-content"> <span>25% Off</span> <h4>For Men's Clothing</h4> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </section> <!-- / Promo section --> <!-- banner section --> <section id="aa-banner"> <div class="container"> <div class="row"> <div class="col-md-12"> <div class="row"> <div class="aa-banner-area"> <img src="/img/slide2.jpg" alt="fashion banner img"> </div> </div> </div> </div> </div> </section> <!-- popular section --> <section id="aa-popular-category"> <div class="container"> <div class="row"> <div class="col-md-12"> <div class="row"> <div class="aa-popular-category-area"> <!-- start prduct navigation --> <ul class="nav nav-tabs aa-products-tab"> <li class="active">Exclusive</li> </ul> <!-- Tab panes --> <div class="tab-content"> <!-- Start men popular category --> <div class="tab-pane fade in active" id="popular"> <ul class="aa-product-catg aa-popular-slider"> <!-- start single product item --> <%=console.log(indexproduct)%> </ul> <a class="aa-browse-btn" href="/product">Browse all Product <span class="fa fa-long-arrow-right"></span></a> </div> <!-- / popular product category --> </div> </div> </div> </div> </div> </div> </section> <!-- / popular section --> <!-- Support section --> <section id="aa-support"> <div class="container"> <div class="row"> <div class="col-md-12"> <div class="aa-support-area"> <!-- single support --> <div class="col-md-4 col-sm-4 col-xs-12"> <div class="aa-support-single"> <span class="fa fa-truck"></span> <h4>FREE SHIPPING</h4> <P>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quam, nobis.</P> </div> </div> <!-- single support --> <div class="col-md-4 col-sm-4 col-xs-12"> <div class="aa-support-single"> <span class="fa fa-clock-o"></span> <h4>30 DAYS MONEY BACK</h4> <P>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quam, nobis.</P> </div> </div> <!-- single support --> <div class="col-md-4 col-sm-4 col-xs-12"> <div class="aa-support-single"> <span class="fa fa-phone"></span> <h4>SUPPORT 24/7</h4> <P>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quam, nobis.</P> </div> </div> </div> </div> </div> </div> </section> <!-- / Support section --> <% include partials/footer %>` Error: `ReferenceError: C:\Users\nishantk\Desktop\project200\renclo\views\index.ejs:156 154| <ul class="aa-product-catg aa-popular-slider"> 155| <!-- start single product item --> >> 156| <%=console.log(indexproduct)%> 157| </ul> 158| <a class="aa-browse-btn" href="/product">Browse all Product <span class="fa fa-long-arrow-right"></span></a> 159| </div> indexproduct is not defined at eval (C:\Users\nishantk\Desktop\project200\renclo\views\index.ejs:74:37) at index (C:\Users\nishantk\Desktop\project200\renclo\node_modules\ejs\lib\ejs.js:682:17) at tryHandleCache (C:\Users\nishantk\Desktop\project200\renclo\node_modules\ejs\lib\ejs.js:254:36) at View.exports.renderFile [as engine] (C:\Users\nishantk\Desktop\project200\renclo\node_modules\ejs\lib\ejs.js:485:10) at View.render (C:\Users\nishantk\Desktop\project200\renclo\node_modules\express\lib\view.js:135:8) at tryRender (C:\Users\nishantk\Desktop\project200\renclo\node_modules\express\lib\application.js:640:10) at Function.render (C:\Users\nishantk\Desktop\project200\renclo\node_modules\express\lib\application.js:592:3) at ServerResponse.render (C:\Users\nishantk\Desktop\project200\renclo\node_modules\express\lib\response.js:1012:7) at C:\Users\nishantk\Desktop\project200\renclo\app.js:396:9 at Layer.handle [as handle_request] (C:\Users\nishantk\Desktop\project200\renclo\node_modules\express\lib\router\layer.js:95:5) at next (C:\Users\nishantk\Desktop\project200\renclo\node_modules\express\lib\router\route.js:137:13) at Route.dispatch (C:\Users\nishantk\Desktop\project200\renclo\node_modules\express\lib\router\route.js:112:3) at Layer.handle [as handle_request] (C:\Users\nishantk\Desktop\project200\renclo\node_modules\express\lib\router\layer.js:95:5) at C:\Users\nishantk\Desktop\project200\renclo\node_modules\express\lib\router\index.js:281:22 at param (C:\Users\nishantk\Desktop\project200\renclo\node_modules\express\lib\router\index.js:354:14) at param (C:\Users\nishantk\Desktop\project200\renclo\node_modules\express\lib\router\index.js:365:14) `
Why am I getting a list index error when trying to write to a CSV but the results print to the console correctly?
I am trying to pull the time posted, text, and number of likes from this linkedin company page: https://www.linkedin.com/company/excella-consulting/ I have the data points all pulling to the console correctly but I get a list index out of range error still. I'm confused. The len of my variable likes_container is 0 but I still pull the correct number of likes per post in the console, I'm new to Python and I'm not sure how to resolve this. I'm using selenium to pull the html and have my credentials in a separate parameters file so I adjusted the code below for the linkedin credentials/URL. Thanks from selenium.webdriver.common.keys import Keys import time import parameters import csv from parsel import Selector import string import re import subprocess # specifies the path to the chromedriver.exe driver = webdriver.Chrome() # driver.get method() will navigate to a page given by the URL address driver.get('https://www.linkedin.com/uas/login?trk=guest_homepage-basic_nav-header-signin') # locate email form by_class_name username = driver.find_element_by_id('username') # send_keys() to simulate key strokes username.send_keys('email#email.com') # locate password form by_class_name password = driver.find_element_by_id('password') # send_keys() to simulate key strokes password.send_keys('#######') # locate submit button by_class_name #log_in_button = driver.find_element_by_class_name('btn__primary--large from__button--floating') # locate submit button by_xpath log_in_button = driver.find_element_by_xpath('//*[#type="submit"]') # .click() to mimic button click log_in_button.click() # search_query = driver.find_element_by_xpath("//input[#type='text']") # # send_keys() to simulate the search text key strokes # search_query.send_keys('Excella Consulting') # # .send_keys() to simulate the return key # search_query.send_keys(Keys.ENTER) #find content only and click driver.get('https://www.linkedin.com/company/excella-consulting/') SCROLL_PAUSE_TIME = 2.5 # Get scroll height last_height = driver.execute_script("return document.body.scrollHeight") while True: # Scroll down to bottom driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") # Wait to load page time.sleep(SCROLL_PAUSE_TIME) # Calculate new scroll height and compare with last scroll height new_height = driver.execute_script("return document.body.scrollHeight") if new_height == last_height: break last_height = new_height company_page = driver.page_source from bs4 import BeautifulSoup as bs linkedin_soup = bs(company_page.encode("utf-8"), "html") linkedin_soup.prettify() containers = linkedin_soup.findAll("div",{"class":"occludable-update ember-view"}) container = containers[0].find("div","feed-shared-update-v2 relative full-height feed-shared-update-v2--e2e feed-shared-update--chat-ui feed-shared-update-v2--minimal-padding Elevation-2dp ember-view") timestr = time.strftime("%Y%m%d-%H%M%S") filename = "Excella_LinkedIn_Posts_" + timestr + ".csv" f = open(filename, "w") headers = "Posted_Date, Text, Likes\n" f.write(headers) for container in containers: posted_container = container.findAll("div",{"class": "feed-shared-text-view white-space-pre-wrap break-words ember-view"}) posted_date = posted_container[0].find("span",{"class": "ember-view"}) box_container = container.findAll("div",{"class": "feed-shared-update-v2__description-wrapper"}) new_box = box_container[0].find("span",{"aria-hidden": "false"}) likes_container = container.findAll("ul", class_="social-details-social-counts--justified social-details-social-counts ember-view") new_likes = likes_container[0].find("span", {"class": "v-align-middle social-details-social-counts__reactions-count"}) print("Posted_Date: " + posted_date.text.strip()) print("Text: " + new_box.text.strip()) try: print("Likes: " + new_likes.text.strip()) except: pass f.write(posted_date.text.strip() + "," + new_box.text.strip().replace(",","|") + "," + new_likes.text.strip() + "," + "\n") f.close() I was expecting to be able to write each post to a row in a csv, here's the print results: Posted_Date: 6d Text: Congratulations to Excellian Trent Hone on his award from the U.S. Naval Institute for his book 'Learning War.' Named the 2018 Author of the Year, we are proud to recognize his hard work and dedication. Likes: 41 Posted_Date: 6d Text: Want to hear more from our team of hashtag#Agile experts and trainers? Sign up for our monthly Training Newsletter to get industry insight, tips and tricks, and a list of our featured upcoming classes! Sign up today to receive our May newsletter tomorrow: hashtag#AgileTraining hashtag#ExcellaTraining Likes: 3 Posted_Date: 23h Text: Today we bring you hashtag#Agile2019 speaker #Dane Weber, a Lead Consultant at Excella! Dane will be presenting 'Undercover Scrum Master' on August 5th at 3:45pm. More details to come: hashtag#scrummaster hashtag#speaker Likes: 2 but I got this error underneath the print results: IndexError Traceback (most recent call last) <ipython-input-26-b452542829fd> in <module> 117 new_box = box_container[0].find("span",{"aria-hidden": "false"}) 118 likes_container = container.findAll("ul", class_="social-details-social-counts--justified social-details-social-counts ember-view") --> 119 new_likes = likes_container[0].find("span", {"class": "v-align-middle social-details-social-counts__reactions-count"}) 120 # try: 121 # new_likes IndexError: list index out of range EDIT: Here's the HTML for a container, can provide more if needed: <div class="occludable-update ember-view" id="ember2840"> <div class="feed-shared-update-v2 relative full-height feed-shared-update--chat-ui feed-shared-update-v2--minimal-padding Elevation-2dp ember-view" data-id="urn:li:activity:6490973066489843713" id="ember2993"> <div class="display-flex feed-shared-actor display-flex feed-shared-actor--with-control-menu ember-view" id="ember2994"><a class="feed-shared-actor__container-link display-flex flex-grow-1 app-aware-link ember-view" data-control-id="g5vpPsibn6Sa8fKqcxeTxg==" data-control-name="actor_container" href="https://www.linkedin.com/company/163739/?miniCompanyUrn=urn%3Ali%3Afs_miniCompany%3A163739" id="ember2995" target="_self"> <div class="feed-shared-actor__image" data-control-id="g5vpPsibn6Sa8fKqcxeTxg==" data-control-name="actor_picture" data-ember-action="" data-ember-action-2996="2996"> <span class="js-feed-shared-actor__avatar" data-entity-hovercard-id="urn:li:fs_miniCompany:163739"> <div class="feed-shared-actor__avatar ivm-image-view-model ember-view" id="ember2997"> <div class="display-flex ivm-view-attr__img-wrapper ivm-view-attr__img-wrapper--use-img-tag ember-view" id="ember2998"><!-- --> <img alt="Excella" class="lazy-image ivm-view-attr__img--centered feed-shared-actor__avatar-image EntityPhoto-square-3"/> </div> </div> </span> </div> <div class="feed-shared-actor__meta" data-control-id="g5vpPsibn6Sa8fKqcxeTxg==" data-control-name="actor" data-ember-action="" data-ember-action-2999="2999"> <h3 class="feed-shared-actor__title t-12 t-black--light t-normal"> <span class="feed-shared-actor__name t-14 t-black t-bold hoverable-link-text" data-entity-hovercard-id="urn:li:fs_miniCompany:163739"> <span dir="ltr">Excella</span> </span> <!-- --> </h3> <span class="feed-shared-actor__description t-12 t-black--light t-normal"> <div class="truncate feed-shared-text-view white-space-pre-wrap break-words ember-view" id="ember3000"><span aria-hidden="false">4,338 followers</span><!-- --></div> </span> <span class="feed-shared-actor__sub-description t-12 t-black--light t-normal"> <div class="feed-shared-text-view white-space-pre-wrap break-words ember-view" id="ember3003"><span aria-hidden="false"><span class="ember-view" id="ember3006"><span>3mo</span></span></span><!-- --></div> </span> </div> </a> <button aria-expanded="false" aria-label="See more about Excella" class="entity-hovercard__a11y-trigger" data-entity-hovercard-id="urn:li:fs_miniCompany:163739" data-entity-hovercard-trigger="click"></button> <!-- --></div> <div class="feed-shared-update-v2__control-menu absolute text-align-right feed-shared-control-menu ember-view" id="ember3008"><artdeco-dropdown class="ember-view" id="ember3009"><artdeco-dropdown-trigger aria-expanded="false" class="feed-shared-control-menu__trigger artdeco-button artdeco-button--tertiary artdeco-button--muted artdeco-button--1 artdeco-button--circle ember-view" id="ember3010" placement="bottom" role="button" tabindex="0"> <li-icon aria-label="Open control menu" class="artdeco-button__icon" role="img" type="ellipsis-horizontal-icon"><svg class="artdeco-icon" focusable="false" height="24px" preserveaspectratio="xMinYMin meet" viewbox="0 0 24 24" width="24px" x="0" y="0"><path class="large-icon" d="M2,10H6v4H2V10Zm8,4h4V10H10v4Zm8-4v4h4V10H18Z" style="fill: currentColor"></path></svg></li-icon> <!-- --></artdeco-dropdown-trigger><artdeco-dropdown-content aria-hidden="true" arrow-dir="right" class="feed-shared-control-menu__content artdeco-dropdown-with-arrow ember-view" data-dropdown="" id="ember3011" justification="right" placement="bottom" tabindex="-1"> <ul> <li class="option-share-via"> <artdeco-dropdown-item class="tap-target display-flex align-items-center ember-view" data-dropdown="" id="ember3013" role="button" tabindex="0"> <li-icon aria-hidden="true" class="flex-shrink-zero mr2" type="link-icon"><svg class="artdeco-icon" focusable="false" height="24px" preserveaspectratio="xMinYMin meet" viewbox="0 0 24 24" width="24px" x="0" y="0"><path class="large-icon" d="M17.29,3a3.7,3.7,0,0,0-2.62,1.09L12.09,6.67A3.7,3.7,0,0,0,11,9.29a3.65,3.65,0,0,0,.52,1.86l-0.37.37a3.66,3.66,0,0,0-4.48.56L4.09,14.67a3.71,3.71,0,1,0,5.24,5.24l2.59-2.59A3.7,3.7,0,0,0,13,14.71a3.65,3.65,0,0,0-.52-1.86l0.37-.37a3.66,3.66,0,0,0,4.48-.57l2.59-2.59A3.71,3.71,0,0,0,17.29,3ZM11.13,14.71a1.82,1.82,0,0,1-.54,1.3L8,18.59A1.83,1.83,0,0,1,5.41,16L8,13.41a1.79,1.79,0,0,1,1.74-.48L8.28,14.4A0.94,0.94,0,0,0,9.6,15.73l1.46-1.46A1.82,1.82,0,0,1,11.13,14.71ZM18.59,8L16,10.59a1.79,1.79,0,0,1-1.74.48L15.73,9.6A0.94,0.94,0,0,0,14.4,8.27L12.94,9.74A1.79,1.79,0,0,1,13.41,8L16,5.41A1.83,1.83,0,0,1,18.59,8Z" style="fill: currentColor"></path></svg></li-icon> <div class="feed-text-description flex-grow-1 text-align-left"> <span class="feed-shared-control-menu__headline t-14 t-black t-bold">Copy link to post</span> <span class="feed-shared-control-menu__sub-headline t-12 t-black t-black--light"></span> </div> </artdeco-dropdown-item> </li> <li class="option-unfollow-company"> <artdeco-dropdown-item class="tap-target display-flex align-items-center ember-view" data-dropdown="" id="ember3015" role="button" tabindex="0"> <li-icon aria-hidden="true" class="flex-shrink-zero mr2" type="block-icon"><svg class="artdeco-icon" focusable="false" height="24px" preserveaspectratio="xMinYMin meet" viewbox="0 0 24 24" width="24px" x="0" y="0"><path class="large-icon" d="M12,2C6.5,2,2,6.5,2,12c0,5.5,4.5,10,10,10c5.5,0,10-4.5,10-10C22,6.5,17.5,2,12,2zM3.9,12c0-4.5,3.6-8.1,8.1-8.1c1.9,0,3.7,0.7,5,1.8L5.6,17C4.5,15.7,3.9,13.9,3.9,12zM12,20.1c-1.9,0-3.7-0.7-5-1.8L18.4,7c1.1,1.4,1.8,3.1,1.8,5C20.1,16.5,16.5,20.1,12,20.1z" style="fill: currentColor"></path></svg></li-icon> <div class="feed-text-description flex-grow-1 text-align-left"> <span class="feed-shared-control-menu__headline t-14 t-black t-bold">Unfollow Excella</span> <span class="feed-shared-control-menu__sub-headline t-12 t-black t-black--light">Stop seeing posts from Excella</span> </div> </artdeco-dropdown-item> </li> <li class="option-report"> <artdeco-dropdown-item class="tap-target display-flex align-items-center ember-view" data-dropdown="" id="ember3017" role="button" tabindex="0"> <li-icon aria-hidden="true" class="flex-shrink-zero mr2" type="flag-icon"><svg class="artdeco-icon" focusable="false" height="24px" preserveaspectratio="xMinYMin meet" viewbox="0 0 24 24" width="24px" x="0" y="0"><path class="large-icon" d="M13.82,5L14,4a1,1,0,0,0-1-1H5V2H3V22H5V15H9.18L9,16a1,1,0,0,0,1,1h8.87L21,5H13.82ZM5,13V5h6.94l-1.41,8H5Zm12.35,2h-6.3l1.42-8h6.29Z" style="fill: currentColor"></path></svg></li-icon> <div class="feed-text-description flex-grow-1 text-align-left"> <span class="feed-shared-control-menu__headline t-14 t-black t-bold">Report this post</span> <span class="feed-shared-control-menu__sub-headline t-12 t-black t-black--light">This post is offensive or the account is hacked</span> </div> </artdeco-dropdown-item> </li> </ul> </artdeco-dropdown-content></artdeco-dropdown> <!-- --> <!-- --></div> <!-- --> <div class="feed-shared-update-v2__description-wrapper"><div class="feed-shared-update-v2__description feed-shared-inline-show-more-text ember-view" id="ember3018"><div class="feed-shared-update-v2__commentary feed-shared-text ember-view" dir="ltr" id="ember3019"> <div class="feed-shared-text__text-view feed-shared-text-view white-space-pre-wrap break-words ember-view" id="ember3020"><span aria-hidden="false"><span class="ember-view" id="ember3023"><span>We can't get enough of </span></span><a class="tap-target feed-shared-text-view__mention ember-view" href="/company/10793171/" id="ember3027" target="_self"><span data-entity-hovercard-id="urn:li:fs_miniCompany:10793171" data-entity-type="MINI_COMPANY">HUNGRY Marketplace</span></a><button aria-expanded="false" aria-label="See more about HUNGRY Marketplace" class="entity-hovercard__a11y-trigger" data-entity-hovercard-id="urn:li:fs_miniCompany:10793171" data-entity-hovercard-trigger="click"></button><span class="ember-view" id="ember3031"><span>!</span></span></span><!-- --></div> </div><!-- --></div></div> <!-- --> <!-- --> <div class="Elevation-0dp feed-shared-update-v2__update-content-wrapper feed-shared-mini-update-v2 feed-shared-mini-update-v2--with-context feed-shared-mini-update-v2--minimal-padding ember-view" id="ember3033"><div> <div class="feed-shared-actor display-flex ember-view" id="ember3034"><a class="feed-shared-actor__container-link display-flex flex-grow-1 app-aware-link ember-view" data-control-id="g5vpPsibn6Sa8fKqcxeTxg==" data-control-name="original_share_actor_container" href="https://www.linkedin.com/company/10793171/?miniCompanyUrn=urn%3Ali%3Afs_miniCompany%3A10793171" id="ember3035" target="_self"> <div class="feed-shared-actor__image" data-control-id="g5vpPsibn6Sa8fKqcxeTxg==" data-control-name="original_share_actor_picture" data-ember-action="" data-ember-action-3036="3036"> <span class="js-feed-shared-actor__avatar" data-entity-hovercard-id="urn:li:fs_miniCompany:10793171"> <div class="feed-shared-actor__avatar ivm-image-view-model ember-view" id="ember3037"> <div class="display-flex ivm-view-attr__img-wrapper ivm-view-attr__img-wrapper--use-img-tag ember-view" id="ember3038"><!-- --> <img alt="HUNGRY" class="lazy-image ivm-view-attr__img--centered feed-shared-actor__avatar-image EntityPhoto-square-2"/> </div> </div> </span> </div> <div class="feed-shared-actor__meta" data-control-id="g5vpPsibn6Sa8fKqcxeTxg==" data-control-name="original_share_actor" data-ember-action="" data-ember-action-3039="3039"> <h3 class="feed-shared-actor__title t-12 t-black--light t-normal"> <span class="feed-shared-actor__name t-14 t-black t-bold hoverable-link-text" data-entity-hovercard-id="urn:li:fs_miniCompany:10793171"> <span dir="ltr">HUNGRY</span> </span> <!-- --> </h3> <span class="feed-shared-actor__description t-12 t-black--light t-normal"> <div class="truncate feed-shared-text-view white-space-pre-wrap break-words ember-view" id="ember3040"><span aria-hidden="false">637 followers</span><!-- --></div> </span> <span class="feed-shared-actor__sub-description t-12 t-black--light t-normal"> <div class="feed-shared-text-view white-space-pre-wrap break-words ember-view" id="ember3043"><span aria-hidden="false"><span class="ember-view" id="ember3046"><span>4mo</span></span></span><!-- --></div> </span> </div> </a> <button aria-expanded="false" aria-label="See more about HUNGRY" class="entity-hovercard__a11y-trigger" data-entity-hovercard-id="urn:li:fs_miniCompany:10793171" data-entity-hovercard-trigger="click"></button> <button aria-label="Follow" aria-pressed="false" class="feed-shared-actor__follow-button feed-shared-update-v2__follow-button artdeco-button artdeco-button--tertiary follow ember-view" data-control-name="actor_follow_toggle" id="ember3048"> <li-icon aria-hidden="true" class="artdeco-button__icon" size="small" type="plus-icon"><svg class="artdeco-icon" focusable="false" height="24px" preserveaspectratio="xMinYMin meet" viewbox="0 0 24 24" width="24px" x="0" y="0"><path class="small-icon" d="M14,9H9v5H7V9H2V7H7V2H9V7h5V9Z" style="fill-opacity: 1"></path></svg></li-icon> <span aria-hidden="true">Follow</span> </button> </div> <a class="tap-target feed-shared-mini-update-v2__link-to-details-page ember-view" href="/feed/update/activity:6490609780434956289/" id="ember3049"><div class="feed-shared-inline-show-more-text--minimal-padding feed-shared-inline-show-more-text ember-view" id="ember3050"> <div class="feed-shared-update-v2__commentary feed-shared-text ember-view" dir="ltr" id="ember3051"> <div class="feed-shared-text__text-view feed-shared-text-view white-space-pre-wrap break-words ember-view" id="ember3052"><span aria-hidden="false"><span class="ember-view" id="ember3055"><span>⭐⭐⭐⭐⭐ HUNGRY already? --> </span></span><a class="feed-shared-text-view__hyperlink ember-view" href="http://tryhungry.com" id="ember3059" rel="noopener noreferrer" target="_blank">tryhungry.com</a></span><!-- --></div> </div> <!-- --></div></a> <!-- --> <div class="feed-shared-mini-update-v2__reshared-content feed-shared-image feed-shared-image--single-image ember-view" id="ember3061"><div class="relative"> <div class="feed-shared-image__container" style="padding-top: 52.36%;"> <a aria-describedby="feed-shared-image-ember3061" class="feed-shared-image__image-link app-aware-link ember-view" data-control-id="g5vpPsibn6Sa8fKqcxeTxg==" data-control-name="update_image" href="#" id="ember3062"> <div class="ivm-image-view-model ember-view" id="ember3063"> <div class="display-flex ivm-view-attr__img-wrapper ivm-view-attr__img-wrapper--expanded ivm-view-attr__img-wrapper--use-img-tag ember-view" id="ember3064"><!-- --> <img alt="No alternative text description for this image" class="lazy-image ivm-view-attr__img--centered feed-shared-image__image feed-shared-image__image--constrained"/> </div> </div> </a> </div> <span class="visually-hidden" id="feed-shared-image-ember3061"> Activate link to view larger image. </span> <!-- --></div> <div class="ember-view" id="ember3065"><!-- --></div></div> <!-- --></div> </div> <!-- --> <!-- --> <div class="ember-view" id="ember3066"><div class="ember-view" id="ember3067"><!-- --></div></div> <div class="feed-shared-social-actions feed-shared-social-action-bar social-detail-base-social-actions feed-shared-social-action-bar--minimal-padding ember-view" id="ember3068"> <span class="reactions-react-button ember-view" id="ember3069"><!-- --> <button aria-label="React to post" aria-pressed="false" class="react-button__trigger artdeco-button artdeco-button--muted artdeco-button--4 artdeco-button--tertiary ember-view" id="ember3070"><!-- --> <span class="artdeco-button__text"> <li-icon aria-hidden="true" class="artdeco-button__icon" type="like-icon"><svg class="artdeco-icon" focusable="false" height="24px" preserveaspectratio="xMinYMin meet" viewbox="0 0 24 24" width="24px" x="0" y="0"><path class="large-icon" d="M17.51,11L15.36,8a14.81,14.81,0,0,1-2.25-5.29L12.74,1H10.5A2.5,2.5,0,0,0,8,3.5V4.08a9,9,0,0,0,.32,2.39L9,9H4.66A2.61,2.61,0,0,0,2,11.4a2.48,2.48,0,0,0,.39,1.43,2.48,2.48,0,0,0,.69,3.39,2.46,2.46,0,0,0,1.45,2.92,2.47,2.47,0,0,0,0,.36A2.5,2.5,0,0,0,7,22h4.52a8,8,0,0,0,1.94-.24l3-.76H21V11H17.51ZM19,19H16.88l-3.41.82A6,6,0,0,1,12,20H7a0.9,0.9,0,0,1-.9-0.89s0-.07,0-0.14l0.15-1-1-.4a0.9,0.9,0,0,1-.55-0.83,0.93,0.93,0,0,1,0-.22L5,15.57,4.27,15a0.9,0.9,0,0,1-.39-0.74A0.88,0.88,0,0,1,4,13.82l0.46-.72L4,12.38a0.88,0.88,0,0,1-.14-0.51,1,1,0,0,1,1-.87H11.5L10.2,6.3a9,9,0,0,1-.33-2.37V3.38a0.5,0.5,0,0,1,.5-0.5h0.95a17.82,17.82,0,0,0,2.52,6.22L16.6,13H19v6Z" style="fill: currentColor"></path></svg></li-icon> <span class="artdeco-button__text react-button__text react-button__text--"> Like </span> </span></button> <!-- --></span> <span class="comment ember-view" id="ember3071"><button aria-label="Comment on {:actorName} post" class="artdeco-button artdeco-button--muted artdeco-button--4 artdeco-button--tertiary ember-view" data-control-name="comment" id="ember3072"> <li-icon aria-hidden="true" class="artdeco-button__icon" type="speech-bubble-icon"><svg class="artdeco-icon" focusable="false" height="24px" preserveaspectratio="xMinYMin meet" viewbox="0 0 24 24" width="24px" x="0" y="0"><path class="large-icon" d="M18,10H6V9H18v1Zm4-5V22l-5-4H3a1,1,0,0,1-1-1V5A1,1,0,0,1,3,4H21A1,1,0,0,1,22,5ZM20,6H4V16H17.7L20,17.84V6Zm-4,6H8v1h8V12Z" style="fill: currentColor"></path></svg></li-icon> <span class="artdeco-button__text"> Comment </span></button> </span> <span class="feed-shared-social-action-bar__action-btn feed-shared-social-action-bar__reshare-button reshare-button button reshare social-action-btn ember-view" data-control-name="reshare" id="ember3073"><button aria-label="Share {:actorFullName} post" class="artdeco-button artdeco-button--muted artdeco-button--4 artdeco-button--tertiary ember-view" data-control-name="reshare" id="ember3074"> <li-icon aria-hidden="true" class="artdeco-button__icon" type="share-linkedin-icon"><svg class="artdeco-icon" focusable="false" height="24px" preserveaspectratio="xMinYMin meet" viewbox="0 0 24 24" width="24px" x="0" y="0"><path class="large-icon" d="M24,12h0a1.18,1.18,0,0,0-.36-0.84L14,2V8H11A10,10,0,0,0,1,18v4H2.87A6.11,6.11,0,0,1,9,16h5v6l9.63-9.14A1.18,1.18,0,0,0,24,12s0,0,0,0h0Zm-8,5.54V14H9a8.15,8.15,0,0,0-6,2.84A8,8,0,0,1,11,10h5V6.48L21.81,12Z" style="fill: currentColor"></path></svg></li-icon> <span class="artdeco-button__text"> Share </span></button> <!-- --></span> <!-- --> </div><!-- --><!-- --> <div class="feed-shared-update-v2__comments-container display-flex flex-column"> <!-- --><!-- --><!-- --> <div class="feed-shared-first-prompt-block ember-view" id="ember3075"> <p class="t-12 t-black t-normal">Be the first to react</p> </div> </div> <!-- --> </div> </div>
Is it possible to create a pinterest-like layout with Bootstrap only?
I am trying to the get my head around this for quite some time now: Is it possible to create a pinterest Layout with Twitter Bootstrap only? I know there are jQuery Plugins like Masonry, but is there no way without them? Thanks
Found a (free) template at http://bragthemes.com/demo/pinstrap/. It's supposed to have all you are asking for. Haven't had time to check it out, though. Edit 2016-03-15: Bootstrap 4 allows this out of the box here. It's still in alpha, but we're getting there.
Found this solution, works within bootstrap (works even without defining column sizes), doesn't require javascript -- I snapped it into a project and it works beautifully: http://www.bootply.com/118335 Bless you #katiejones!
EDIT: This is now out of the box in boostrap 4 http://v4-alpha.getbootstrap.com/components/card/#card-columns Sure Thing. Took me a while to work out. Hope this helps! Apologies for the code dump but its necessary to show the grid working. <head> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script type="text/javascript" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/masonry.js"></script> <script type="text/javascript" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/imagesLoaded.js"></script> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous"> <!-- Optional theme --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css" integrity="sha384-aUGj/X2zp5rLCbBxumKTCw2Z50WgIr1vs/PFN4praOTvYXWlVyh2UtNUU0KAUhAX" crossorigin="anonymous"> <!-- Latest compiled and minified JavaScript --> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" integrity="sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==" crossorigin="anonymous"></script> </head> <div class="container"> <div class="row masonry-container"> <div class="col-xs-6 col-sm-3 col-md-3 item"> <div class="thumbnail"> <img src="http://lorempixel.com/150/200/abstract" alt=""> <div class="caption"> <h3>Thumbnail label</h3> <p>Lorem ipsumLorem ipsum dolosit amet, consectetur adipisicing eli dolor sit amet, consectetur adipisicing elit. </p> </div> </div> </div><!--/.item --> <div class="col-xs-6 col-sm-3 col-md-3 item"> <div class="thumbnail"> <img src="http://lorempixel.com/150/200/abstract" alt=""> <div class="caption"> <h3>Thumbnail label</h3> <p>Lorem ipsumLorem ipdolor sit amet, consectetur adipisicing eli dolor sit amet, consectetur adipisicing elit. </p> </div> </div> </div><!--/.item --> <div class="col-xs-6 col-sm-3 col-md-3 item"> <div class="thumbnail"> <img src="http://lorempixel.com/150/200/abstract" alt=""> <div class="caption"> <h3>Thumbnail label</h3> <p>Lorem ipsumLorem ipsum dolor sit amet, consectetur adipisicing eliLorem ipsum dolor sit amet, consectetur adipisicing eliLorem ipsum dolor sit amet, consectetur adipisicing eli dolor sit amet, consectetur adipisicing elit. </p> </div> </div> </div><!--/.item --> <div class="col-xs-6 col-sm-3 col-md-3 item"> <div class="thumbnail"> <img src="http://lorempixel.com/150/200/abstract" alt=""> <div class="caption"> <h3>Thumbnail label</h3> <p>Lorem ipsumLorem ipsum dolor sit amet, consectetur adipisicing eliLorem ipsum dolor sit amet, consectetur adipisicing eliLorem ipsum dolor sit amet, consectetur adipisicing eli dolor sit amet, consectetur adipisicing elit. </p> </div> </div> </div><!--/.item --> <div class="col-xs-6 col-sm-3 col-md-3 item"> <div class="thumbnail"> <img src="http://lorempixel.com/150/200/abstract" alt=""> <div class="caption"> <h3>Thumbnail label</h3> <p>Lorem ipsumLorem ipsum dolor ctetur adipisicing eli dolor sit amet, consectetur adipisicing elit. </p> </div> </div> </div><!--/.item --> <div class="col-xs-6 col-sm-3 col-md-3 item"> <div class="thumbnail"> <img src="http://lorempixel.com/150/200/abstract" alt=""> <div class="caption"> <h3>Thumbnail label</h3> <p>Lorem ipsumLorem ipdolor sit amet, consectetur adipisicing eli dolor sit amet, consectetur adipisicing elit. </p> </div> </div> </div><!--/.item --> <div class="col-xs-6 col-sm-3 col-md-3 item"> <div class="thumbnail"> <img src="http://lorempixel.com/150/200/abstract" alt=""> <div class="caption"> <h3>Thumbnail label</h3> <p>Lorem ipsumLorem ipsum dolor sit amet, consectetur adipisicing eliLorem ipsum dolor sit amet, consectetur adipisicing eliLorem ipsum dolor sit amet, consectetur adipisicing eli dolor sit amet, consectetur adipisicing elit. </p> </div> </div> </div><!--/.item --> <div class="col-xs-6 col-sm-3 col-md-3 item"> <div class="thumbnail"> <img src="http://lorempixel.com/150/200/abstract" alt=""> <div class="caption"> <h3>Thumbnail label</h3> <p>Lorem ipsumLorem ipsum dolor sit amet, consectetur adipisicing eliLorem ipsum dolor sit amet, consectetur adipisicing eliLorem ipsum dolor sit amet, consectetur adipisicing eli dolor sit amet, consectetur adipisicing elit. </p> </div> </div> </div><!--/.item --> <div class="col-xs-6 col-sm-3 col-md-3 item"> <div class="thumbnail"> <img src="http://lorempixel.com/150/200/abstract" alt=""> <div class="caption"> <h3>Thumbnail label</h3> <p>Lorem ipsumLorem ipsum dolor ctetur adipisicing eli dolor sit amet, consectetur adipisicing elit. </p> </div> </div> </div><!--/.item --> </div> <!--/.masonry-container --> </div><!--/.tab-panel --> <style type="text/css"> body { padding-top: 50px; } .main-container { padding: 10px 15px; } .p { text-align: center; } </style> <script type="text/javascript"> /* Demo Scripts for Making Twitter Bootstrap 3 Tab Play Nicely With The Masonry Library * on SitePoint by Maria Antonietta Perna */ //Initialize Masonry inside Bootstrap 3 Tab component (function( $ ) { var $container = $('.masonry-container'); $container.imagesLoaded( function () { $container.masonry({ columnWidth: '.item', itemSelector: '.item' }); }); //Reinitialize masonry inside each panel after the relative tab link is clicked - $('a[data-toggle=tab]').each(function () { var $this = $(this); $this.on('shown.bs.tab', function () { $container.imagesLoaded( function () { $container.masonry({ columnWidth: '.item', itemSelector: '.item' }); }); }); //end shown }); //end each })(jQuery); </script>
Yes, it is possible but with some limitations. Principle Each column is a div (or section depending upon the meaning of your layout) Within each column each tile is also be a div, or img etc. depending upon your design. Practice To make the columns you can use the following various techniques: float the columns display: inline-block the columns Use the new flexible box API (non-standard implementations are creeping into modern browsers) Use the new grid positioning API (although I'd avoid this for now as it's not supported hardly at all) Then place various tiles (divs) in each column. Again, depending upon your design/layout you could replace the column-divs with uls, and have a list of tiles (lis). I can't speak as to whether that is semantically correct for your design. Limitations Resizing the Pinterest page maintains the general position of most elements i.e. elements at the top of a column generally stays near the top, even when the number of columns is adjusted for the browser width - the pure CSS solution won't do that out of the box. Work-Arounds While not a perfect solution, you can use media queries to influence the position of various elements. With some time, one could get pretty close to the Pinterest layout - that said, there's probably a good reason they chose to implement said layout with JavaScript.
I know my answer is late. but just wanted this common question to be up dated. I found out 3 latest implementations. isotope. Found this on bootstrap website. Works well with infinite-scroll to build infinite scroll web pages too. Salvattore. This is achived with pure CSS and JS. JS is only used to pull data. masonry.desandro.com. This is a JS intensive implementation. but it has its own features.
Since Bootstrap 4, the .card-columns class is available. Specifications in there documentation here. It makes a nice Pinterest-like grid. 😌 <div class="card-columns"> <div class="card" id="card1"></div> <div class="card" id="card2"></div> <div class="card" id="card3"></div> <div class="card" id="card4"></div> <div class="card" id="card..."></div> </div> About the number of columns, though, I had trouble adapting it to different screen sizes. I finally managed to do it with : #media (max-width: 575.98px){ .card-columns { column-count: 1; } } #media (min-width: 576px){ .card-columns { column-count: 2; } } #media (min-width: 768px){ .card-columns { column-count: 3; } } #media (min-width: 992px){ .card-columns { column-count: 4; } } #media (min-width: 1200px){ .card-columns { column-count: 4; } }
There we have a stuff named: bootstrap-waterfall: http://mystist.github.io/bootstrap-waterfall/ But in fact, this plugin does not need bootstrap as it's dependencies. It's depends on whether you want to use bootstrap as your pin's markups or just style it yourself.
<div class="card-deck"> <div class="card"> <img class="card-img-top" src="..." alt="Card image cap"> <div class="card-block"> <h4 class="card-title">Card title</h4> <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p> </div> <div class="card-footer"> <small class="text-muted">Last updated 3 mins ago</small> </div> </div> <div class="card"> <img class="card-img-top" src="..." alt="Card image cap"> <div class="card-block"> <h4 class="card-title">Card title</h4> <p class="card-text">This card has supporting text below as a natural lead-in to additional content.</p> </div> <div class="card-footer"> <small class="text-muted">Last updated 3 mins ago</small> </div> </div> <div class="card"> <img class="card-img-top" src="..." alt="Card image cap"> <div class="card-block"> <h4 class="card-title">Card title</h4> <p class="card-text">This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.</p> </div> <div class="card-footer"> <small class="text-muted">Last updated 3 mins ago</small> </div> </div> </div>
For everyone who dont want want to go through the hassle of cross browser compatibility, here is a PHP solution. Assuming you have your data in an array, <?php $iColumns = 4;?> <?php for($i=0; $i < $iColumns; ++$i):?> <div class="span3"> <?php $j=$i; while( isset( $aData[$j] ) ): $oItem = $aData[$j] ?> <div class="thumbnail" style="margin-top:10px;"> <a href=""> <img src="" alt=""/> </a> <h3>title</h3> <p>caption</p> </div> <?php $j=$j+$iColumns; endwhile;?> </div> <?php endfor;?>