What's new

Welcome to the forum 👋, Visitor

To access the forum content and all our services, you must register or log in to the forum. Becoming a member of the forum is completely free.

Center Div

fermlour

Member
Joined
Mar 29, 2013
Messages
32
Reaction score
1
HTML Coins
0
Hello, anyone knows if it is possible to center a div vertically and horizontally? I already tried but when I change the zoom is not centered.
 
If I'm not mistaken, the easiest method is defining the div's line-height attribute through CSS. That way, the line of text will be vertically centered automatically. For instance:

HTML:
<div style="line-height:100px">
Text
</div>

That only works for 1 line of text though. If you need to vertically center images or a paragraph, this may help: http://www.vanseodesign.com/css/vertical-centering/

Hope that helps!
 
Centered with respect to what? Do you just have a single div that you want in the middle of a blank document?

Perhaps try posting the code you have so far?
 
Imagine, I have a div with an image 400px x 400px, I want to center the image in the center of the screen. I'm using the code <center>, but I can not center vertically
 
You'll want to set the padding up top to 50% in the css, so it brings down the div half way to the page.

<div id=image><img src="url" /></div>

And for CSS

.image { padding-top:50%;}
 
<html>
<head>
<style type="text/css">
.image { padding-top:50%;}

</style>
</head>

<body>
<center>
<div id=image><img src="http://www.rossmoyne.wa.edu.au/Portals/0/docs/Community/Alumni/Facebook-Icon.jpg" /></div>
</center>
</body>
</html>

Am I doing something wrong?
 
No. like so:

<html>
<head>
<style type="text/css">
#image { padding-top: 10%;}

</style>
</head>

<body>
<center>
<div id="image"><img src="http://www.rossmoyne.wa.edu.au/Portals/0/docs/Community/Alumni/Facebook-Icon.jpg" /></div>
</center>
</body>
</html>

Play around with the percentages for the padding until you get the desired results.
 
<html>
<head>
<style type="text/css">
.image { padding-top:50%;}

</style>
</head>

<body>
<center>
<div id=image><img src="http://www.rossmoyne.wa.edu.au/Portals/0/docs/Community/Alumni/Facebook-Icon.jpg" /></div>
</center>
</body>
</html>

Am I doing something wrong?

Change the .image to #image because id's use the # and classes use the . Then play around with the percentage until you get the desired results.
 
Why don't you get rid of the <center> tag and like Melvin said use "#image { padding-top:50%;}" use "#image { padding-left:50% }" as this will most likely work. Plus ID's use "#" not "." so that could be a problem with your previous code you posted.
 
Why don't you get rid of the <center> tag and like Melvin said use "#image { padding-top:50%;}" use "#image { padding-left:50% }" as this will most likely work. Plus ID's use "#" not "." so that could be a problem with your previous code you posted.

I can not yet, is not centered.
I am using the code:

<html>
<head>
<style type="text/css">
#image { padding-top:50%;}
#image { padding-left:50% }
</style>
</head>

<body>

<div id=image><img src="http://www.rossmoyne.wa.edu.au/Portals/0/docs/Community/Alumni/Facebook-Icon.jpg" /></div>

</body>
</html>

thank you!
 
HTML:
<div id="container" style="height:500px;background:url(http://www.rossmoyne.wa.edu.au/Portals/0/docs/Community/Alumni/Facebook-Icon.jpg) no-repeat 0 50%"></div>

Use the image as a background one, then set the div's height to the appropriate one.
 
Code:
<html>
<head>
<style type="text/css">
#image { padding-top:25%; padding-left:50%; }
</style>
</head>

<body>

<div id=image><img src="http://www.rossmoyne.wa.edu.au/Portals/0/docs/Community/Alumni/Facebook-Icon.jpg" /></div>

</body>
</html>

that should work
 
In both codes gives the error! : \ Let there ... I'll try to use <center>
 

Theme customization system

You can customize some areas of the forum theme from this menu.

  • Wide/Narrow view

    You can control a structure that you can use to use your theme wide or narrow.

    Grid view forum list

    You can control the layout of the forum list in a grid or ordinary listing style structure.

    Picture grid mode

    You can control the structure where you can open/close images in the grid forum list.

    Close sidebar

    You can get rid of the crowded view in the forum by closing the sidebar.

    Fixed sidebar

    You can make it more useful and easier to access by pinning the sidebar.

    Close radius

    You can use the radius at the corners of the blocks according to your taste by closing/opening it.

  • Choose the color combination that reflects your taste
    Background images
    Color gradient backgrounds
Back