logo
down
shadow

CSS / jQuery Vertically and Horizontally Center DIV


CSS / jQuery Vertically and Horizontally Center DIV

By : user3861632
Date : November 20 2020, 07:00 PM
I wish this help you I'm trying to vertically and horizontally center this div even when there is content to scroll and the user is scrolling down the page. The following test works fine in IE, but in Firefox I get a weird flickering affect when hovering over the thumbnail image. Any thoughts? , foo.css
code :


Share : facebook icon twitter icon
Center padded, full-width DIV horizontally and vertically using jQuery

Center padded, full-width DIV horizontally and vertically using jQuery


By : melisa
Date : March 29 2020, 07:55 AM
this will help The following code works wonders to center my div as long as there's no padding or 100% width in the css: , When I want to center something I normally do this:
code :
jQuery.fn.center = function () {

    this.css({
        position: 'absolute',
        top: 50+'%',
        left: 50+'%',
        marginTop: -(this.outerHeight()/2),
        marginLeft: -(this.outerWidth()/2)
    });

    return this;
}
$(element).center();
Using Jquery how do I get a div element to center vertically and horizontally on page load?

Using Jquery how do I get a div element to center vertically and horizontally on page load?


By : Rita Greyreality
Date : March 29 2020, 07:55 AM
I wish this help you Ok, lookie here: http://jsfiddle.net/zQ97A/13/
Basically you need to have width on your container and you also need the following code:
code :
"top": ((($(window).height() - $('.welcomer').outerHeight()) / 2) + $(window).scrollTop() + "px"),
"left": ((($(window).width() - $('.welcomer').outerWidth()) / 2) + $(window).scrollLeft() + "px")
Dynamically center div vertically and horizontally using jQuery

Dynamically center div vertically and horizontally using jQuery


By : user3621794
Date : March 29 2020, 07:55 AM
hope this fix your issue This will calculate dynamically the and position the .box at the center of the screen. You can also call this function on resize and rotate events.
code :
$(updateBoxDimension);
$(window).on('resize', updateBoxDimension);

function updateBoxDimension() {
    var $box = $('.box');

    // To center the box
    var boxLeft = ($(window).width()) / 2 - ($box.width() / 2),
        boxTop = ($(window).height()) / 2 - ($box.height() / 2);

    $box.css({
        left: boxLeft,
        top: boxTop
    });
}
Need to horizontally and vertically center align UL in DIV, and vertically center align the list elements which are text

Need to horizontally and vertically center align UL in DIV, and vertically center align the list elements which are text


By : ppaulweber
Date : March 29 2020, 07:55 AM
like below fixes the issue Remove float: left from the .navbar ul li rule, then apply the following CSS.
This works with the vertical-align property, which only applies to inline and inline-block elements. So we have to set all of the list items to display: inline-block and vertical-align:center to center them within the list.
code :
div.navbar div.table::before {
  content: "";
  display: inline-block;
  height: 100%;
  vertical-align: middle;
}
ul.nav {
  font-size: 0;
}
ul.nav li {
  display: inline-block;
  vertical-align: middle;
}
$(function() {
  $('ul.nav a').bind('click', function(event) {
    event.preventDefault();
    var $anchor = $(this);


    $('html, body').stop().animate({
      scrollTop: $($anchor.attr('href')).offset().top
    }, 1500);

    event.preventDefault();
  });
});
div.navbar div.table::before {
  content: "";
  display: inline-block;
  height: 100%;
  vertical-align: middle;
}
ul.nav {
  font-size: 0;
}
ul.nav li {
  display: inline-block;
  vertical-align: middle;
}
* {
  margin: 0;
  padding: 0;
}
body {
  letter-spacing: -1px;
}
.section {
  margin: 0px;
  height: 100vh;
  width: 100vw;
  background: url(../images/white.png) no-repeat center center fixed;
  position: relative;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}
.img-circle {
  border-radius: 50%;
  height: 100px;
  width: 100px;
}
.navbar {
  height: 160px;
  width: 100%;
  position: absolute;
  top: 0px;
  background: #fff;
  color: #000000;
  font-family: 'Lato', sans-serif;
}
.navbar:hover {
  background-color: #787878;
}
.contents {
  top: 160px;
  width: 100%;
  position: absolute;
  font-family: 'Open Sans', sans-serif;
  font-size: 16pt;
  font-style: none;
  letter-spacing: -1px;
}
.section h2 {
  font-family: 'Lato', sans-serif;
  font-size: 24px;
  text-align: center;
}
.section p {
  width: 600px;
}
.navbar ul {
  list-style: none;
}
.navbar ul li {
  padding: 15px;
  color: #000;
  font-size: 14px;
  font-weight: bold;
}
.navbar ul li a {
  color: #000;
  text-decoration: none;
}
.navbar ul li a:hover {
  text-decoration: none;
  color: #000;
}
span.reference {
  position: fixed;
  left: 10px;
  bottom: 10px;
  font-size: 13px;
  font-weight: bold;
}
span.reference a {
  color: #fff;
  text-shadow: 1px 1px 1px #000;
  padding-right: 20px;
}
span.reference a:hover {
  color: #ddd;
  text-decoration: none;
}
.table {
  display: table;
  /* Allow the centering to work */
  margin: 0 auto;
}
<body>
  <div class="section" id="sectionAbout">
    <div class="navbar">
      <div class="table">
        <ul class="nav">
          <li>ABOUT</li>
          <li><a href="#sectionServices">SERVICES</a>
          </li>
          <li>
            <a href="#sectionGWA">
              <img src="images/yellow.png" class="img-circle">
            </a>
          </li>
          <li><a href="#">BLOG</a>
          </li>
          <li><a href="#sectionContact">CONTACT</a>
          </li>
        </ul>
      </div>
    </div>
    <div class="contents">
      <h2>ABOUT US</h2>
      <div class="table">
        <p>
          <bold>this</bold>is some text
          <br>
          <br>this is some more text.
        </p>
      </div>
    </div>
  </div>
  <!-- The JavaScript -->
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
  <script type="text/javascript" src="css/jquery.easing.1.3.js"></script>
</body>
JQuery mobile: Vertically and horizontally center multiple images using grid

JQuery mobile: Vertically and horizontally center multiple images using grid


By : Goshawk
Date : March 29 2020, 07:55 AM
may help you . I'm building an app using jquery mobile. I want to vertically and horizontally center multiple images using grid, i want the images to be exactly in the center of the page. I'v tried everything but nothing really worked. , You can scale the content div to take the device height:
code :
$(document).on( "pagecontainershow", function(){
    ScaleContentToDevice();

    $(window).on("resize orientationchange", function(){
        ScaleContentToDevice();
    })
});

function ScaleContentToDevice(){
    scroll(0, 0);
    var content = $.mobile.getScreenHeight() - $(".ui-content").outerHeight() + $(".ui-content").height();
    $(".ui-content").height(content);
}
<div id="GridWrapper">
  <div class="ui-grid-a centeredGrid">
    <div class="ui-block-a" >
        <img alt="" src="http://i.imgur.com/MIK25Fd.png" >
    </div>
    <div class="ui-block-b">
        <img alt="" src="http://i.imgur.com/MIK25Fd.png" >
    </div>
    <div class="ui-block-a" >
        <img alt="" src="http://i.imgur.com/MIK25Fd.png" >
    </div>
    <div class="ui-block-b">
        <img alt="" src="http://i.imgur.com/MIK25Fd.png" >
    </div>
  </div>
</div>

#GridWrapper{
  position: relative;
  height: 100%;
}
#GridWrapper .centeredGrid{
  position: absolute;
  width: 380px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
Related Posts Related Posts :
  • Use jQuery to open PDF links with Google Docs
  • jquery performing calculation on dynamically generated elements
  • jqGrid dynamic select option - beforeEditCell not firing
  • jQuery.html() gets inner html. but i need the entire html
  • How to show javascript warning , if user click on link which will open in new window?
  • Unobtrusive horizontal scrolling with CSS and jQuery
  • How do I change an attribute in an HTML table's cell if I know the row and column index of the cell?
  • What is jQuery for Document.createElementNS()?
  • jQuery accordion link issue
  • using JQuery and Prototype in the same page; more explanation needed!
  • Height of JQuery UI Tab Content Panel
  • How can I filter using the current value of a text box in a jQuery selector?
  • fullCalendar Font size
  • Jquery: Extracting the hrefs from multiple links on a page
  • Simple javascript/jquery append, remove question
  • Append or prepend opening/closing tags with jQuery
  • Issue with jQuery setting checkboxes as checked in IE6 (not showing as checked?)
  • External arrows for jcarousel?
  • How to make this effect accessible for screen-reader and without JS
  • How to add brackets (a) to ordered list? compatible in all browsers
  • jQuery addClass() not running before jQuery.ajax()
  • jQuery Cycle on html elements instead of images?
  • Disable other option in same div, when first one is selected
  • Jquery: Fade multiple elements one after the other
  • Truncate text to fit table cell without wrapping using css or jquery
  • How to load jqtouch on-demand
  • Real messy JQUERY
  • Jqzoom not working on safari
  • jQuery: AJAX umlauts & special characters are a mess
  • jQuery core method overload
  • How to clear input text
  • JCrop - Can't move selection
  • Any way to colorize specific days in FullCalendar?
  • Identifying dynamically generated elements
  • Select and change property of all elements with css("color") of a certain value
  • jQuery: How do I stop the page being displayed until it's been processed?
  • Changing all CSS styles with a property via Jquery
  • CSS Menu loses focus when part of jquery hover()
  • jquery.ui sortable using a table and item:tr , placeholder difficulties
  • security deleting a mysql row with jQuery $.post
  • Loop through text nodes inside a div
  • Inline-editing: onBlur prevents onClick from being triggered (jQuery)
  • JQuery.AJAX - can my server return a blob of data?
  • $("div#myDiv").css("content") returns undefined in IE8
  • Add title to jQuery Cycle slideshow from Alt attribute?
  • getSelection() by Double Click or manual selection is not the same
  • JQuery QuickSearch: Searching on load if the input isn't blank
  • Jquery slideToggle problem
  • How to use jQuery to paginate JSON data?
  • Validating the age limit using jquery
  • filter only http:// using jquery
  • Jquery DatePicker Customization
  • Execute function after all ajax .load() requests are finished
  • JSONP how to retrieve text
  • Jquery date picker Next and previous button images are not showing
  • Selecting an element based on class and id in jquery - similar to an SQL query
  • fullCalendar json with php in "agendaWeek"
  • jQuery UI Tabs force delay before changing tab on mouseover
  • NOOB question... variable for animate value?
  • jquery ajax type GET question
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk