Mobile app version of vmapp.org
Login or Join
Annie201

: Making a div wrap around the content I have a div but it fits to the borders of the container instead of wrapping around the text. I tried float:left but it will push it to the side and

@Annie201

Posted in: #Css

I have a div but it fits to the borders of the container instead of wrapping around the text. I tried float:left but it will push it to the side and there's no way to make it go to the center. Help?

Code:

div.warning-stripe {
padding:2px;
border:1px solid #FFA11B ;
background-color: #FFC71B ;
vertical-align:middle;
color:835600;
margin-left:auto;
margin-right:auto;
text-align:center;

}

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Annie201

1 Comments

Sorted by latest first Latest Oldest Best

 

@Pope3001725

Based on what I see I'm guessing you're trying to get this DIV to center itself in another block level element and not have it expand to the entire width of the container. To do that you need to set a width for that DIV:

div.warning-stripe {
padding:2px;
border:1px solid #FFA11B ;
background-color: #FFC71B ;
vertical-align:middle;
color:835600;
margin-left:auto;
margin-right:auto;
text-align:center;
width: 300px; /* You need a width if you're going to use auto margins */
}

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme