Hiển thị các bài đăng có nhãn Template editing. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Template editing. Hiển thị tất cả bài đăng

Thứ Ba, 28 tháng 5, 2019

Adding a separator line between your posts

This article shows how to put a horizontal separator line between posts in your blog, using either HTML's line command, or CSS rules.  It also has suggestions about ways of formatting these lines using different colours and line-styles.




There are at least four approaches to choose from if you want to put a divider between your posts in Blogger.  These days, I prefer the CSS-rule approach, because it's so easy and flexible.  But I've shown details of a few other methods too:
  • Manually add a horizontal line command to each post
  • Use the post-footer colour block as a line (in Designer templates only)
  • Add the HTML command for a line to the main section of your template, in one of the post-footers
  • Add a top or bottom-border to the CSS rule that formats the body of your posts.
The following sections give more detail about each option, including how to apply them to your blog, and their advantages and disadvantages.


Manually add a line to each post

When you are editing a post, you can put a horizontal line anywhere in the contents.

In the post-editor:

  • If  Post options > Compose Settings is set to  Interpret typed HTML, then you can just type <hr />, and Blogger will place a line like this in your post.


  • If  Post options > Compose Settings is set to  Show HTML literally, then you need to switch to the HTML tab before you type <hr />.


Disadvantage: If your post is set to display comments, or the blog is set to show the author, labels etc under the post, these items will be underneath any line that you add manually to a post.


Designer Theme - post footer colour

If your blog has a designer theme (ref, What sort of theme have I got), then the Theme Designer > Advanced tab may have an option for setting the background colour of the post-footer (depending on which theme you are using).



If you use a dark colour (or have a dark background and use a light color), this makes the post-footer look like a line.

Disadvantage:  The "line" might be a bit thicker than you like.   And if your post is set to display comments, or the blog is set to show the author, labels etc under the post, these items are shown right inside the footer line.





Add a line-command to your theme

If you don't like the other two approaches, you can change your theme to add a horizontal line.  To do this:

Edit your blog's theme in the usual way.

Most themes have three footer lines:  what is in each one depends on the theme, and how you have arranged the items in the Layout > Blog Posts editor.  Look at the theme for code like this:
       <div class='post-footer-line post-footer-line-2'><span class='post-labels'>
        <b:if cond='data:post.labels'>
          <data:postLabelsLabel/>
          <b:loop values='data:post.labels' var='label'>
            <a expr:href='data:label.url' rel='tag'><data:label.name/></a><b:if cond='data:label.isLast != &quot;true&quot;'>,</b:if>
          </b:loop>
        </b:if>
      </span> </div>
OR
 <div class='post-footer-line post-footer-line-3'/>
    </div>

Add the <hr /> command to which ever of the footer-lines you want it in, for example
 <div class='post-footer-line post-footer-line-3'/>
<hr />

    </div>

Advantage:  you can easily place the divider line anywhere you want it, relative to the other items in your post-footer.


Disadvantage:  you need to modify your theme, and this does have some risks.  And it does use the <hr /> tag which some people (CSS purists) suggest is not a good idea.



Enhancements to the basic <hr /> command

There are lots of ways you can modify the <hr / > code.   For example

<hr style="text-align: left;" /> -  to left-align it

<hr style="color: red;" /> -  to change the colour
<hr style="width: 50%;" /> -  to make it narrower

See w3c.schools <hr /> tag for more information. 



Add a border to the CSS rule that formats your posts

The cascading-style-sheet rules in your theme control most aspects of how your blog looks.   They can be a very powerful way to control how your blog looks - and give a quick way to add a line between your posts.

What to do

If you have a designer template, then the quick way to make this change is to add a CSS rule to your theme.  The rule code to add is:
.post-body
{
border-bottom:1px dotted #666666;
}

or this one if you want the border at the top of each post:
.post-body
{
border-top:1px dotted #666666;
}

Making more complex changes

The CSS rule that controls how the "body" of your posts look is .post-body.   To make changes to it:

1 Edit your theme in the usual way.

3 Look for .post-body in the rules section . It will look something like this, but  the exact lines and values may be different:
.post-body {
margin-top: 0;
margin-$endSide: 2px;
margin-bottom: 0;
margin-$startSide: 3px;
}
 4  If you can find a .post-body rule, then add this line, just before the } character.
border-bottom:1px dotted #666666;
5    If you cannot find a  .post-body statement in the rules section of your template, then you need to add it.

Put it somewhere:
After    <b:skin><![CDATA[/*

Before  ]]></b:skin>

But not in the middle of any other rules: look at how the rest of that section of your template is laid out for clues.

The statement to add is something like the following, though you may want to try out different values for parts of it.:
.post-body {
border-bottom:1px dotted #666666;
margin-top: 0;
margin-$endSide: 2px;
margin-bottom: 0;
margin-$startSide: 3px;
padding-top:10px;
margin-top:20px;
}


Alternative formats

The #666666 means draw the line in black - you may like to use a different colour, or use the word "solid" instead of "dotted" to make a firmer looking line.

As an alternative, you can say border-top:1px dotted #666666; - this puts a line at the top of the body of each post, just underneath the title.



Related Articles


What sort of theme have I got

Disadvantages of editing your blog's theme

Adding a new CSS rules to your theme

Centering the Post-title or Page-title

Putting HTML from elsewhere into your blog.

Thứ Hai, 17 tháng 10, 2016

Lining up the first post and the sidebar

In some Blogger themes, there is a big gap between the bottom of the header and the start of the first post, which means that the posts and the sidebar are not aligned.  This article explains how to adjust the gap, and so remove the problem.





In the themes that Blogger provides, as well as all third-party themes, the amount of space between elements on the screen is not accidental:   designers put a lot of effort into working out what spacing will look good, and then finding ways to put CSS code into the template so that the spacing they want is shown in any browser software that Blogger supports.

But there are times when you may want to change this spacing, and this is easy to do, provided you are willing to accept the disadvantages of editing your theme, and if  you can work out exactly which part of the template code to change.


The pre-Header gap

A pet-hate of mine is the blank space above the first post in many Designer themes, which looks strange unless you put something else in to the space.  In the example below, there is an AdSense link-unit in the area highlighted in red, just to fill in the empty space:




How to change the gap above the post header in Designer themes

1  Edit your theme  in the usual way.

2  Find this code
h3.post-title, .comments h4 {
  font: $(post.title.font);
  margin: .75em 0 0;
}
The exact numbers used in your template may be different:  the key thing is to find the CSS command that is putting a margin above the post header.  In the template that I took this example from (Simple), it's the "0.75em" - which puts 75% of the space of a the post-header characters as a blank space above the header.


3   Change the first margin value to get the result you want
How much to change it by depends on your template, but in some cases I've used 0 successfully.

What the numbers mean
In CSS, when a margin statement has three numbers beside it, they refer to the
  • top, 
  • left-and-right, 
  • bottom 
margins respectively.   So if you want to do something else to the post-header, eg indent it, this is the place to make changes


4   Click Preview to see what the blog will look like - keep doing this until you get the right setting.


5   When you are happy with the spacing, click Save Theme to apply the changes to your blog.   (Or Clear Edits if you cannot get it right and need to stop trying).


Note:  If you make a big change to your theme, it's a good idea to check out out in at least one version of the other browsers that your readers use - usually means current versions of Internet Explorer, Firefox and Chrome.   But it may depend on your niche - a tool like Google Analytics will give you some statistics about what browsers, and screen sizes, your visitors have.

Also, it is possible to make this change by just installing a new CSS rule for h3.post-title into your blog - because the latest one found is always the one used, and because the template designer's Add CSS function puts the rules you add after the othr rules.   I don't recommend it here, though, because working with the original rule makes it easier to see the effect of making changes to any of the values in the area.


Other affected spacing

If you have more than one post per page, then this change will also reduce the amount of space between the bottom of one post and the header of the next one.   Depending on your theme, you want want to add a little more space into the margin statement in the bottom of the post-footer, eg
.post-footer {
  margin: 20px -2px 20;
  padding: 5px 10px;
}

If you display comments in your blog, you also need to check the impact on comments, because the original command applied to h4 items in comments as well.

If you are making a lot of changes, you may want to make a test blog, and plan your changes in private before applying them to your main blog.




Related Articles

Setting up Google Analytics to get statistics about for your visitors

Adding a new CSS rule to your blog's theme

Advantages and disadvantages of editing your theme

How to edit your blogger theme

Who did your blogger theme come from - the quick way of finding out

Making a test-blog for template changes

Planning changes to your blog in private

Thứ Ba, 29 tháng 9, 2015

How to centre-align the sharing-icons from AddThis in Blogger

This article shows how to get and then centre-align the row of sharing items that you can get from AddThis (and it's likely that a similar technique applies to sharing buttons from other services like ShareThis, too).



If you think that Blogger's own social sharing buttons a just a bit too small and difficult position, then you may decide to use a service like AddThis to generate buttons that are more elegant all round.

Signing up with AddThis is easy: just log in to your Blogger account, and in a separate tab open up AddThis.com. Choose Create Account, and then Continue with Google. This links your Google account and your AddThis account, and is the easiest approach - but there are other options too, like creating your account with your Facebook or Twitter accounts, or even just signing up the old fashioned way with your email address.

Once you have signed up and chosen a plan (personally I just the free "Basic" plan), you need to actually install the AddThis buttons on your site. To do this:
  • Select one or more sets of sharing buttons (from the options available to your account type),
  • Choose the settings which apply to that set of buttons
  • Choose Activate (button in the bottom right corner of the setting screen), and
  • Install the code that AddThis gave you into your blog.

Installing the code that AddThis gave you is pretty much like installing any other piece of code.   Typically the code you have to install has two parts:

For the piece that says:
Step 1: Add the following code to the <body> of your website.
Search for "<body"  (note:  no closing angle-bracket because some templates have extra instructions in there), and then put the code from AddThis after the angle bracket that goes with the <body


For the piece that says:
Step 2: Paste this code into whichever page you would like this tool to show up.
Find the location in your template that you would like the gadget (eg an HTM gadget, or inside the post statement itself - read more about the options), and copy and paste the relevant code from AddThis.




But it's not in the right place.

If you install the code as is from AddThis, you will find that the row of sharing buttons is pretty tightly linked up with the rest of the page, and left-aligned.   Fortunately this is easy to change.


How to centre (or right align) rows of buttons from AddThis 

To put the set of sharing buttons from AddThis at the middle of the page, you need to surround the 2nd piece of code from AddThis with another Div statement, like the one in bold below:
<div style = 'width:100%; text-align: center; margin-bottom:3em; margin-top:2em;'><!-- Go to www.addthis.com/dashboard to customize your tools -->
<div class="addthis_sharing_toolbox"></div>
</div>
The exact details to use depend on how exactly you want to set up your sharing-bar form AddThis.  I wanted it to be centre-aligned on one of my sites, with some extra white space above and below, so I used these commands:

  • width:100%  -  says to use all of the page-width in deciding where to put the sharing bar  (by detfault, it would just use the width of the sharing bar itself
  • text-align: centre   -   means that he bar will be put in the middle
  • margin-bottom and margin-top   put some extra space above and below the gadget, so it sticks out more-so.


But you may use a different approach, depending on what your blog is trying to achieve.

What your readers see

Visitors using a web-browsers

Will see your AddThis buttons, as you defined them

Readers who subscribe to your blog's RSS feed

Will not see your blog's AddThis sharing buttons, unless they happen to click through from their feed-reader to your blog.

Readers who follow-by-email 

Will not see your standard social sharing buttons at all, unless they visit your site.   (AddThis does have some email newsletter buttons, but these don't automatically go into emails generated from Blogger).


Is it worth it?

For what it's worth, I recently made the change from custom sharing buttons that I'd made myself to classier looking ones from AddThis, and saw quite a jump (50% or more) in the number of social shares, across all my sites.

YMMY, of course.



Related Articles

Installing 3rd party code into Blogger

Using Div statements to control layout

Thứ Tư, 10 tháng 4, 2013

How to tick the "expand widgets" checkbox in Blogger's new template editor

This QuickTip is about finding the "expand widgets" option in Blogger's template editor.



Today, Blogger Buzz announced a new version of the template editor.

This is exciting in all sorts of ways, including that it implies that Blogger will continue to support template editing:   some people suspected that Dynamic Templates, which don't allow template editing, might be the way of the future.

But there's one immediate issue: many of the existing "How to do XXXX in Blogger" tutorials include statements like
Open your template for editing, and tick the "Expand widgets" checkbox

or

Open your template for editing, and make sure that "Expand widgets" isn't ticked


However today's changes have deleted the Expand Widgets checkbox.

So - what do you do if you need to expand the widgets?   Luckily, this is one of the things that has been made easier, once you find out where the option has moved to.


How to see expanded code for a gadget / widget


The equivalent of ticking the "expand" check-box is to:


1)    Find the gadgetID in the usual way.


2)   Open the template for editing, and find the reference to the widget / gadgetID in the code
(Either using the browser's find feature - or  the "Jump to Widget" feature that is now in the post editor.)


3)    Click on the fold marker for that gadget.
This is the horizontal arrow ( ? ) which is in the very left side of the editing window on the same line as the gadget name.

Clicking it turns the sideways arrow into a down-arrow, and shows you the code that's included in that gadget - or at least as much of it as Blogger is going to let you see.




To un-tick the expand check-widgets checkbox, just make sure that all the fold-arrows are horizontal. (they work as toggles - clicking them changes them from one expanded to contracted, or vice versa).


What else has changed?

I'll be updating Blogger-HAT's main "How to edit your Blogger template" article soon - this is just a quick heads-up to start with.

If you've found any more features of the new template editor that you like (or don't) or which need more explanation then drop a comment below and I'll see what I can do.