Vertically align buttons below caption to longest text of three captions - css

Just started creating a website in WordPress with Bootstrap 4 and I've been puzzling on an issue for days now.
I'm trying to vertically align read more buttons for a 'related posts' section on a website. I want to have the read more button automatically aligned to the longest caption text. I've tried multiple ways with relative/absolute, but I can't seem to get it to work.
Here is my current code:
<div class="row">
<?php $cat = new WP_Query( 'cat=6&posts_per_page=3' ); ?>
<?php while($cat->have_posts()) : $cat->the_post(); ?>
<div class="col-xs-12 col-md-4 readmore">
<img class="w-100" src="<?php the_post_thumbnail_url(); ?>">
<div class="col-12" style="margin-top:15px;">
<h2 class="h6 text-uppercase text-center text-nowrap"><strong><?php the_title(); ?></strong></h2>
<p><?php the_content(); ?></p>
<p><?php //the_excerpt(); ?></p>
</div>
<div class="col-6 mx-auto" style="bottom: 10px;margin-bottom: 20px">
Read More
</div>
</div>
<?php endwhile; ?>
</div>
<?php wp_reset_postdata(); ?>
And this is how it look currently:
The thing that makes the even more difficult is that ideally it should still be responsive. So on a smaller screen the buttons should be directly after the caption, like this:
Hopefully it's clear what the problem is and hopefully someone can share their thoughts. Thanks in advance!

You don't need all child elements to initially be the same height. You can use flexbox to achieve the desired results you are looking for.
Here is a link to a codepen that shows the solution and there is an explanation below.
https://codepen.io/sugarbuzzdesigns/pen/ZjwQZb
Create a container that will contain all of your posts. This should be set to display: flex. Set the flex direction to column so we can set it to row on larger screens with a media query.
Create containers for each post. These posts are the flex items in the container we just created
Wrap your image, title, and content in one div so it can be evenly spaced separately from the read more button
Now you can set each post to flex: 1 so they take up equal space. Next you can set each post to flex-direction: column and justify-content: space-between.
HTML
<div class="container">
<div class="blog-post">
<div>
<h3>Heading Here</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quaerat explicabo cumque reiciendis error hic soluta rem enim amet laborum consequuntur, delectus mollitia molestiae maiores ullam possimus non corporis. Animi, sit. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corporis expedita laudantium ut earum sint, numquam adipisci autem cupiditate dolorem aspernatur illo laboriosam, dolores quis? Perspiciatis debitis nesciunt corporis dicta eveniet!<p>
</div>
Read More
</div>
<div class="blog-post">
<div>
<h3>Heading Here</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quaerat explicabo cumque reiciendis error hic soluta rem enim amet laborum consequuntur, delectus mollitia molestiae.<p>
</div>
Read More
</div>
<div class="blog-post">
<div>
<h3>Heading Here</h3>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quaerat explicabo cumque reiciendis error hic soluta rem enim amet laborum consequuntur, delectus mollitia molestiae maiores ullam possimus non corporis. Animi, sit.<p>
</div>
Read More
</div>
</div>
CSS
.container {
display: flex;
}
#media (min-width: 600px) {
.container {
flex-direction: row;
}
}
.blog-post {
display: flex;
flex: 1;
flex-direction: column;
justify-content: space-between;
}

You will need to specify a div where all child elements are of equal height. I believe there are some features for responsive design too. Check this article out:
How do I keep two side-by-side divs the same height?
The top comment under the answer suggests: If you are developing a responsive design and you want your second div to go down in smaller screens you will need to set .row to display: block; in your media query.
I will run some testing for you now and post the code snippet

Related

:empty selector not working in #media print [duplicate]

This question already has answers here:
:empty selector not working in css
(3 answers)
Closed 3 years ago.
I work in Twig on symphony and have an empty div that should be hidden in print mode.
<div class="form-fields__list">
</div>
The thing is that on screen the :empty selector works just fine, but is being ignored in print mode. Even tried to wrap the block mentioned above in {% spaceless %} block in order to remove any possible whitespaces. Anyone have an idea why this might be happening?
The :empty pseudo selector will select elements that contain either nothing or only an HTML comment.
Will Match
<div></div>
<div><!-- test --></div>
Will Not Match
<div> </div>
<div>
<!-- test -->
</div>
<div>
</div>
.container {
margin: 40px auto;
max-width: 700px;
}
#media print {
p:empty {
background-color: linen;
padding: 15px;
}
}
.pseudo::before {
content: "I am a piece of generated content inside a paragraph. The paragraph is still considered empty and gets a background color.";
}
<div class="container">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima, in, odit autem tempora fuga neque quos expedita repudiandae labore iure. Rem, blanditiis natus unde nisi explicabo odio pariatur maxime earum.
</p>
<p></p>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloremque, tempora, ratione ad distinctio iusto illum accusamus qui porro inventore commodi voluptates tenetur dolor sed harum excepturi nemo aperiam beatae sint!
</p>
<p class="pseudo"></p>
<p>
<!-- COMMENT HERE -->
</p>
<p></p>
</div>

Bootstrap 3 Reorder columns for mobile and tablet

I using Bootstrap 3 and im trying to reorder the columns position in mobile and tablet.
How is this possible?
this is my code:
<div class="row main-row">
<div class="col-md-6">
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quia illum recusandae delectus assumenda adipisci minima eaque! Tempore sit eius error, enim, voluptatem repudiandae dolorem atque fugiat aperiam placeat, corporis consequuntur.
</div>
<div class="col-md-6">
</div>
</div>
I want to Bootstrap to show
Text
Image
Text
Image
Right now it shows
Image
Text
Text
Image
Is there a way to handle this?
What it looks like right now
Can use flex in the mobile version.
.main-row {
display: flex;
flex-flow: column;
}
.main-row .col-md-6 {
display: flex;
order: 1;
}
.main-row .col-md-6 +.col-md-6 {
display: flex;
order: 0;
}
<div class="row main-row">
<div class="col-md-6">
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quia illum recusandae delectus assumenda adipisci minima eaque! Tempore sit eius error, enim, voluptatem repudiandae dolorem atque fugiat aperiam placeat, corporis consequuntur.
</div>
<div class="col-md-6">
IMGES
</div>
</div>
Unfortunately in Bootstrap 3 you cannot change the order of columns in smaller screens but you can do that in large screens. In Bootstrap 4 you can now change the order of columns in smaller screens. Below you can see one way of doing this.
<div class="row flex-column-reverse flex-md-row">
<div class="col-md-3">
sidebar
</div>
<div class="col-md-9">
main
</div>
</div>

Controlling height of adjacent column in css grid

I have a job site designed with with css grid. The job listings and email subscribe are divided bygrid-template-columns: (3fr, 1fr), the problem is is that the email subscribe box is the same height as the job listings (if there are 10 listings for example this is quite a large email subscribe box), how can I change this? (Note: jsfiddle included at bottom will make it much more clear and I have tried to set a height value on #item2 and this did not work) Thanks in advance!
.grid {
display: grid;
grid-template-columns: 3fr 1fr;
}
#item1 {
margin-left: 15px;
}
#item1>h1 {
text-align: center;
}
#list_of_jobs {
list-style: none;
}
#item2 {
text-align: center;
margin-right: 15px;
border: 3px solid #eeeeee;
}
<div class="grid">
<div id="item1">
<h1>Jobs in 10529</h1>
<table>
<tbody>
<div>
<ul id="list_of_jobs">
<li>
<h2>Job 1</h2>
<p class="lead"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus itaque minus corporis earum consequuntur unde saepe consequatur commodi harum ut. </p>
</li>
<li>
<h2>Job 2</h2>
<p class="lead"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus itaque minus corporis earum consequuntur unde saepe consequatur commodi harum ut. </p>
</li>
<li>
<h2>Job 3</h2>
<p class="lead"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus itaque minus corporis earum consequuntur unde saepe consequatur commodi harum ut. </p>
</li>
<li>
<h2>Job 4</h2>
<p class="lead"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repellendus itaque minus corporis earum consequuntur unde saepe consequatur commodi harum ut. </p>
</li>
</ul>
</div>
</tbody>
</table>
</div>
<div id="item2">
<form>
<p>Subscribe to recieve job alerts near 105</p>
<!-- query stores zip code-->
<input type="text" placeholder="Email">
<button class="btn" type="submit">Subscribe</button>
</form>
</div>
</div>
<!-- close grid div-->
http://jsfiddle.net/bmy0s93k/2/
Add this to your code:
#item2 {
align-self: start;
}
revised fiddle
A default setting in a grid container (like in a flex container) is align-items: stretch. This means that grid items (like flex items) will stretch the full length of the relevant axis in the container.
You need to override the default.
References:
ยง 6.2. Block/Cross-Axis Alignment: the align-self property
How to disable equal height columns in Flexbox?

Floating different height divs [duplicate]

i am using left floating DIVs to simulate a two column layout (each div contains textfield to edit different data, like name, hobbies,...). So it should look like this
1 2
3 4
5 6
Now my div-boxes aren't always the same, since some DIVs have more elements than the other ones. Now my layout looks likes this
1 2
2
3 4
5 6
You can also see the effect on this example if you scale your so that only four or three colums are shown. E.g. if 4 columns are shown in a row there is much space between Float 1 and Float 6. This doesn't look good on my UI. What I want is to have Float 6 following Float 1 with no space in between (except the margin I define)
Edit: My DIVs basically just contain a float:left and a width:40%, so that two fit on a screen
Here's a screenshot showing more
Here is a pure CSS solution. I took this example
Check it out if you want to learn more. He also use jQuery Masonry as fallback.
CSS:
.masonry { /* Masonry container */
-moz-column-count: 4;
-webkit-column-count: 4;
column-count: 4;
-moz-column-gap: 1em;
-webkit-column-gap: 1em;
column-gap: 1em;
}
.item { /* Masonry bricks or child elements */
background-color: #eee;
display: inline-block;
margin: 0 0 1em;
width: 100%;
}
HTML:
<div class="masonry">
<div class="item">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</div>
<div class="item">Neque, vitae, fugiat, libero corrupti officiis sint facilis tempora quidem repudiandae praesentium odit similique adipisci aut.</div>
<div class="item">Incidunt sit unde minima in nostrum? Incidunt sit unde minima in nostrum?</div>
<div class="item">Ducimus, voluptates, modi, delectus animi maiores consequuntur repellat quisquam fugiat eum possimus enim culpa totam praesentium magni quae!</div>
<div class="item">Lorem ipsum dolor sit amet, dicta dolore adipisci hic ipsam velit deleniti possimus cumque accusantium rerum quibusdam.</div>
<div class="item">Neque, vitae, fugiat, libero corrupti officiis sint facilis tempora quidem repudiandae praesentium odit similique adipisci aut.</div>
<div class="item">Incidunt sit unde minima in nostrum?</div>
<div class="item">Incidunt sit unde minima in unde minima in unde minima in nostrum?</div>
<div class="item">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae, praesentium consequatur ducimus commodi quam ex illo omnis dicta reiciendis vel nesciunt deserunt aut sequi nam mollitia perferendis ipsam possimus temporibus!</div>
<div class="item">Ab, adipisci, temporibus eaque quis harum perferendis incidunt cupiditate doloribus dolor numquam voluptates ipsum dolore aspernatur et voluptate ipsam beatae animi culpa.</div>
</div>
Hope this will help you. Thanks.
The jQuery Masonry plugin will do exactly what you want.
If you wanted to stick with pure CSS, you could do something like the following, but I don't think it's what you're going for:
<div class="col">
<div class="one"></div>
<div class="three"></div>
<div class="five"></div>
<div class="seven"></div>
</div>
<div class="col">
<div class="two"></div>
<div class="four"></div>
<div class="six"></div>
<div class="eight">who do we appreciate</div>
</div>
And the CSS:
.col {
float: left;
width: 200px;
}
if you can use php, here is little trick ;)
<?php
$dir = "your/images/dir/";
$img = scandir($dir); // read images to array, or make script which read it from db
unset($img[0], $img[1]); // remove unnecessary ;)
$columns = 5; // define how many columns you want to use
$margin = 5; // define page margin and margin between images in %
// create columns..
for ($c = 0; $c < $columns; $c ++)
{
$main_counter = 0;
foreach ($img as $file)
{
if ($main_counter % $columns == $c)
{
$column[$c][] = $file;
}
$main_counter ++;
}
}
?>
<! -- show images -->
<div style="margin: <?php echo $margin; ?>%;">
<?php
foreach ($column as $key => $data)
{
?>
<div style="float: left; width: <?php echo (100 / $columns); ?>%;">
<?php
foreach ($data as $image)
{
?>
<div style="margin-bottom: <?php echo $margin; ?>%; margin-right: <?php echo $margin; ?>%; background-image: url(<?php echo $dir . $image; ?>); background-size: cover;"><img src="<?php echo $dir . $image; ?>" style="visibility: hidden; width: 100%;"></div>
<?php
}
?>
</div>
<?php
}
?>
</div>
maybe help you ;)
working demo on http://www.showcase.glirp.sk/

CSS Floating Divs with different height are aligned with space between them

i am using left floating DIVs to simulate a two column layout (each div contains textfield to edit different data, like name, hobbies,...). So it should look like this
1 2
3 4
5 6
Now my div-boxes aren't always the same, since some DIVs have more elements than the other ones. Now my layout looks likes this
1 2
2
3 4
5 6
You can also see the effect on this example if you scale your so that only four or three colums are shown. E.g. if 4 columns are shown in a row there is much space between Float 1 and Float 6. This doesn't look good on my UI. What I want is to have Float 6 following Float 1 with no space in between (except the margin I define)
Edit: My DIVs basically just contain a float:left and a width:40%, so that two fit on a screen
Here's a screenshot showing more
Here is a pure CSS solution. I took this example
Check it out if you want to learn more. He also use jQuery Masonry as fallback.
CSS:
.masonry { /* Masonry container */
-moz-column-count: 4;
-webkit-column-count: 4;
column-count: 4;
-moz-column-gap: 1em;
-webkit-column-gap: 1em;
column-gap: 1em;
}
.item { /* Masonry bricks or child elements */
background-color: #eee;
display: inline-block;
margin: 0 0 1em;
width: 100%;
}
HTML:
<div class="masonry">
<div class="item">Lorem ipsum dolor sit amet, consectetur adipisicing elit.</div>
<div class="item">Neque, vitae, fugiat, libero corrupti officiis sint facilis tempora quidem repudiandae praesentium odit similique adipisci aut.</div>
<div class="item">Incidunt sit unde minima in nostrum? Incidunt sit unde minima in nostrum?</div>
<div class="item">Ducimus, voluptates, modi, delectus animi maiores consequuntur repellat quisquam fugiat eum possimus enim culpa totam praesentium magni quae!</div>
<div class="item">Lorem ipsum dolor sit amet, dicta dolore adipisci hic ipsam velit deleniti possimus cumque accusantium rerum quibusdam.</div>
<div class="item">Neque, vitae, fugiat, libero corrupti officiis sint facilis tempora quidem repudiandae praesentium odit similique adipisci aut.</div>
<div class="item">Incidunt sit unde minima in nostrum?</div>
<div class="item">Incidunt sit unde minima in unde minima in unde minima in nostrum?</div>
<div class="item">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quae, praesentium consequatur ducimus commodi quam ex illo omnis dicta reiciendis vel nesciunt deserunt aut sequi nam mollitia perferendis ipsam possimus temporibus!</div>
<div class="item">Ab, adipisci, temporibus eaque quis harum perferendis incidunt cupiditate doloribus dolor numquam voluptates ipsum dolore aspernatur et voluptate ipsam beatae animi culpa.</div>
</div>
Hope this will help you. Thanks.
The jQuery Masonry plugin will do exactly what you want.
If you wanted to stick with pure CSS, you could do something like the following, but I don't think it's what you're going for:
<div class="col">
<div class="one"></div>
<div class="three"></div>
<div class="five"></div>
<div class="seven"></div>
</div>
<div class="col">
<div class="two"></div>
<div class="four"></div>
<div class="six"></div>
<div class="eight">who do we appreciate</div>
</div>
And the CSS:
.col {
float: left;
width: 200px;
}
if you can use php, here is little trick ;)
<?php
$dir = "your/images/dir/";
$img = scandir($dir); // read images to array, or make script which read it from db
unset($img[0], $img[1]); // remove unnecessary ;)
$columns = 5; // define how many columns you want to use
$margin = 5; // define page margin and margin between images in %
// create columns..
for ($c = 0; $c < $columns; $c ++)
{
$main_counter = 0;
foreach ($img as $file)
{
if ($main_counter % $columns == $c)
{
$column[$c][] = $file;
}
$main_counter ++;
}
}
?>
<! -- show images -->
<div style="margin: <?php echo $margin; ?>%;">
<?php
foreach ($column as $key => $data)
{
?>
<div style="float: left; width: <?php echo (100 / $columns); ?>%;">
<?php
foreach ($data as $image)
{
?>
<div style="margin-bottom: <?php echo $margin; ?>%; margin-right: <?php echo $margin; ?>%; background-image: url(<?php echo $dir . $image; ?>); background-size: cover;"><img src="<?php echo $dir . $image; ?>" style="visibility: hidden; width: 100%;"></div>
<?php
}
?>
</div>
<?php
}
?>
</div>
maybe help you ;)
working demo on http://www.showcase.glirp.sk/

Resources