How do i remove the inline-block space between two divs that are a part of the wordpress loop? They are supposed to sit side-by-side, each being 50% width. I realize I could change the width to 49% or use floats, but I would like to leave it this way if possible.
I know you normally can do it by eliminating the white space in the coding with comments as below:
<div class="before-after">
<img src="images/ba_01.jpg" alt="">
<h4>Frick TDSH 355XL<br><small>Slide Valve and Rotor Housing</small></h4>
</div><!-- this comment here eleminates the spacing
--><div class="before-after">
<img src="images/ba_02.jpg" alt="">
<h4>Frick NGC300 Gear Plate</h4>
</div>
This is my wordpress loop, and no matter where I put the comment, and still adds white space in the actual returned html.
<?php
$my_query = new WP_Query(
array(
'cat' => '2',
)
);
while ( $my_query->have_posts() ) : $my_query->the_post();
?>
<div class="before-after">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
?>
<h4><?php the_title(); ?><br><small><?php the_content(); ?></small></h4>
</div><!-- --><?php endwhile;?><?php wp_reset_postdata();?>
And this is what is showing up in Developer Tools:
<div class="before-after">...</div>
<!---->
<div class="before-after">...</div>
<!---->
I'm sure I'm just overlooking something easy, but any help would be appreciated. Thanks!
#Prusprus here it is straight from the source code:
<div class="before-after">
<img width="500" height="300" src="http://localhost:8888/wp-content/uploads/2013/10/ba_02.jpg" class="attachment-post-thumbnail wp-post-image" alt="Frick NGC300 Gear Plate" />
<h4>Frick NGC300 Gear Plate<br><small></small></h4>
</div>
<!---->
<div class="before-after">
<img width="500" height="300" src="http://localhost:8888/wp-content/uploads/2013/10/ba_01.jpg" class="attachment-post-thumbnail wp-post-image" alt="Frick TDSH 355XL" />
<h4>Frick TDSH 355XL<br><small><p>Slide Valve and Rotor Housing</p>
</small></h4>
</div>
<!---->
There may be a different way to mark this as answered, not sure, but #Prusprus gave me the solution in a comment above.
I simply had to remove a line break at the start of my code between the closing php tag and the start of my div.
The traditional way of floating inline-block elements could correct this, but since its unfavored there is another way.
You can also set the letter spacing of the parent element to -0.31em to solve this and set the letter-spacing back to normal in the divs themselves. I'll set up a jsfiddle in a sec.
CODE
.row {
letter-spacing:-0.31em;
}
.col {
letter-spacing:normal;
display:inline-block;
width:50%;
}
Good luck!
Two methods here
Set the parent's font-size to 0 and then restore it on the inline-block elements.
Apply a suitable margin to the last div.
DEMO x 2
HTML
<div class="opt1">
<div class="before-after"></div>
<div class="before-after"></div>
</div>
<div class="opt2">
<div class="before-after"></div>
<div class="before-after"></div>
</div>
CSS
.opt1, .opt2 {
margin:10px;
border:1px solid green;
}
.before-after {
display:inline-block;
background:lightgrey;
width:50%;
height:100px;
font-size:16px
font-size:1rem;
}
.opt1 {
font-size:0;
}
.opt2 .before-after{
vertical-align:top;
}
.opt2 .before-after:last-child {
margin-left:-.25em;
}
Related
So I have a Wordpress page in the making, and basically I have a title column and a text column.
The issue is that I am using the wordpress text editor, and its putting all of my content into the text column but I want a couple of photos and captions for those photos to go into the title column so that the readers read and theres pictures alongside. I was successful with using position:absolute, except that the photos were no longer responsive to zooming in and out on the webpages.
How can I keep the written content in the text column, and the pictures in the title column and have them still be responsive to zoom that they stay within the title-column with zooming in/out?
(I put the "<" in (<) on purpose)
(<)a href="http://localhost/wordpress/wp-content/uploads/2016/04/18.jpg">
(<)img class="size-medium wp-image-146 alignleft";
(<)src="http://localhost/wordpress/wp-content/uploads/2016/04/18.jpg" alt="Age 18" width="175" height="400" />
(<)div id=caption18>Me around age 18(<)/ div>
/* Two Column Title Layout */
div.title-column {
width: 20%;
float: left;
}
div.text-column {
width: 80%;
float: right;
}
<article class="post page">
<!-- column-container -->
<div class="column-container clearfix">
<!-- title-column -->
<div class="title-column">
<h2><?php the_title(); ?></h2>
</div><!-- /title-column -->
<!-- text-column -->
<div class="text-column">
<?php the_content(); ?>
</div><!-- /text-column -->
</div><!-- /column-container -->
</article>
<?php endwhile;
else :
echo '<p>No content found</p>';
endif;
get_footer();
?>
If I understood your question right, you are trying to do something like this while retaining the scalability of the image(s)? Note that I had to adjust some of your brackets. I also changed the width of the image to "auto" and the height to "0". This should retain the scalability of the image, but I have not tested it.
<!-- title-column -->
<div class="title-column">
<h2><?php the_title(); ?></h2>
<a href="http://localhost/wordpress/wp-content/uploads/2016/04/18.jpg">
<img class="size-medium wp-image-146 alignleft" src="http://localhost/wordpress/wp-content/uploads/2016/04/18.jpg" alt="Age 18" width="auto" height="0">
</a>
</div><!-- /title-column -->
I have links of images stored in database,I want to bring the set of images at the centre of the screen (which in my case is left-aligned). No matter how many pictures comes dynamically, the set of the images should be aligned centre.
Iam using bootstrap for designing and here is how my code look like:
<div class="row">
<div class="col-md-12 text-center">
<?php
foreach($n as $val)
{ // loop to iterate 'n' image links
?>
<div class="col-md-1">
<img src="<?php echo $val; ?>" // images showing up.
</div>
<?php
}
?>
</div>
</div>
I am adding an image below to demonstrate the situation.
I have tried the following:
bootstrap classes : center-block (which is based on margin)
bootstrap classes : text-center (which is based on text-align)
bootstrap classes : "img-responsive center-block"
Please Note:
I don't want to push the content toward centre forcefully (like using of bootstrap class "col-md-push-3" or something as such, because the number of images to be displayed is not fixed. They vary time to time)
The column classes you are using to wrap the images [col-md-1]are floated left by default....you'd have to override that behaviour.
.text-center .col-md-1 {
float: none;
display: inline-block;
}
.text-center .col-md-1 {
float: none;
display: inline-block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="col-md-12 text-center">
<div class="col-md-1">
<img src="http://lorempixel.com/image_output/city-q-c-100-100-6.jpg" />
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<div class="col-md-1">
<img src="http://lorempixel.com/image_output/city-q-c-100-100-6.jpg" />
</div>
<div class="col-md-1">
<img src="http://lorempixel.com/image_output/city-q-c-100-100-6.jpg" />
</div>
</div>
</div>
You can still use some good old CSS using FlexBox, as shown on this Fiddle. Basically, it uses a structure like:
<div class="container">
<div class="picture">
<img src="http://lorempixel.com/image_output/food-q-c-200-200-1.jpg" />
</div>
</div>
And then, with some FlexBox properties, you can achieve what you want:
.container {
display: flex;
}
.picture {
flex: 1 1;
width: 100%;
}
img {
width: 100%;
}
To sum up, you put the container in flex mode, and then all its div would occupy same space. Some intermediary divs are required in order to keep the aspect ratio of each image.
If you want to center them in case of you have less pictures available, you can still use the justify-content: center; property, setting a maximum width on the divs, such as this other Fiddle.
Note however that this solution would not work on IE9-.
Make a div with text-align:center
Amand then make a div inside it with display:inline-block
I am using this simple code in my view.php. The div is aligned horizontally correctly, but it aligns vertically in print.
<div class="row">
<div class="col-lg-6">
<div class="col-lg-7" style="padding:5px;box-sizing: border-box;border: 1px solid #ddd;background-color:#f9f9f9">
<b>Patient Name:</b> <?= $model->patient_name ?>
</div>
<div class="col-lg-5" style="padding:5px;box-sizing: border-box;border: 1px solid #ddd;background-color:#f9f9f9">
<b> Auth. No.:</b> <?= $model->authorisation_number ?>
</div></div> </div>
I want these div to align horizontally in print as well. I am not using any custom print.css for this page.
Ok I found the answer-
I need to use <div class=col-xs-*> in place of <div class = col-lg-*> that mostly achieves what I am looking for.
I welcome if there is any better workaround.
Thanks.
I have a link in the following div, it code is,
<?php _e('More', 'isis'); ?>
Now, I want to make the whole div a hyperlink. Please guide me. Thanks. The whole code is below,
<div class="midrow_blocks_wrap">
<i class="fa <?php echo of_get_option('block1_logo'); ?> fa-3x icon"></i>
<a href="#">
<div class="midrow_block">
<!--We need to make this div a link -->
<div class="mid_block_content">
<h3><?php echo of_get_option('block1_text'); ?></h3>
<p><?php echo of_get_option('block1_textarea'); ?></p>
</div>
<?php if ( of_get_option('block1_link') ) { ?><?php _e('More', 'isis'); ?><?php } ?>
</div>
</div>
<div class="shadow"><img src="<?php echo get_template_directory_uri(); ?>/images/service_shadow.png" alt="<?php the_title_attribute(); ?>" /></div>
</div>
A lot of the time when I'm trying to make a hyperlink fill a whole div I give the div a position: relative and the hyperlink a position: absolute; width: 100%; height: 100%; left: 0; top:0; I developed this because wrapping a whole div in a hyperlink can be screwy.
It is usually much easier to do it that way. If you give a z-index: 9 or some higher number you will cover most of your base for the div and then if you need other links or content in there you'll need to do a higher z-index.
Just a thought.
So I want to position my a meta-data div in the corner of every post image, but all the images are different sizes. How do I do this?
Heres an example of what I need:
This is the loop:
<div id="images">
<?php wp_get_attachment_image(); ?>
</div>
<div id="date">
<?php get_the_date(); ?>
</div>
I posted this # wordpress.stackexchange but they said to post it here
It doesn't matter what size the image is. You have to give the container div a position:relative and the corner div a position:absolute with top:0 and left:0
HTML:
<div id="images"><?php wp_get_attachment_image(); ?>
<div id="date"><?php get_the_date(); ?></div>
</div>
*note date is inside the image tag!
CSS:
#images{
position:relative;
}
#date{
position:absolute;
top:0;
left:0;
}