English 中文(简体)
1. 建立纵向和横向中心 html div
原标题:Creating a vertically and horizontally centered html div

我正试图创建一个类似于谷歌主页的网页。 该系统将有一个中央定位输入箱和一个显示链接的顶点。 我也希望,如果我改变浏览器窗户的规模,该页就会充满活力。 我已经利用 y2电网和一张桌子取得了部分成功。 这里指:

<body>
  <div id="doc3">
    <div id="hd"><a style="float:left" href="link1.com"> link1</div> 
    <div id="bd" style="display: table; height: 400px;">
      <div style="display: display: table-cell; vertical-align: middle">
        <input name="searchbox" value="searchinput" size="40" />
        <input name="submit" type="submit" value="search />
      </div>
    </div> 
  </div>
</body>

唯一的问题是,该网页在转播浏览器窗户时没有动态地转播。 是否有更好的办法这样做?

最佳回答

你们可以 use笑,完美地把它定下来。

jQuery

$(window).resize(function() {
    var wh = (($(window).height()-$( #center ).height())/2)+ px ;
    var ww = (($(window).width()-$( #center ).width())/2)+ px ;
    $( #center ).css({
        top: wh,
        left: ww
    });
}).resize();

CSS

#center {
    border: 1px solid black;
    position: absolute;
    width: 50px;
}​

如果你不关心“ 适当>垂直集中,你可以:

#center {
    border: 1px solid black;
    margin: 0 auto;
    position: relative;
    width: 50px;
    top: 45%; /* or whatever % looks  right  */
}​
问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

Drop down background url in Safari Issue

selectBox.selectCSS { background: url(/Images/replacementSelectBackground.png) top left no-repeat height:auto; } I have an issue in Safari only where the image is not rendering on top ...

CSS specific for Safari

How do you target specifically safari in css with styles?

Aligning textarea in a form

Ive used the following css code to align my form elements: form { position:relative; } form input { position:absolute; left:11em; } However, the textarea element is not aligned correctly with the ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

CSS problem with page footer

I have defined my page footer in the css file as: #footer { position: absolute; height: 50px; text-align: center; background: #66CCCC; bottom: 0px; left: 0px; width: 100%; height: ...

热门标签