Category Archives: CSS

Elegant CSS Borders

This weeks Tidy tutorial is going to look at borders. Adding a little flair to a border can really add something extra to the feel of a website.

We’ve recently started working with a client with whose target audience is middle aged and older women, we wanted to give this website an elegant feeling, and we think we’ve achieved just that with additions such as these borders we’re going to talk about today.

This is a nice and quick tutorial, and we know you like that, you don’t always need to write lines upon lines of CSS to get great effects. So let’s jump in! We’ll start with the HTML markup needed:

That’s all we need, a simple div with the class of ‘border’ wrapped in a container. We’re placing it a container so we can make this box responsive and add some padding to stop it hitting the sides of the page. The initial styling will look a little something like this:

.container {
	padding: 2em;
}
.border {
	position: relative;
	width: 100%;
	max-width: 550px;
	height: 340px;
	/* We're picking out a colour from the background image we're using but you can pick any colour */
	background-color: #ccaeb9;
}

Here’s what you should be seeing, bear in mind we’ve got a couple of extra generic styles here but the fundamentals will be the same:

We’ll make the start on the borders themselves now, to get this effect we’re going to make use of the before and after pseudo elements. Targeting both before and after first for the generic styles this is what we’ll need:

.border::before,
.border::after {
	content: '';
	position: absolute;
	border: solid 2px #ccaeb9;
}

After this change we aren’t going to see a difference, it’ll look exactly the same until we target the pseudo elements separately to do the positioning of each border. Before we get to the next step make sure the ‘.border’ is set to position relative and that you’ve got some box-sizing styles set up like this:

*, ::after, ::before {
    box-sizing: border-box;
}

Now moving back to the borders, let’s start with the before:

.border::before {
	left: -20px;
	width: calc(100% + 40px);
	height: 100%;
}

Before we break it down, here’s what you should be seeing:

Right, now let’s look at that CSS block. Starting with the height, this is clear, we want the height of the border to be exactly that of the box. The width, we want 20px each side of the box for the overlapping border style, we do this in a way which can stay responsive. Using calc we add the overflow of the box to the 100% width. Now to finish the before section off we use left to move the border left, giving each side an equal space around the box. Another way this can be visualised is like this:

.border::before {
	height: 100%;
	width: calc(100% + (space on the left side desired + space on the right side desired));
	left: - space on the left side desired;
}

The after is going to look similar to above, but the width and height is going to be reversed:

.border::after {
	top: -20px;
	width: 100%;
	height: calc(100% + 40px);
}

The opposite effect should be given here, looking like this:

And that’s it, nice and simple here. Playing with pixels added to the 100% in the calc and also the left we can make the spacing of the borders around the box smaller and larger. I’m sure you can also think of ways to make this look even better with hover animations too! Have a play around on the Pen and share what you make.

codepen.io/TidyDesign/pen/qMMBoL/

Thanks for reading, catch you again soon.

Luke

Curtain Mobile Nav

Today’s Tidy Tutorial is going to look at a take on a mobile nav, showcasing a curtain style open and close animation with fading nav links.

We’ve got a couple of elements here that are pretty standard and won’t be covered but you can check the Pen to see these (mainly the nav toggles). Before we jump into the nitty-gritty let’s look at the setup…

A FREE Mobile Nav Tutorial

We’re going to need a HTML structure of the nav, it’s going to look a little like this:

There’s nothing out of the ordinary here, looking at the above code block it’s a pretty standard structure. The only item which could be considered an oddity is the toggle bars being the first nav item – this is purely for some automatically calculated spacing for the closing toggle. Now we just need some initial styling:

This first CSS block will place the nav above the page’s content when we’re ready to show it. Also you’ll see the comment above the ‘height’ declaration, we’re placing this here so we can style the nav. We will need to take this away to hide the nav, but first, before we completely hide the nav we need to write a quick fix to space out the close toggle bar properly and move onto some styling:

Nothing complex here, it just places the cross to the left and moves it into the centre of the li. The reason it originally seems out of line is due to the transforms moving the spans into the cross shape. To see how we’ve created to toggles please see the Codepen Pen of this tutorial.

Everything is quite squished right now, so we need to make the ul the same height as the nav and also space out the links:

Here we’re using the beauty of flex to automatically evenly space out the links, flex direction states we want the links in a column. If you’re unsure on any of the styles around flex then check this post from CSS Tricks, everything you’ll need to know will be covered: css-tricks.com/snippets/css/a-guide-to-flexbox/

Time to add in the curtain effects styles, we’re going to use pseudo elements. We’ll start by creating both and move the positioning of each after:

You’re going to see a rectangle now that takes up half of the page…

::before is our left “curtain”, ::after will be the right. We need to move the ::after pseudo element to the right side. We will do this with the following style:

Now your whole screen should be covered by the “curtains”. These need to be hidden off screen though so they can be animated in later:

Simple transforms are how we do this, adding a minus to the ::before’s style to move this to the left.

Now the majority of styles have been completed but before we move on we need to hide the nav when we don’t need it. A simple few lines will do this:

On our page we should just see the hamburger and whatever other content we’ve placed on the page, for us just a header:

Next we’re going to need to add the only JS side to this tutorial, a simple class added to the nav element will be what triggers the opening and closing of the nav. We just need one event listener which is going to toggle the class, it doesn’t get much simpler than this:

That’s the JS done, everything else is going to run through CSS. All the styles which deal with the open nav are going to be prefaced with ‘.nav-open’. Starting with these following few styles we make it so the mobile nav is able to be opened, the page once you click on the nav toggle will be covered by the “curtain” elements.

Two problems here though – first, we’re stuck here; we’ve not shown the links so you can’t go back. Second, the curtain elements jumped in rather than animated in. Let’s fix the latter first:

You can tweak this style however you like, the timings can make a big difference but the biggest impact can be made through the timing function, we’re using ease-out but play around with other standard timings and even try creating your own cubic bezier (here’s a great site for helping you create your own cubic-bezier.com).

This is where things get a little finicky, if you were to close the nav now you’ll see the whole thing instantly disappears. This is down to the measures taken to completely hide the nav when it’s not in use. To fix this we have to get creative with transitions:

Toggle between the open and closed state now and you’ll see the curtain elements open and close properly. Once the curtains move in we can tackle the links, currently they show and hide instantly, we want these to appear after the curtains have shown.

We’ll start by getting the nav links to show once the curtains have closed, to do this is pretty similar to the above, on the ‘.nav-item’ class we set the transition duration and delay. The delay needs to be set for longer than the curtains’ transition duration:

The reason we’re breaking out the transition declarations into their long form is so we can override them individually. Also as mentioned above, setting the delay on the nav-open class means we can provide different times for both the opening and closing sections of this transitions. We want the nav items to fade out first on the closing – to do this we’ll set the transition delay to 0 on the just the ‘.nav-item’ class:

We’re nearly there! We just need a few final tweaks. The first one to tackle is getting the curtains to transition out after the links have faded out. We need to add the delay onto the nav before and afters, also adding a delay to the nav-open before and after of 0s to keep the curtains opening first on the initial menu opening:

The very last bits run of the same ideas as the previous couple of CSS code blocks, we need to update the time on the nav elements’ transition duration to the total time of the closing transition. This is the nav pseudo elements’ transition duration (.5s) + nav links’ transition duration (.5s) + transition delay difference (.15) which equals 1.15s.

Finally let’s do the double transition timing trick to get the padding of the main nav to visible as soon as the nav opens and be removed once the links fade out – this stops a glitchy looking jump. The reason it’s added after is to help make the nav hide completely, if we were to use display none on the container then the children (nav items) would lose their ability to transition their opacity. The last code block is:

There we have it, a completed mobile curtain like navigation. There’re a few quirks of CSS to overcome along the way but the final product is worthy of that extra effort. Have a play around with the styles in the Pen and see what you can come up with!

codepen.io/TidyDesign/pen/gdvqPp/

Thank you for reading, we hope you enjoyed this FREE mobile nav tutorial, until next time!

Luke

Creating a Responsive SVG Overlay

Today I’m going to show you a way to change up the standard straight lines below your header images, we’re going to use a wave in this tutorial but any shapes you like will be suitable.

This process is done by creating an SVG and placing this into the HTML file below your header> (or whatever container you’d like). I’ll be using Figma to create my SVG overlay, but you can use any SVG editor to achieve these results, just note that some steps may be slightly different. There’s a couple other SVG editors you can choose from if you haven’t got Figma (a free piece of software), one being Adobe Illustrator and another the free editor InkScape. Now we’re sorted on what we’ll need to continue, let’s jump in!

I’ve placed in a background image on the pages to replicate a header area, this is purely to keep a nice visual representation of how it’ll look once live. The first step will be to place a rectangle on top the header image, let’s put this at the bottom of the image. I made the rectangle 6px high choosing a bright red to help it stand out. I also added some guidelines to visually separate the page into 3 sections.

From here you’ll need to double click the red rectangle, you should now see diagonal lines over the shape when hovered over. With that done move up to the toolbar at the top and select the pen tool.

Zoom into the first of the guidelines and click on the intersect between the guideline and the top of the rectangle, make sure to hit the escape key to create just one single point. Scroll along and do the same on the second guideline.

Before you zoom out head all the way to the right, use the move/select tool and drag the top right point of the rectangle up 10px – 15px.

Now zoom back out and you should see something similar to this…

Still using the move/select tool grab the point on the first guideline and drag it up in straight line. How high you drag this up determines how big your wave will be.

This next step is where we’ll see the curve of the wave taking shape. Double click on the red shape and move up to the toolbar in the top left to select the bend tool. The next step is to click on the two points over the guidelines…

Simple, right? Now you’ve got a crisp wave like topped rectangle, we just need to export it to be used on the web. With the wave selected look to the sidebar on the right of the page, the last option you should see under the Design tab is Export, select SVG from the drop down, hit export and now it’s saved ready for use.

Here’s the SVG code I’m left with, you should see something similar:

We just need to make a couple of changes to this, one so we can easily refer to it and the other to help make it responsive. These changes are only on the first line, we need to add an ID and also remove both the width and height attributes (the fill attribute is unnecessary and can go too):

Right! We’re ready to get to the code now… We’re going to need a header tag with a background image, and a container for our SVG code:

The container is needed to keep the SVG to the right aspect ratio, without it you’ll be able to get the SVG to be as wide as the container but it’ll also take up the height of the container. So paste in the SVG code into the container and we’re a handful of CSS lines away from completing this. First, we need to make the header tag position relative, and add the following styles to the SVG container:

#svg-container {
	position: absolute;
	bottom: 0;
	width: 100%;
	height: 0;
}

You’re probably thinking “I’m not seeing the SVG!”, the last piece to finish this off is taking advantage of the old padding bottom trick. We need to calculate the aspect ratio, a simple formula by multiplying the percentage width by the viewBox height, divided by the viewBox width. Let’s break that down, our percentage width, as we want it to be full screen, is 100%, our viewBox is ‘viewBox=”0 0 1440 45″‘ therefore the CSS value will be: padding-bottom: calc(100% * 45 / 1400);

Change the values to what yours needs to be a boom! Now you’ll see the wave sat perfectly at the bottom of the header. If you want to see a live example, please see this Codepen Pen;

https://codepen.io/TidyDesign/pen/xaPVoR

Luke

Creating a Cut Out Text Effect

Before we start, there’s a couple of small caveats to this incredibly visually pleasing (and simple) CSS trick, but don’t let that put you off!

First of all, there’s only two colours that this trick correctly works with – white on black, and black on white. The second of these caveats is browser support, it’s not available on all browsers, but it’s natural fallback is actually a perfectly suitable mid-ground. The blend mode stops working and you’re left with either black text on a white background, or white text on a black background, still completely legible and not out of the ordinary to see on the web. Check here to see where it will and won’t work – https://caniuse.com/#feat=css-mixblendmode.

Now, on to the trick itself…

This trick relies on mix-blend-mode. Simply put, the mix-blend-mode style describes how an element’s content should blend with the content of the element’s direct parent and the element’s background. There’s many different mix-blend-mode options, but the two we are using today will be ‘multiply’ and ‘screen’.

As I’m sure you’ll already know the majority of the CSS used to create this set up I won’t bloat out the examples with unnecessary code, but there’s a CodePen you can view which holds all of the CSS used https://codepen.io/TidyDesign.

We will start with black text on a white background. So create a h1 element and let’s give this a background colour of white, and a colour of black.

h1.cutout {
	background: white;
	color: black;
}


With this set up we can add the magic…

h1.cutout {
	background: white;
	color: black;
	mix-blend-mode: screen;
}

How simple is that, 3 lines of code and we’ve got a great cut out text effect!

Now, if you want to switch the colours to be white on black all we have to do is change these three styles. Swap over the colour and background values and change ‘mix-blend-mode: screen;’ to ‘mix-blend-mode: multiply;’.

That’s all, who doesn’t like effects this striking which are so easy to create! CSS is full of little secrets like this, try playing around with the colours and blend modes in the Pen to see what other things you can create…

https://codepen.io/TidyDesign/pen/aamweL/

Thank you for reading

Luke

CSS Rotate

The CSS transform property has many different outcomes: skew, rotate, scale, translate etc. Today we are going to focus on the rotate effect, showing how it is used and an example of its use.

We are going to rotate an image 360 degree on hover to demonstrate its effect. A basic page has been set up with the image in the centre:

css-rotate

To rotate the image on hover we will need to add this code to our IMG styling in our CSS. For convenience my styling is in the head but note styling should go in an external CSS file. Below is my styling for the image above.

img{
display: block;
width:500px;
height: auto;
margin: 100px auto 0;
}

Rotating the image is actually pretty simple and requires two extra pieces of CSS styling. The first is to add the :hover pseudo class to our img tag. Once we have this in place we can add the transform style. See below:

img:hover{
-ms-transform: rotate(360deg);
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-o-transform: rotate(360deg);
transform: rotate(360deg);
}

I have included all browser prefixes: Chrome, IE, Firefox, Opera, to ensure it functions on the up to date browsers. As you can see the transform property itself takes different styles and rotate is one of them. The rotate style uses degrees to move an element, 360deg as shown above rotates the element around once.

The final property that needs to be inserted is the transition property. This allows us to see the element rotate. Without it there would be no smooth transition from one state to the next. See below:

img{
display: block;
width:500px;
height: auto;
margin: 200px auto 0;
-ms-transition:all 500ms linear;
-webkit-transition:all 500ms linear;
-moz-transition:all 500ms linear;
-o-transition:all 500ms linear;
transition:all 500ms linear;
}

We have added to our previous code above and again included the vendor prefixes. Check it out in your browser and see how it works. Cool effects and styling can be accomplished with the transform property. No need to add hover effects and instead can have more than just vertical and horizontal lines on a page… Preview CSS Rotate

Blayne Phillips

Media Queries and Responsive Web Design

Today, increasing numbers of visitors to company websites are choosing to access them via devices such as smartphones and tablets in contrast to desktop computers.

responsive web design

Naturally, users expect to be able to browse web pages just as effectively on their mobile device as they did on their desktop computers.

Creating a highly responsive website, fully optimized to ensure access via mobile phones and tablets as well as desktop resolutions is a key consideration for all businesses whatever their size or sector.

As technology evolves, the latest screen resolutions offer exciting possibilities for web design.

Media queries are the means by which it is possible to deliver different styles to different devices. The aim is to ensure that users have the best possible experience of your company’s website.

CSS3 media queries allow gathering of data about a visitors device, which in turn is employed to apply relevant CSS styles. This allows for adjustment of layouts to perfectly match the width and spec of the device employed to access the web. Creating highly responsive web design requires a shift in perspective. As changes in screen resolution impact on the world of web design, smartphones and tablets provide new ways to utilize the very latest techniques.

Rescaling and image resolution are key considerations in mobile responsive web design, with the focus on presenting a company’s online presence in a way that is both practical and highly adaptive to the method employed by a user to access it.

Technologies such as fluid grids can have an important role to play in responsive design technology too.

If you are keen to find out more about how to ensure that your business’ website is fully mobile responsive, why not contact us today to find out more about all we have to offer you? We look forward to hearing from you.

Kerry McPhail

How to preload images using just CSS

In mid-January we started work on website re-design, part of the spec was to create a fun and colourful navigation that offered something different… So, following a couple of design concepts we had a design and idea signed off. All was looking and working well until I noticed one of several .png files that makeup the navigation took longer than others to load! From a website usability perspective it was one of those Arrr moments!

I asked the question, “How can I preload an image using just CSS?” Well, website browsers load information within a webpage from top to bottom… So by adding:

<div style=”display:none;”>
<img src=”../images/preload-me-first.png” width=”200″ height=”50″ />
</div>

to the top of your web page, the browser will load ‘preload-me-first.png’ (into your computers memory) before information at the bottom of your page… By placing the above code just after the <body> tag you will guarantee to preload an image(s) using just CSS… Finally, it is also worth setting the width and height attributes to add a little extra speed.

So there you have it, how to preload an image using just CSS… Enjoy!

Hiding DIVS with CSS

This tutorial will show you how to create a DIV, add some tidy CSS and Java Script to create a hidden area on your webpage! Here you could add some promotional offers or extra content for your readers. (To see this code in action please click on the two blue raindrops on our Tidy Design homepage, enjoy!)

So step one is the Java Script, this can be pasted into the header section of your webpage:

<script type=”text/javascript”>
$(document).ready(function(){
$(“.btn-slide”).click(function(){
$(“#panel”).slideToggle(“slow”);
$(this).toggleClass(“active”); return false;
});  
});
</script>

You will also need to link to a jQuery file such as:

<script type=”text/javascript” src=”http://www.tidydesign.com/jquery.js”></script>

Now you have the above in place please locate an area on your webpage that you would like to add this tidy effect. You will then need to create the hidden DIV

<div id=”panel”>
Tidy Web Content
</div>

And create a text link that will open it, making content visible to the reader.

<a href=”#”>Click here to view Tidy Web Content</a>

Now the fun / creative bit, lets add some tidy CSS to the panel and btn-slide.

#panel {
background: #333;
height: 250px;
display: none;
text-align: center;
color:#FFF;
}
.btn-slide {
background-color: ebebeb;
text-align: center;
width: 200px;
padding: 10px;
margin: 0 auto;
display: block;
text-decoration:none;
color: #666;
border: 2px solid #B5B5B5;
}

Now you have all the components in place your webpage with ‘hidden DIV’ should something like the following… Please click here to download a sample page.

How to put text into a Transparent Box using CSS

Step one of this tidy tutorial is creating a div element (class=”background”) with a fixed height and width, a background image, and a border.

div.background
{
width:730px;
height:400px;
background:url(bg.jpg) repeat;
border:5px solid #CCC;
}

Then we create a smaller div (class=”transbox”) inside the first.

div.transbox
{
width:620px;
height:200px;
margin:30px 50px;
background-color:#000;
border:1px solid black;

In addition we need to make this div transparent.

div.transbox
{
width:620px;
height:200px;
margin:30px 50px;
background-color:#000;
border:1px solid black;
/* for IE */
filter:alpha(opacity=60);
/* CSS3 standard */
opacity:0.6;
}

Inside the transparent div, we add some text inside a p element.

div.transbox p
{
margin:30px 40px;
font-weight:bold;
color:#fff;
}

So your page should look something like:

<html>
<head>
<style type=”text/css”>
div.background
{
width:730px;
height:400px;
background:url(bg.jpg) repeat;
border:5px solid #CCC;
}
div.transbox
{
width:620px;
height:200px;
margin:30px 50px;
background-color:#000;
border:1px solid black;
/* for IE */
filter:alpha(opacity=60);
/* CSS3 standard */
opacity:0.6;
}
div.transbox p
{
margin:30px 40px;
font-weight:bold;
color:#fff;
}
</style>
</head>
<body>
<div>
<div>
<p>Tidy text in here…
</div>
</div>
</body>
</html>

Download sample

Create unique and accurate page titles to boost search results

Your title tag tells both users and search engines such as Google what the topic of a particular web page is about. The <title> tag should be placed within the <head> tag of your HTML document and you should create a unique title for each page on your site.

<title>Plot Of Land For Sale in the UK | Investing in Plots of Land | Agricultural and GreenField Land Investment</title>

The title above is from the homepage of our land investment website, you will see it lists the business name and main focus areas.

If your webpage appears in the search engine results page, the contents of the title tag will usually appear as the first line of the results. If you are looking to attract visitors and not cheese off the search engines then please don’t spam keywords! Keep each title relevant to the page and avoid unneeded or repeated keywords.