612wharfavenue Posted June 8, 2013 Share Posted June 8, 2013 Hi please take a look at my site, below is the code snippet in question i have to center my images since ive never had any luck with the css-html methods. The problem is because its set to wait for document.ready() sometimes it will place all my images to the right. Ive tried window.load() but the images center offscreen at smaller window sizes. It was also suggested i try <div style=" background: url('Assets/image.png') center center no-repeat; width: 100%; height: 500px; "> </div> but this causes it to lose responsiveness. Ive searched around and i cant find a solution, i just need my images (and the one form) to stay centered and for the images to scale down with the window size.site: http://bit.ly/11nAQJK <script type="text/javascript"> //Centering Script$(document).ready(function () { updateContainer(); $(window).resize(function() { updateContainer(); });});function updateContainer() {(function ($) {$.fn.vAlign = function() { return this.each(function(i){ var h = $(this).height(); var oh = $(this).outerHeight(); var mt = (h + (oh - h)) / 2; $(this).css("margin-top", "-" + mt + "px"); $(this).css("top", "50%"); $(this).css("position", "absolute"); }); };})(jQuery);(function ($) {$.fn.hAlign = function() { return this.each(function(i){ var w = $(this).width(); var ow = $(this).outerWidth(); var ml = (w + (ow - w)) / 2; $(this).css("margin-left", "-" + ml + "px"); $(this).css("left", "50%"); $(this).css("position", "absolute"); });};})(jQuery); Link to comment Share on other sites More sharing options...
dsonesuk Posted June 8, 2013 Share Posted June 8, 2013 All you need to do is apply display: block; and margin:0 auto; to image <img class="image" src="Assets/OrderSheet.png" style="display:block; margin: 0 auto;"> and don't use <br> for spacing, use margins or padding instead. Link to comment Share on other sites More sharing options...
612wharfavenue Posted June 9, 2013 Author Share Posted June 9, 2013 How do i apply that to the form? I tried making a div around it with display:block; margin: 0 auto;but it didnt center. Link to comment Share on other sites More sharing options...
dsonesuk Posted June 9, 2013 Share Posted June 9, 2013 The use of margin: 0 auto; requires a fixed width to be defined. In this case you would only use margin: 0 auto; on the form to center, IF the form is the same width to accommdate the input elements within it. BUT! because inputs are inline, in other words act like text in a paragraph element you just need to apply text-align: center; to the form element. Link to comment Share on other sites More sharing options...
612wharfavenue Posted June 9, 2013 Author Share Posted June 9, 2013 Ooooh, super simple then, thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now