am working on a codeigniter website and currently trying to achieve a layout like this where i have equal heights for all images in row but different widths.
My images are stored in a MYSQL database with url paths pointing to the directory where they are located. I have also stored their heights and widths (the height and widths are stored in pixels).
Here is the sql for fetching the contents in PhotoController
$data['data'] = $this->model
->select('photo_path, photo_height, photo_width')
->get()
->getResultArray();
Then in Home view, here is what i have so far. (using bootstrap 4 for styling)
<div class="container">
<div class="row">
<?php foreach ($data as $row) : ?>
<div class="col-md-4 col-lg-6">
<img src="<?= base_url($row['photo_path']); ?>" class="img-lazy img-fluid">
</div>
<?php endforeach; ?>
</div>
</div>
Am stuck on what to do next here.
html
<div class="masonry-with-columns-2">
<?foreach ($data as $row){?>
<div>
img here
</div>
<?}?>
</div>
scss
// Within style tags in your html file
body {
margin: 0;
padding: 1rem;
}
// SCSS
// Masonry layout horizontal
.masonry-with-columns-2 {
display: flex;
flex-wrap: wrap;
div {
height: 150px;
line-height: 150px;
background: #9B1B30;
color: white;
margin: 0 1rem 1rem 0;
text-align: center;
font-weight: 900;
font-size: 2rem;
flex: 1 0 auto;
}
#for $i from 1 through 36 {
div:nth-child(#{$i}) {
$h: (random(400) + 70) + px;
width: $h;
}
}
}
Source https://mdbootstrap.com/docs/angular/layout/masonry/
Related
My main file is a .php file, and images can be uploaded and displayed from this page. Getting those images to display in three columns has been confusing. It is usually done like this: https://www.w3schools.com/howto/howto_css_images_side_by_side.asp with each image or images placed in div tags. three div tags if you want three columns. In my .php file, images are not written out in the code, so how do I get the images to display in three columns on the page?
I do include one div tag wrapped around the PHP code which is showing the first column.
Here is the CSS code:
.container{
}
.container .heading h3 span{
font-weight: 100;
}
.container .box{
display: flex;
flex-direction: row;
justify-content: space-between;
}
.container .box .dream{
flex-direction: column;
width: 32.5%;
}
.container .box .dream img{
width: 100%;
padding-bottom: 15px;
border-radius: 5px;
}
PHP code:
<div class="products-wrapper">
<div class="container">
<div class="box">
<div class="dream">
<?php foreach ($products as $product): ?>
<a href="<?=url('index.php?page=product&id=' .
($product['url_slug'] ? $product['url_slug'] : $product['id']))?
>" class="product">
<?php if (!empty($product['img']) &&
file_exists($product['img'])): ?>
<img src="<?=base_url?><?=$product['img']?>" alt="<?
=$product['name']?>">
<?php endif; ?>
<span class="name"><?=$product['name']?></span>
<span class="price">
<?=currency_code?><?=number_format($product['price'],2)?>
<?php if ($product['rrp'] > 0): ?>
<span class="rrp"><?=currency_code?><?
=number_format($product['rrp'],2)?></span>
<?php endif; ?>
</span>
</a>
<?php endforeach; ?>
</div>
I use html2pdf to generate pdf with table data but I have some issue that I can't deal with. No matter how I set margins i always have some additional blank page at the end of pdf.
This is how looks like my pdf template :
<body>
<div class="page">
<div class="inner-page">
<div class="dealers-table">
<div class="head">
<div class="it">Lp.</div>
<div class="name">Name</div>
<div class="street">street</div>
<div class="post-code">Post Code</div>
<div class="city">City</div>
<div class="phone">Phone</div>
<div class="services">Services</div>
</div>
<div class="body">
<div>
<div class="it"></div>
<div class="name"></div>
<div class="street"></div>
<div class="post-code"></div>
<div class="city"></div>
<div class="phone"></div>
<div class="services"> /</div>
</div>
</div>
</div>
</div>
</div>
And css:
.page {
width: 210mm;
height: 280mm;
margin: 0 auto;
padding: 0;
-webkit-box-sizing: border-box;
box-sizing: border-box;
position: relative;
}
.inner-page {
padding: 5mm 10mm;
}
.dealers-table {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
font-size: 6.5pt;
line-height: 1;
}
I don't set any margins in options of my Converter.
When I set page width less than 280px table from second page starts at the end of first page and additional blank page doesn't appear, in other situations there is always useless blank page.
How can I fix it?
EDIT 1
There is some code where I generate pdf on server side:
public function generatePdf() {
$autoDealers = $this->autoDealersOrServices(0);
(some function where i fetch array of dealers from my DB)
$autoDealers = view('pdf.template', [
'autoDealers' => $autoDealers
])->render();
$input = new StringInput();
$input->setHtml($view);
$converter = new Converter($input, new FileOutput());
$converter->setOption('landscape', false);
$converter->setOptions([
'printBackground' => true
]);
$output = $converter->convert();
$output->store('pdf/auto/dealers.pdf');
}
SyntaxEditor Code Snippet
"--encoding UTF-8 --page-size A4 --margin-left 10 --margin-right 10 --margin-top 20 --margin-bottom 0"
I need help with adjusting a certain html element <div class="content"> with css so that it will be fixed and responsive like this (https://i.imgur.com/vYsIUXy.jpg) on that position regardless of screen dimensions and not like this (https://i.imgur.com/qUHHI0q.jpg).
I change the width of #info #head>.content from 100% to 82% but on a smaller screen dimension it overlaps with the cover image.
HTML Code
Snippet
<div id="head">
<div class="content">
<div class="uigrid">
<div class="contingo">
<p style="font-size:30px;">Meng Qi Shi Shen</p>
<div class="horizontal-list">
Adventure
Comedy
Drama
Historical
Romance
Shoujo
<div class="type"><span class="sub" onclick="if (!window.__cfRLUnblockHandlers) return false; changegrid()">Sub</span><span class="dub" onclick="if (!window.__cfRLUnblockHandlers) return false; changegrid()">Dub</span></div> </div>
</div>
</div>
</div>
<div class="overlay"></div>
</div>
Full php(html) code
https://codeshare.io/arj6eA
CSS Code
https://codeshare.io/GbyP86
you can try to use max-width of device to adjust the with you want. Like for instance if the decive is width is 600ps
#media (max-width: 600px) {
#info #head:after {
content: '';
position: absolute;
bottom: 0;
width: 82%;
height: 3px;
box-shadow: 0 2px #1b1c1d;
}
}
or like this one when the width of the device is 1000px
#media (max-width: 1000px) {
#info #head:after {
content: '';
position: absolute;
bottom: 0;
width: 75%;
height: 3px;
box-shadow: 0 2px #1b1c1d;
}
}
for more of this please check here https://www.w3schools.com/css/css_templates.asp
I'm not sure if this is possible, but I'm trying to create a layout like so:
The elements are <div>'s with text inside, coming from a PHP foreach loop.
While being pulled from the database, there is an if conditional that can add a class, where I can can control the width/height of the element. This will make the element larger.
I've looked into CSS Grid & Flexbox, and can't see a solution. The amount of larger boxes can change from page to page, but should always keep the same pattern.
I'm wondering if the best solution would be to somehow re-arrange the array in PHP to re-order the output of the elements.
I've really tried to find a solution for this with CSS Grid, but unfortunately I've come only on possibilities which donĀ“t make the whole thing dynamic as you might want. But I think there are currently no other options - if someone knows a way, please correct me. ;)
According to my knowledge, there is also currently no selector in css that allows you to accurately address every second element of a class, which unfortunately makes it more complicated.
In my first solution, I have built on the :nth-child(even) selector. For this approach the element with the class you want to address must be the in the right order to the parent element, so that the index is correct. Thereby you would have to adjust the PHP code, so that the larger elements already get in the right place in the HTML output.
For the second solution (which I like much less), I tried to build the whole thing on the general sibling combinator selector. With this I address all existing elements on the page individually like: .class ~ .class = second element or .class ~ .class ~ .class = third element. As a result, the PHP code would not have to be adjusted and you get "more flexibility" on this part, but you would be limited in the number of elements per page, since the settings for them would be fixed in the CSS code.
Here now the two solutions:
1. The :nth-child(even) way
.grid {
display: grid;
height: 100%;
width: 100%;
grid-template-columns: repeat(4, 1fr);
grid-auto-rows: 1fr;
grid-gap: 20px;
grid-auto-flow: row dense;
}
.grid__item--large {
grid-column: -3 / span 2;
grid-row: span 2;
}
.grid__item--large:nth-child(even) {
grid-column: 1 / span 2;
}
/* just for the snippet styling */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
margin: 20px;
}
.grid__item {
min-height: 200px;
background: gray;
display: flex;
justify-content: center;
align-items: center;
font-size: 2em;
color: white;
}
.grid__item--large {
min-height: 400px;
}
/* --- */
<div class="grid">
<div class="grid__item grid__item--large">1</div>
<div class="grid__item">2</div>
<div class="grid__item">3</div>
<div class="grid__item">4</div>
<div class="grid__item">5</div>
<div class="grid__item grid__item--large">6</div>
<div class="grid__item">7</div>
<div class="grid__item">8</div>
<div class="grid__item">9</div>
<div class="grid__item">10</div>
<div class="grid__item grid__item--large">11</div>
<div class="grid__item">12</div>
<div class="grid__item">13</div>
<div class="grid__item">14</div>
<div class="grid__item">15</div>
<div class="grid__item grid__item--large">16</div>
<div class="grid__item">17</div>
<div class="grid__item">18</div>
<div class="grid__item">19</div>
<div class="grid__item">20</div>
</div>
2. The "general sibling combinator" way
.grid {
display: grid;
height: 100%;
width: 100%;
grid-template-columns: repeat(4, 1fr);
grid-auto-rows: 1fr;
grid-gap: 20px;
grid-auto-flow: row dense;
}
.grid__item--large {
grid-column: -3 / span 2;
grid-row: span 2;
}
.grid__item--large ~ .grid__item--large {
grid-column: 1 / span 2;
}
.grid__item--large ~ .grid__item--large ~ .grid__item--large {
grid-column: -3 / span 2;
}
.grid__item--large ~ .grid__item--large ~ .grid__item--large ~ .grid__item--large {
grid-column: 1 / span 2;
}
/* just for the snippet styling */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
margin: 20px;
}
.grid__item {
min-height: 200px;
background: gray;
display: flex;
justify-content: center;
align-items: center;
font-size: 2em;
color: white;
}
.grid__item--large {
min-height: 400px;
}
/* --- */
<div class="grid">
<div class="grid__item">1</div>
<div class="grid__item grid__item--large">2</div>
<div class="grid__item">3</div>
<div class="grid__item">4</div>
<div class="grid__item grid__item--large">5</div>
<div class="grid__item">6</div>
<div class="grid__item">7</div>
<div class="grid__item">8</div>
<div class="grid__item">9</div>
<div class="grid__item grid__item--large">10</div>
<div class="grid__item">11</div>
<div class="grid__item">12</div>
<div class="grid__item">13</div>
<div class="grid__item">14</div>
<div class="grid__item">15</div>
<div class="grid__item grid__item--large">16</div>
<div class="grid__item">17</div>
<div class="grid__item">18</div>
<div class="grid__item">19</div>
<div class="grid__item">20</div>
</div>
I hope that can help somehow. :)
hope to help you.
var row=5; // total row layout
var count=0;
var strLayout='';
for(var i=0;i<row*2;i++){
if(count%3==0){
strLayout +='<div style="float:left;width:100px;height:100px;"><div style="float:left;width:40px;height:40px;margin: 5px;;background:black"></div>';
strLayout +='<div style="float:left;width:40px;height:40px;margin: 5px;;background:black"></div>';
strLayout +='<div style="float:left;width:40px;height:40px;margin: 5px;;background:black"></div>';
strLayout +='<div style="float:left;width:40px;height:40px;margin: 5px;;background:black"></div></div>';
}else{
strLayout +='<div style="float:left;width:90px;height:90px;margin: 5px;background:black"></div>';
}
if (count==3){
count=0;
}else{
count++;
}
}
$('#layout').html(strLayout);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="layout" style="float:left;width:200px;background:white">
</div>
I want to make the following bootstrap code automatically show an overlay for two out of three options contained in a database field. They are SOLD, CONTRACT, and NO.
I want different overlays for SOLD and CONTRACT, and no overlay for NO
I have searched for overlays, most tutorials have on hover events, and I am lost as to how to do this.
<div class="row">
<div class="col-md-6 col-md-offset-3">
<a href="listing_show.php?ID=<?php echo($Recordset1->getColumnVal("ID")); ?>">
<img src="images/<?php echo($Recordset1->getColumnVal("IMAGE")); ?>" class="img-responsive center-block sold" alt="<?php echo($Recordset1->getColumnVal("TITLE")); ?>"/>
</a>
</div><br><br>
</div>
I worked it out through a couple of js fiddles on other questions here, if it helps anyone here is the code I added...
html
I added a thumbnail div and a caption div underneath the image both conditional on the contents of the database field.
<?php if($Recordset1->getColumnVal("SOLD") == "YES") { ?>
<div class="caption post-content-sold"></div>
<? } ?>
<?php if($Recordset1->getColumnVal("SOLD") == "CON") { ?>
<div class="caption post-content-contract"></div>
<? } ?>
Then in the CSS I added code to make the thumbnail relative, and then added the two classes to style the image relating to the database field
.thumbnail {
position: relative;
}
.post-content-sold {
background: rgba(255, 255, 255, 0.8) none repeat scroll 0 0;
opacity: 0.8;
top:0;
left:0;
min-width: 100%;
max-height: 98%;
position: absolute;
color: #ffffff;
content:url(http://www.mtnlakerealty.com/sold.png);
}
.post-content-contract {
background: rgba(255, 255, 0, 1) none repeat scroll 0 0;
opacity: 1;
top:5%;
left:5%;
max-width: 50%;
max-height: 50%;
position: absolute;
color: #ffffff;
content:url(http://www.mtnlakerealty.com/contract.png);
}