- This topic is empty.
-
AuthorPosts
-
December 12, 2011 at 8:38 pm #35613
dynamyc
MemberI have this markup for example :
----some content----
and this css:
#container {
position:relative;
width:100%;
}
#search {
position:absolute;
top:0;
left:50%;
}Am I forced to define the width of container in pixels to make the search be in the middle of the screen, because I want to be centered for almost every desktop resolutions?
December 12, 2011 at 8:47 pm #92574December 13, 2011 at 12:27 am #92578poonu
Memberuse this trick
.div-abc {position:absolute;
z-index:1;
width:500px; height:500px; background:#666; border:solid 1px #333;
border-radius:10px;
-moz-border-radius:10px;
-webkit-border-radius:10px;
left:50%;
margin-left:-250px;
}December 13, 2011 at 2:08 am #92580jamygolden
MemberThe div must have a fixed size to center an absolute div ( without js )
December 13, 2011 at 3:32 am #92584joshuanhibbert
Member@jamy_za that depends on if you need it to work in IE7 or not. The link I posted above shows a solution that doesn’t require a fixed width.
December 13, 2011 at 11:38 am #92600dynamyc
MemberOh yeah, this is the answer I was looking for, many thanks.
But now I have another issue, I can’t center some thumbnails vertically.
I’ve tried to use : vertical-align: middle; but with no success.Markup for this is:
and this css:
.jThumbnailScroller#tS1{
position:relative;
width:100%;
}
.jThumbnailScroller .jTscrollerContainer{position:absolute;}
.jThumbnailScroller .jTscroller{position:relative; height:100%; margin:0; left:0; top:0; display:inline-block; *display:inline;}
.jThumbnailScroller{
position:relative;
width:800px;
height:255px; /*changed 255px set it if you change #tt margin-top value*/
margin:0;
padding:0;
overflow:hidden;
}
December 13, 2011 at 4:53 pm #92646joshuanhibbert
MemberI’m not sure exactly what you’re trying to do, but looking at the markup on this page might help: http://joshnh.com/lab/
June 20, 2013 at 5:53 pm #139664connorgaughan
MemberBased on your original post this [Pen might come in handy](http://codepen.io/connorgaughan/pen/gHqtl “CodePen”). Essentially you center the absolutely positioned div by defining a width by % not px. Using the box-model idea you split the difference from 100 and apply it to left and right.
-
AuthorPosts
- The forum ‘CSS’ is closed to new topics and replies.