Categories: WordPress Snippets

Expanding a div beyond its container to be full width of page

Sometimes its necessary to break a div out of its container and make it full width of the page which luckily we can do using a bit of CSS trickery!

An example of this for us is where a plugin shortcode was inserted within the WYSIWIG editor which was within a container div and we wanted this element to be full width of the page.

How we did it…

Firstly, as we are manipulating the div full width we need to add the following to the top of our main stylesheet:

html,
body {
	overflow-x: hidden;
}

The next step is add some css for the div that we want extend full width:

.fullwidth { /* Update this to your div name */
     width: 500%;
     margin-left: -200%; 
}

To explain what is happening here, we are making the div 500% width which makes it five times bigger than the content area and full width on most screens depending on the size of the div container. The margin left of -200% is then set to make it centered again.

The -200% in our example is actually a calculation of (width – 100%) / 2

So if you made the width 300% then the margin left would be (300% – 100% = 200%) / 2 = -100% (be sure that it is a negative margin).

There it is, a simple method to break a div out of its container which works cross browser.

Any questions then please leave a comment

Matt Peacock

Matt is an award-winning WordPress developer with over 11 years of web development experience. A WordPress devotee with a real passion for contributing and improving what he does on a daily basis, he builds websites that are the 'difference that makes the difference'. Matt is a former county champion golfer, NLP Practitioner, qualified life coach and has a degree in Psychology.

Share
Published by
Matt Peacock

Recent Posts

Why collaborative partnerships are the way to grow your agency

How do you go about growing your agency? Do you rely on repeat business and…

4 years ago

Didn’t get that promotion? Good

Following on from yesterday's post “if you want to be tougher, be tougher”, this is…

4 years ago

Why WordPress coding standards are everything

We were recently asked by someone why we relatively expensive and charged more than someone else…

6 years ago

Our first e-book is here, here is how you can get it

We are pleased to announce that our first e-book is now available to download on…

6 years ago

Weekly round-up of WordPress news – Vol 21

A nice mix this week of Wordpress guides and e-commerce posts make up this weeks…

7 years ago

Weekly round-up of WordPress news – Vol 20

GDPR features today and this is going to be a hot topic in WordPress and…

7 years ago

This website uses cookies.