I'm trying to put the output of a query, in php, in a column based grid. I was trying to get a pinterest like effect with four columns, where every post has a different height, but where they all have the same width.
If I try using display: grid;, I'll get a single column with all the posts, because the foreach will just dump it all there.
if i try using display: inline-grid; it becomes a row based grid, and the result isn't exactly pretty.
php code
class Post{
public static function getAll()
{
$conn = Db::getInstance();
$result = $conn->query('SELECT posts.*,users.firstname,users.lastname, users.picture FROM posts,users WHERE posts.user_id=users.id ');
return $result->fetchAll(PDO::FETCH_CLASS, __CLASS__);
}
}
html code
<?php foreach ($posts as $post): ?>
<div class="grid-container">
<div class="post">
<article >
<img src="<?php echo $post->picture; ?>" class="profilepic">
<p class="name"> <?php echo $post->firstname.' '.$post->lastname; ?> </p>
<p> <?php echo $post->date_created; ?> </p>
<img src="<?php echo $post->image; ?>" alt="">
<p> <?php echo $post->description; ?> </p>
More
</article>
</div>
</div>
<?php endforeach; ?>
css code
div.grid-container {
display: grid;
grid-column: 25% 25% 25% 25%;
}
is there any way to do this?
Make sure your post is placed around your <div class="post">. Currently you are creating a new <div class="grid-container"> on every loop iteration.
Also, instead of using the css property grid-column please use grid-template-columns as #Wendelin has shown above in the code snippet.
If that doesn't work, please paste a dump of your rendered HTML and CSS here.
Your css is wrong grid-column specifies in which column an item should be. What you want is grid-template-columns
div.grid-container {
display: grid;
grid-template-columns: 25% 25% 25% 25%;
}
also instead of using 25% you can use 1fr. Read more.
Basically fr stands for fraction. You define 1fr four times so together there are 4 fractions.
Then it divides the specified fractions by the total fractions and converts it to percent.
Example:
grid-template-columns: 1fr 1fr 1fr 1fr = grid-template-columns: 1/4 1/4 1/4 1/4 = grid-template-columns: 25% 25% 25% 25%
grid-template-columns: 2fr 1fr 2fr 3fr = grid-template-columns: 2/8 1/8 2/8 3/8 = grid-template-columns: 25% 12.5% 25% 37.5%
div.grid-container {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
}
.post {
height: 100px;
background-color: #eee;
margin: 5px;
padding: 5px;
text-align: center;
}
<div class="grid-container">
<div class="post">
<article>
Some content
</article>
</div>
<div class="post">
<article>
Some content
</article>
</div>
<div class="post">
<article>
Some content
</article>
</div>
<div class="post">
<article>
Some content
</article>
</div>
<div class="post">
<article>
Some content
</article>
</div>
<div class="post">
<article>
Some content
</article>
</div>
<div class="post">
<article>
Some content
</article>
</div>
<div class="post">
<article>
Some content
</article>
</div>
</div>
Related
.s-assets {
width: 100%;
height: 60vh;
&__block {
height: 10vh;
background-image: url("http://nas.gansa.pl/2019/puszczaknyszynska/wp-content/uploads/2019/10/Inteligentny_obiekt_wektorowy_kopia_12.png");
}
&__content {
width: 500px;
background-image: url('http://nas.gansa.pl/2019/puszczaknyszynska/wp-content/uploads/2019/10/Inteligentny_obiekt_wektorowy_kopia_12.png');
}
}
<div class="col col-12 col-sm-6 col-lg-3 s-assets__block s-assets__block--first">
<?php if (have_rows('sub_first_asset')) : ?>
<?php while (have_rows('sub_first_asset')) : the_row();
?>
<div class="s-assets__content">
<h3 class="s-assets__block-title">
<?php echo get_sub_field('sub_sub_first_asset_title'); ?>
</h3>
<div class="s-assets__block-img">
<img alt="" src="<?php echo get_sub_field('sub_sub_first_asset_img'); ?>" />
</div>
</div>
<?php endwhile;
endif; ?>
</div>
So I have to create this:
I have made acf's for h2 and img (image of bed, in this case). Then I had to export those two frames (vertical and horizontal) and place them as .png, but I can't put them ino html structure, I have to use css.
This doesn't work and I have no idea why... maybe there is something I do not understant about how css actually works?
Please be undarstaning, this is my first time I do such things.
note the difference in html, in your html there was only one class and not in your css you were using two
example .assets_title and not css with sass you were getting this: .assets.title{}
so in html must contain two classes in the
Modify the code below test please:
.s-assets {
width: 100%;
height: 60vh;
&.__block {
height: 10vh;
background-image: url("https://i.stack.imgur.com/xoRYM.png");
}
&.__content {
width: 500px;
background-image: url('https://i.stack.imgur.com/xoRYM.png');
}
}
.__block {
height: 10vh;
background-image: url("https://i.stack.imgur.com/xoRYM.png");
}
.__content {
width: 500px;
background-image: url('https://i.stack.imgur.com/xoRYM.png');
}
<div class="col col-12 col-sm-6 col-lg-3 s-assets__block s-assets__block--first">
<?php if (have_rows('sub_first_asset')) : ?>
<?php while (have_rows('sub_first_asset')) : the_row();
?>
<div class="s-assets __content">
<h3 class="s-assets __block-title">
<?php echo get_sub_field('sub_sub_first_asset_title'); ?>
</h3>
<div class="s-assets __block-img">
<img alt="" src="<?php echo get_sub_field('sub_sub_first_asset_img'); ?>" />
</div>
</div>
<?php endwhile;
endif; ?>
</div>
<div class=" testingclass wpd-page-title wpd-page-title_horiz_align_left wpd-page-title_vert_align_middle" style="background-color:#ffffff;height:80px;color:#222328;margin-bottom:15px;">
<div class="wpd-page-title__inner">
<div class="container">
<div class="wpd-page-title__content">
<div class="page_title">
<h1>Multilingual Digital Marketing</h1>
</div>
</div>
</div>
</div>
</div>
CSS for these are
body.term-107 .wpd-page-title {
background: url(https://khaleejdev.com/kds/newtornetto/wp-
content/uploads/2018/05/107.jpg)no-repeat;
background-size: 100%;
}
I want to make the below Header background image blur as below of this page.
https://khaleejdev.com/kds/newtornetto/product-category/multilingual-digital-marketing/
Please help me achieve it without affecting title. I tried all the previous answers of Stackoverflow but it didn't worked.
Actually i have a bunch of php code for wordpress product archive template, if html can adjusted to attain the feature i want without affecting current layout as shown in url https://khaleejdev.com/kds/newtornetto/product-category/multilingual-digital-marketing/ .
Please check the image , i want blur affect on image only, not on title.
It would be great.
Here is the php code
<div class=" testingclass wpd-page-title<?php echo !empty($page_title_classes) ? esc_attr($page_title_classes) : ''; ?>"<?php echo !empty($page_title_styles) ? ' style="'.esc_attr($page_title_styles).'"' : '' ?>>
<div class='wpd-page-title__inner'>
<div class='container'>
<div class='wpd-page-title__content'>
<div class='page_title content'>
<h1><?php echo esc_html($wpd_page_title); ?></h1>
<?php if(!empty($page_sub_title) && $page_title_horiz_align != 'center'): ?>
<div class='page_sub_title'><div><?php echo esc_attr( $page_sub_title ); ?></div></div>
<?php endif; ?>
</div>
<?php if (!empty($page_sub_title) && $page_title_horiz_align == 'center'): ?>
<div class='page_sub_title'><div><?php echo esc_attr( $page_sub_title ); ?></div></div>
<?php endif; ?>
<?php if ($page_title_breadcrumbs_conditional == 'yes'): ?>
<div class='wpd_breadcrumb'><?php
/** Breadcrumb Template */
get_template_part( 'template-parts/header/partials/breadcrumb' );
?></div>
<?php endif; ?>
</div>
</div>
</div>
</div>
You can use the following CSS declaration to blur a background image:
filter: blur(value);
N.B. If you want the <div> to contain other content but you wish to blur only the background image, then apply the background image and the blur to a ::before pseudo-element.
Working Example:
.wpd-page-title {
position: relative;
width: 100%;
height: 180px;
}
.wpd-page-title::before {
content: '';
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url(https://picsum.photos/300/300) no-repeat;
}
.blur-3px::before {
filter: blur(3px);
}
.blur-6px::before {
filter: blur(6px);
}
.blur-9px::before {
filter: blur(9px);
}
<div class="wpd-page-title"></div>
<div class="wpd-page-title blur-3px"></div>
<div class="wpd-page-title blur-6px"></div>
<div class="wpd-page-title blur-9px"></div>
Read More on CSS Filters:
https://css-tricks.com/almanac/properties/f/filter/
https://developer.mozilla.org/en-US/docs/Web/CSS/filter
https://www.sitepoint.com/css-filter-effects-blur-grayscale-brightness-and-more-in-css/
You have two options,
You can take out the "title" from the background parent div and use position absolute property to align it on the background image and apply blur code for the parent div
.testingclass{
filter: blur(5px);
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-o-filter: blur(5px);
-ms-filter: blur(5px);
}
like following
<div class=" testingclass wpd-page-title wpd-page-title_horiz_align_left wpd-page-title_vert_align_middle" style="background-color:#ffffff;height:80px;color:#222328;margin-bottom:15px;">
</div>
<div class="wpd-page-title__inner">
<div class="container">
<div class="wpd-page-title__content">
<div class="page_title">
<h1>Multilingual Digital Marketing</h1>
</div>
</div>
</div>
</div>
Use PSD to make the image Blur, because you cant control the blurred effect to inside elements if you apply blur or opacity to parent
You can notice that, the blur affect is working for the 3 image grid section, because the image and text are separated, and you are using position: absolute for the text div.
I have two sizes of images (vertical and horizontal), they will always be the same size, respectfully. I am trying to create a container that would hold the image but not push the content over and stay a similar height or width. I also dont want to show the image full size so I was thinking about using overflow:hidden. I have attempted this in a JSFiddle seen here but it stretches the container. Any help is appreciated.
<div>
<span class="mixSpanLeft">
<img src="http://cdn.wallpapersafari.com/26/79/HoFC0h.jpg" />
</span>
<span class="mixSpanRight">
<p>The images will always be on the left and will be only two sizes, 1000x500 or 500x1000. What is the best way to show them if they have alternating sizes? Should I have completely different styles for them?
</p>
</span>
</div>
http://jsfiddle.net/hmjoLmej/4/
What about something like this.
I used the more appropriate flexbox instead of float, which gives greater control of the layout.
The image is added using background, which gives greater control to scale, clip, etc.
Note, since the p is block element they should not be children of a span (which is inline element), so I updated your markup/CSS with a div
Updated, showing how you can add the image source in the markup
.wrapper {
display: flex;
}
.mixSpanLeft {
width: 50%;
background-color: #abc;
background-repeat: no-repeat;
background-position: center top;
background-size: cover;
}
.mixSpanLeft a {
display: inline-block;
height: 100%;
width: 100%;
}
.mixDivRight {
width: 50%;
background: #def;
}
.mixDivRight p {
padding: 2%;
}
<div class="wrapper">
<span class="mixSpanLeft" style="background-image: url(http://cdn.wallpapersafari.com/26/79/HoFC0h.jpg)">
</span>
<div class="mixDivRight">
<p>Content</p>
<p>Content</p>
<p>Content</p>
<p>Content</p>
</div>
</div>
<div class="wrapper">
<span class="mixSpanLeft" style="background-image: url(http://cdn.wallpapersafari.com/29/20/3HE5Mx.jpg)">
</span>
<div class="mixDivRight">
<p>Content</p>
<p>Content</p>
<p>Content</p>
<p>Content</p>
</div>
</div>
Could some body help with this?
I have this code which prints 4 picture articles on a row.
<article>
<div class="post-thumbnail img">
<?php if (class_exists('MultiPostThumbnails')) : MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'secondary-image'); endif; ?>
</div>
<!--/.post-thumbnail-->
</article>
Any time i try to add a subtitle, it does not stay on a row any more. like this
<article>
<div class="post-thumbnail img">
<?php if (class_exists('MultiPostThumbnails')) : MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'secondary-image'); endif; ?>
</div>
<div class="post-thumbnail img">
<?php the_title();?>
</div>
<!--/.post-thumbnail-->
</article>
What happens is, the fist image text will be below the image, the rest will be on top..But all needs to be below those images.
Any solution?
CSS`
.post-thumbnail img {
height: auto;
margin-bottom: -16px;
float: left;
width: 23.0%;
margin-right: 2%}
`
You should give us the HTML code generated by the PHP function.
So far, I don't know if you haven't made a mistake in your CSS code :
/* .post-thumbnail img = get the <img> inside a <div class="post-thumbnail"> */
/* .post-thumbnail.img = get the <div class="post-thumbnail img"> */
.post-thumbnail.img {
height: auto;
margin-bottom: -16px;
float: left;
width: 23.0%;
margin-right: 2%;
}
Hope that help.
I have the following PHP page
<?php include 'header-adminpanel.php'; ?>
<div class="container">
<div class="body-content">
<div class="side-left"><?php include 'adminproduct_sidebar.php'; ?></div>
<div class="side-right"></div>
</div>
</div>
<?php include 'footer.php'; ?>
Where I expected the output as
But the real output is
Styling is as follows;
.side-left{
width: 250px;
float: left;
height: auto;
}
.side-right{
width: 750px;
float: left;
height: auto;
}
.body-content{
height:auto;
width: 1000px;
margin:auto;
}
.container {
height: auto;
width: 100%;
}
Without those "side-left" and "side-right" divs it looks fine as below
What's wrong with my code? Any Suggestions..
You should add this before including footer. That should solve the things.
<div style="clear:both"></div>
Add
<div style="clear:both"></div>
before the line,
<?php include 'footer.php'; ?>
You are using floated elements and they collapsed as there is no content.
Add clearfix to body-content.
Also take a look at Why doesn't the height of a container element increase if it contains floated elements? and What does the CSS rule clear: both do?
add Clear both before footer div, Try the following
<?php include 'header-adminpanel.php'; ?>
<div class="container">
<div class="body-content">
<div class="side-left"><?php include 'adminproduct_sidebar.php'; ?></div>
<div class="side-right"></div>
</div>
</div>
<div style="clear:both"></div>
<?php include 'footer.php'; ?>
Example
The only reason that the footer is sliding to the right side of the '.container' is because '.container' div's child have a float property.
So for a quick fix add 'clear:both' to the '.container' div and also to the footer div or empty div.
If this does not fix the problem we need to see the footer, side-left and slid-right html.
Here is Two Solution
First Clearing Floats Using Clear:both
And Another Adding Overflow: auto to Parent div
HERE IS CODE
HTML :
<div class="body-content">
<div class="side-left"><?php include 'adminproduct_sidebar.php'; ?></div>
<div class="side-right"></div>
<div style="clear:both"></div>
</div>
Another solution is
Just adding a css
.body-content{
overflow:auto;
}
Hope it helps you :)