I have two half width divs that have the same class but are assigned posts through WordPress. Currently I have them lined up with full width posts above and below, but, I need to apply 5px of padding to both but not on the edges, i.e. left post has right padding, right post has left padding and I can't think for the life of me how to do this. I tried using different post formats and checking which format the post was and applying padding based on that but it didn't work as intended. For some reason, it pushed the divs to the center and had padding in the wrong places. Firstly here's my PHP structure with the if/else:
<?php if (has_post_format('status')) : ?>
<div class = "twocolumnpost left">
<div <?php post_class() ?>>
<?php if (has_post_thumbnail()) : ?>
<div class = "post-thumb">
<?php the_post_thumbnail(); ?>
<div class = "caption">
<h4><?php the_title(); ?></h4>
<p><?php echo get_the_date(); ?></p>
</div>
</div>
<?php endif; ?>
</div>
</div>
<?php elseif (has_post_format('gallery')) : ?>
<div class = "twocolumnpost right">
<div <?php post_class() ?>>
<?php if (has_post_thumbnail()) : ?>
<div class = "post-thumb">
<?php the_post_thumbnail(); ?>
<div class = "caption">
<h4><?php the_title(); ?></h4>
<p><?php echo get_the_date(); ?></p>
</div>
</div>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
As you can see it has padding on both the left and right sides (it should line up with the post above) and not enough in the middle. The CSS I used for this is:
.twocolumnpost .post {
float: left;
display: block;
width: 50%;
padding: 10px 0px;
}
.twocolumnpost.left {
padding-right: 0px;
}
.twocolumnpost.right {
padding-left: 0px;
}
.twocolumnpost img, .twocolumnpost iframe {
max-width: 440px;
max-height: 294px;
width: 100%;
padding: 0;
}
Now what I'd like it to be like is this:
BUT with 10px of padding in the center of the two posts but NOT the sides i.e. 5px right on the left post, 5px left on the right post. The only difference with the second image is that the max-width of the pictures are set to 450px instead of 400px and obviously have no left or right padding.
No matter what I try it doesn't line up properly, and I'm at a loss. Any help would be greatly appreciated. Ideally this could be done without the need for two different post types so it applies correctly to any twocolumnpost but the structure as is works too. Thanks!
Live sit is here: http://suburbia.comoj.com/wordpress/
There are several ways of resolving this issue, but it depends on what kind of users (and browsers) do you want to support. If you don't mind using modern standards (therefore leaving some users on legacy browsers behind), you can use the the calc property:
.twocolumnpost {
width: calc(50% - 10px);
padding: 10px 0px;
}
.twocolumnpost.left {
float: left;
}
.twocolumnpost.right {
float: right;
}
p/s: You don't need to declare the display: block property when you set floats — that's the default behavior for floats anyway.
Even better, you can take advantage of CSS flexbox, but you need to set the parent of .twocolumnpost to have flex display. Let's say the parent has the class name of .twocolumnpost-parent:
.twocolumnpost-parent {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
}
.twocolumnpost .post {
width: calc(50% - 10px);
}
You can see the proof-of-concept fiddle here: http://jsfiddle.net/teddyrised/DMy7r/
Update: On a related note, I have written a jQuery script to do the exact same, but with gallery images. Perhaps you can adapt it to your needs: Responsive Photosets. Not exactly relevant, but addresses the same issue that you are currently facing.
It could be just a white space issue.
You can either so something like have an html comment between your divs killing the whitespace or you can float the divs over. You might have to rework the containing elements to make sure the floats don't do crazy things. But floating the left and right columns (twocolumnpost) should have them flush against each other (unless there is padding/margin on them).
In short I think the gap is being created by the whitespace between the divs with the twocolumnpost class. If you float this two next to eachtoher or remove the whitespace you should be able to have them flush against each other.
Related
I have two post's next to each other on one of my pages. I have them take up the full width of the page. Although I got this to work, on the right the thumbnail has a small gap under it. This only happens on safari not on chrome. I have researched and found this gap could happen if you don't have you img tags on the same line. However, I am not using ing tags, I'm calling elements from wordpress. Does anyone have any other solutions on how to fix this? Can it be done through css? Thanks in advance.
safari, see how the bottom of the pictures don't line up
chrome, how I want it to look - bottom of pictures line up
fiddle with img tags instead of php - https://jsfiddle.net/v90pug4o/
although this is not completely similar to my problem I thought I would provide it in img tags since my code is in php. There is still a gap in the fiddle (its on the right side) its very noticeable when you compare it to this fiddle - https://jsfiddle.net/5bp0a3rf/ - where I put the img tags on the same line. However unfortunately I am not able to do this with my code since it's php. So thats why I was wondering if there are any other options?
<div class="food-featured-posts">
<div class="food-featured-posts-first">
<?php query_posts( 'p=185'); while (have_posts()): the_post(); ?>
<?php the_post_thumbnail(); ?>
</div>
<?php endwhile; ?>
<div class="food-featured-posts-second">
<?php query_posts( 'p=173'); while (have_posts()): the_post(); ?>
<?php the_post_thumbnail(); ?>
</div>
<?php endwhile; ?>
</div>
css
.food-featured-posts-first img {
width: 100%;
height:100%;
}
.food-featured-posts-second img {
width: 100%;
height:100%;
}
.food-featured-posts-first {
width: 50%;
}
.food-featured-posts-second {
width: 50%;
}
.food-featured-posts {
display: flex;
margin-bottom: 200px;
}
Am developing a WordPress site using the underscores theme and I just added a widget with contact info to my site with the following code:
<div class="topheader">
<div class="info">
<?php if( is_active_sidebar( 'info' ) ) : ?>
<?php dynamic_sidebar( 'info' ); ?>
<?php endif; ?>
</div>
</div>
CSS:
.topheader {
background-color:#e6e6e6;
}
.info {
max-width: 1280px;
}
The info is the first thing that I on the page. But I see that there is a space at the top and at the bottom where my slider is located.
How can I eliminate the existing margin that I see before and after the heading?
Cause at the moment I gap, then the widget, and after the widget there is another gap and only then the slider.
I am tried to setting the header margin to 0px, but it didn't really work.
Here a screenshot
How can I eliminate the existing margin that I see before and after the heading?
By heading do you mean an H3 tag by any chance? These are default in sidebars. You should just set margin-top:0 on the H3 tags in your sidebars, to get rid of any margin pushing your sidebar down.
To counter act this, I would then add some margin-bottom to the widget block to space them out a bit.
I think that's what you mean.. but it's hard to understand without any visual representation of what your problem is.
You have to set the start values in css like this:
body, html {
margin: 0;
padding: 0;
}
Otherwise please copy the whole Code of the page here. Open it in your browser, open the site Code and copy all.
Just inspect the element and test whats causing the margin. You can try this code. This might help. But not sure because your question is not clear enough to know your code.
*{
margin: 0;
padding: 0;
}
.top-header, .info {
margin: 0;
padding: 0;
}
Hello is there a simple way to align text inside span?
I found several solutions but nothing seems to work for me. Here is my code:
<?php echo Yii::t('default','Tax Amount').': ';?>
<span style="border-bottom: 1px solid; ">
<?php echo Yii::app()->locale->numberFormatter->formatCurrency($taxamount, 'EUR');?>
</span>
</span>
All I want is to align the $taxamount to the right and leave Tax Amount to the left as is. I thought it was pretty easy at first but nothing works! I also tried it with div and it worked but it messes with anything I have below that. I have three more echo’s like this below that code. I'm not very proficient with CSS and I would appreciate any help.
My full code is something like this:
<?php echo Yii::t('default','Amount').': ';?>
<span style="border-bottom: 1px solid;">
<?php echo Yii::app()->locale->numberFormatter->formatCurrency($model->credit, 'EUR');?>
</span>
<br>
<?php echo Yii::t('default','Tax').': 23%';?>
<br>
<?php echo Yii::t('default','Tax Amount').': ';?>
<span style="border-bottom: 1px solid; ">
<?php echo Yii::app()->locale->numberFormatter->formatCurrency($taxamount, 'EUR');?>
</span>
</span>
<br>
<?php echo Yii::t('default','Total').': ';?>
<span style="border-bottom: 1px solid;">
<?php echo Yii::app()->locale->numberFormatter->formatCurrency($total, 'EUR');?>
</span>
I comment out everything and I only used one solution as suggested below.
So my code now is like this:
p>span {
display: inline-block;
width: 50%;
}
p>span:last-child {
text-align: right;
}
.pull-left {
float: left;
}
.pull-right {
float: right;
}
<p><span>Tax Amount</span><span>EUR 12.50</span></p>
I use mpdf extension in Yii to print the results in pdf. So this is all my code now plus the mpdf extension.But still nothing happens!
A <span> is an inline element, the text align will work, but you'll need to give the element a width (which won't work, while its an inline element).
There are a few ways to do it, one is to display them as inline blocks inside a paragraph:
p>span {
display: inline-block;
width: 50%;
}
p>span:last-child {
text-align: right;
}
<p><span>Tax Amount</span><span>EUR 12.50</span></p>
Another way is to float them: (but I personally prefer the first method)
p>span {
display: block;
float: left;
width: 50%;
}
p>span:last-child {
text-align: right;
float: right;
}
<p><span>Tax Amount</span><span>EUR 12.50</span></p>
If your left-aligned text is inside another element (like my <div> below), you should be able to add the 'float:right' CSS style to your <span>.
<div>
Left-hand text <span style="float:right">Right-hand text</span>
</div>
float is typically used for images, but it can be used with span tags. It works by literally floating your <span> tag to the right edge of your containing element.
This should give you the behavior you're looking for, but you can also check out this question. It looks like they're trying to accomplish something similar.
At the bottom of this page I have a media gallery. The first three photos are the photo gallery, Inlined after it I placed some video thumbnails. For some reason the alignment of each element of the video gallery is messed up. Can you help me?
This is the HTML of each video thumbnail:
<?php if((get_post_meta($post->ID, 'url_video3', true))) { ?>
<div class="video_container">
<a href="#TB_inline?inlineId=url_video3&width=600&height=400" class="thickbox video">
<?php $attachment_id = get_field('icona_video3'); echo wp_get_attachment_image( $attachment_id, icona); ?>
<div class="play-icona"><img src="<?php bloginfo('template_url'); ?>/images/video_link.png" /></div>
</a>
</div>
<?php } ?>
And this is the CSS:
.thickbox.video {
text-decoration: none !important;
width: 96px !important;
height: 96px !important;
}
.video_container {
position: relative;
display: inline-block;
height: 96px !important;
width: 96px !important;
margin: 0 !important;
padding: 0 !important;
}
.play-icona {
position:absolute;
left:35%;
top:35%;
}
Generally speaking, inline-block elements respect surrounding whitespace (following the standard whitespace collapsing rules). If rendering an element with inline-block causes noticeable gaps around the element, make sure the two elements in HTML are right up against one another — if there are any newlines or spaces, they'll get translated into a gap by the web browser.
Hay all im building a news aggregator with SimplePie, the SP elements are working fine but I would like to have the feeds that it pulls in displayed in columns across the page using HTML5 and CSS3. I have managed to implement it so that the columns are formed and display the feeds, but at the moment the stories are being ordered one on to of the other from left to right with the newest being displayed top left, the second newest bellow the first in column one and so on. What I would like is for the stories to be displayed from left to right across the column so that the newest is at the top of the first column, the second newest at the top of the second column, the third newest in the third column and so on.
The code that Im using at the moment is as follows:
<div id="page-wrap">
<?php if ($feed->error): ?>
<p><?php echo $feed->error; ?></p>
<?php endif; ?>
<?php foreach ($feed->get_items() as $item): ?>
<div class="chunk">
<h4 style="background:url(<?php $feed = $item->get_feed(); echo $feed->get_favicon(); ?>) no-repeat; text-indent: 25px; margin: 0 0 10px;"><?php echo $item->get_title(); ?></h4>
<p class="footnote">Source: <?php $feed = $item->get_feed(); echo $feed->get_title(); ?> | <?php echo $item->get_date('j M Y | g:i a T'); ?></p>
</div>
<?php endforeach; ?>
And this CSS:
#page-wrap {
width: 100%;
margin: 25px auto;
height:400px;
text-align: justify;
-moz-column-count: 3;
-moz-column-gap: 1.5em;
-moz-column-rule: 1px solid #c4c8cc;
-webkit-column-count: 3;
-webkit-column-gap: 1.5em;
-webkit-column-rule: 1px solid #c4c8cc;
}
If anyone could help me out with this that would be great.
You're trying to make CSS3 columns behave like normal divs, this will bloat your css code and make it difficult to maintain. But you want an answer, not a lecture semantics, so the solution is:
h4 {
-moz-column-break-before : always;
-webkit-column-break-before : always;
}
Then you don't need columns. You juste put the links one after the other.
One solution would be to set the width of the elements that contain the elements and have a float: left;. Then you make sure that every three elements (for examples), you go to the next line.
There might be other examples.