Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Centering Div content with variable width
Message
De
20/03/2020 20:01:54
 
 
À
Tous
Information générale
Forum:
CSS
Catégorie:
Autre
Titre:
Centering Div content with variable width
Divers
Thread ID:
01673761
Message ID:
01673761
Vues:
46
I need to center a div which has a variable width. Basically, no matter the content in that div, I need to assure that it will be centered. For as long as that div and its parent div have a fixed width, this works. However, on some specific pages, where that div is having content of various sizes, I cannot force a fix width. Without that, I cannot center the div. Anyone would have an idea?
<!DOCTYPE html>
<html>
<head>

<style>
html
{
   height: 100%;
}

body
{
   height: 100%;
   width: 100%;
   display: flex;
   flex-direction: column;
   margin: 0px;
}

.Main
{
   width: 100%;
   height: 100%;
   margin: auto;
   max-width: 720px;
}

.MyContainer
{
   max-width: 720px;
   background-color: #ffff00;
}
</style>
</head>

<body>
Header

<div class="Main">
<div class="MyContainer">Body</div>
</div>

Footer
</body>
</html>
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform