Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS center content inside div

I need to center html content inside a div class="partners" (top div with 2 images). As you can see from the image below (it floats left instead of center of the div):

enter image description here

This is my html code:

<div id="partners">     <div class="wrap clearfix">         <h2>Partnertnerzy serwisu:</h2>         <ul>             <li><a href="http://www.dilbert.com/"><img width="56" height="16" alt="Parnter bar wika" src="/as/partners/wika.png"></a></li>                 <li><a href="http://www.youtube.com><img width="65" height="15" alt="Parnter bar siemens" src="/as/partners/siemens.png"></a></li>             </ul>         <a class="linkClose" href="/firmy?clbp=1">Zamknij </a>     </div> </div> 

Image: enter image description here

CSS:

#partners, #top {     position: relative;     z-index: 100; } #partners {     margin: 12px 0 3px;     text-align: center; } .clearfix:after, .row:after {     clear: both;     content: ".";     display: block;     height: 0;     visibility: hidden; } #partners .wrap {     width: 655px; } .wrap {     margin: 0 auto;     position: relative;     width: 990px; } #partners h2 {     color: #A6A5A5;     float: left;     font-weight: normal;     margin: 2px 15px 0 0; } #partners ul {     float: left; } ul {     list-style-position: outside;     list-style-type: none; } 
like image 816
ShaneKm Avatar asked Oct 28 '11 07:10

ShaneKm


People also ask

How do I center the content of a div in CSS?

You can do this by setting the display property to “flex.” Then define the align-items and justify-content property to “center.” This will tell the browser to center the flex item (the div within the div) vertically and horizontally.

How do I center my inner div?

To move the inner div container to the centre of the parent div we have to use the margin property of style attribute. We can adjust the space around any HTML element by this margin property just by providing desired values to it.

How do I center an image in a div using CSS?

Step 1: Wrap the image in a div element. Step 2: Set the display property to "flex," which tells the browser that the div is the parent container and the image is a flex item. Step 3: Set the justify-content property to "center." Step 4: Set the width of the image to a fixed length value.

How do I center text vertically in a div?

Answer: Use the CSS line-height property Suppose you have a div element with the height of 50px and you have placed some link inside the div that you want to align vertically center. The simplest way to do it is — just apply the line-height property with value equal to the height of div which is 50px .


1 Answers

To center a div, set it's width to some value and add margin: auto.

#partners .wrap {     width: 655px;     margin: auto; } 

EDIT, you want to center the div contents, not the div itself. You need to change display property of h2, ul and li to inline, and remove the float: left.

#partners li, ul, h2 {     display: inline;     float: none; } 

Then, they will be layed out like normal text elements, and aligned according to text-align property of their container, which is what you want.

like image 197
socha23 Avatar answered Sep 19 '22 09:09

socha23