This question already has answers here:
How can I horizontally center an element?
(133 answers)
Closed 8 years ago.
How do you center a div or anything else horizontally, so that on both sides the empty spaces are equal? And the div is exactly in the middle? No matter the size of the objects.
Take for example: the Stackoverflow site itself.
Except for the black header on the top of this site, everything is in the middle and the empty spaces on both sides are equal to each other.
I've searched for a long time, but I only encountered the wrong answers or vague answers.
Please help and thank you!
In css, you can use margin: auto;
A common pattern is to wrap your content in a container with a fixed width and add margin: auto; to it.
try this. here is why
margin: 0 auto;
The common way is using margin:0px auto. Look at the following example.
HTML
<div id="wrapper">
<div class="test">
This is my content Div.
</div>
</div>
CSS
.test
{
width:60%;
border:1px solid #ccc;
margin:0px auto;
}
DEMO
Related
This question already has answers here:
Image inside div has extra space below the image
(10 answers)
Closed 1 year ago.
I'm totally beginner, but I really don't know why there is a space between the bottom of my image and my wrap div border!
What's this???
<div class="myItem">
<img src="https://picsum.photos/100">
</div>
.myItem {
border: 5px solid blue;
background: tomato;
}
https://jsfiddle.net/g7rvm0ub/1/
Add display:block to img will remove the bottom space, another approach is add vertical-align:middle to img.
I'm not sure why the div is 5 pixels bigger than the the image, as I am a bit of a beginner as well, but one way to fix it is to decrease the size of the div using height: 100px.
This question already has answers here:
Flexbox: center horizontally and vertically
(14 answers)
Closed 5 years ago.
I am building user interface for responsive single page chat application using HTML and CSS. The interface must include a <form> element for submitting a message.
Inside the <form> element I have <textarea> element and <button> element as submit button. The button must have inside it two images one centered on the other, and after a lot of effort and searchs I managed to do that. The problem is that I want this <button> and <textarea> to be on the same line and vertically centered in the <form>. I tried and searched a lot for something that may help me but none of the results was what I need,some of the what I tried is based on the answers in the following link:
Vertically centering button using css
see my code in fiddle.
Note: I am not allowed using CSS frameworks and no IDs for styling.
I appreciate any help.
Thank you!
use vertical-align:middle; on textarea
CSS
textarea{
vertical-align:middle;
}
You can adjust your image by giving it width, height and required margin padding.
img {
width: 30px;
height: 30px;
background-color: red;
}
For centering objects you can use margin: 0 auto;
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Using jQuery to center a DIV on the screen
I know it works with table, but nowdays there is no way to auto vertical align (in the center) text? I can't believe it...
My code :
HTML
<div class="content">
This is my text
</div>
CSS
.content
{
width:80px;
height:150px;
background-color:#aeaeae;
}
Add display: table-cell; vertical-align: middle; to your div, demo: little link.
For this to work on IE7, you can use this: another little link. It detects when your browser is IE6/7, and replaces elements with display: table-*; with actual HTML tables.
Here's a site with multiple options and the assessments of each. I've used the table based one with good success.
http://css-tricks.com/vertically-center-multi-lined-text/
.content
{
width:80px;
height:150px;
background-color:#aeaeae;
display:table-cell;
vertical-align:middle;
}
This should help
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Space at the bottom and right side of my page
First off, I am sorry for posting this twice, my previous question earlier got good replies but they did not fix my problem.. so I am posting it again to hopefully get some more answers (I really need to fix this issue!)
Link for the actual page
Basically, at the bottom of my page between the offers/properties div and the footer there is a big space. I know why this is; I have used relative positioning and used top: -256px; to position the boxes where they are.
I have tried:
Aligning the 2 divs with absolute positioning - that does the trick of getting rid of the space at the bottom and I can get the boxes where I want them however if I was to scale down the browser, the boxes go out of position..(is there a way to get around that?)
Removing all positioning and floating them to the left/right - removes the space at the bottom/right but doesn't go into the position I would like them to
Sam on my previous question did this, it sorts of my problem just I can get them into position!
Adding overflow: hidden; to the container div.
I just don't know what to do so any help is really appreciated!
Thanks in advance!
EDIT:
Just saw that you got that answer already.. The next step is to put those boxes in a container.
<div id="offer_box_wrap"></div>
style
#offer_box_wrap {
width: 650px;
float: left;
margin-left: 5px;
}
you'll have to tweak it but it should work
end EDIT
You are relatively positioning your left boxes so...
i would suggest this
do not use <li> for boxes
use a div with a class that aligns them as you want.
<div class="offer_box"></div>
style it
.offer_box {
width: 208px;
height: 170px;
background: url(http://www.propertytest.uphero.com/images/offers_box.png) no-repeat;
float:left;
margin: (figure out the spacing you need for 3 per row)
}
put a clear div underneath the last one
<div style="clear: both"></div>
see it here http://jsfiddle.net/atTGa/2/
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Give a CSS styled div a “border-left-image”
Im trying to put a border on a div, to the left and to the right of the div.
HTML:
<div id="containerscontainer"><div>
CSS:
#containerscontainer {
width: 970px;
margin: 0 auto;
padding: 0px 0px 0px 0px;
background-color:#000;
border-left-image:url('/gfx/bkshadleft.png');
border-right-image:url('/gfx/bkshadright.png');
}
but for some reason in chrome i can see im getting error unknown property name? why is this? am i not doing it right?
Fiddle example: http://jsfiddle.net/uzi002/8dX7R/3/
To work in Chrome, you need to name the style:
-webkit-border-left-image
See this post: Give a CSS styled div a "border-left-image"
From experience, I feel like the syntax might be off, or the images aren't the right dimensions and the borders are off. I'd recommend using a website like this to generate the images:
http://border-image.com/
And also, I see no border images in your Fiddle.