html - How to center a div horizontally with a varying width -
i did lot of research on , found if set width, can use margin: 0 auto
left: 0;
, right: 0
, , position: absolute
, saw had declared width.
well in case, doing button cursor: pointer;
, not want set width because cursor turn pointer. in addition link , mess more.
so, said, question is, how can div centered absolute value without declaring width.
.blue-section { background-color: #9bd0d2; height: 500px; width: 100%; position: relative; } #blue-info-container { top: 20%; position: absolute; left: 0; right: 0; width: 70%; margin: 0 auto; text-align: center; } #blue-section-title { color: #fff; font-size: 1.4em; padding-bottom: 75px; } #blue-section-description { color: #fff; font-size: 1.2em; } #blue-section-button { position: absolute; bottom: 20%; left: 0; right: 0; width: 300px; margin: 0 auto; cursor: pointer; } #blue-section-button span { border: 1px solid #fff; text-align: center; color: #fff; padding: 20px 20px; }
<div class="blue-section"> <div id="blue-info-container"> <div id="blue-section-title">fdsfdsafsda</div> <div id="blue-section-description">fnderjfgnreopn nfdewjfn wreo fnewjif njkfkew nji fn jekwf njfedww nfdefnewdi fewjq nffemdwkom fdmkwf mfewmkqoffewkqo fnfew klf</div> </div> <div id="blue-section-button"><span>more about</span> </div> </div>
try this. have modified css
.blue-section { background-color: #9bd0d2; height: 500px; width: 100%; position: relative; } #blue-info-container { top: 20%; position: absolute; left: 0; right: 0; width: 70%; margin: 0 auto; text-align: center; } #blue-section-title { color: #fff; font-size: 1.4em; padding-bottom: 75px; } #blue-section-description { color: #fff; font-size: 1.2em; } #blue-section-button { position: absolute; bottom: 20%; left: 0; right: 0; text-align: center; } #blue-section-button span { border: 1px solid #fff; text-align: center; color: #fff; padding: 20px 20px; display: inline-block; cursor: pointer; }
<div class="blue-section"> <div id="blue-info-container"> <div id="blue-section-title">fdsfdsafsda</div> <div id="blue-section-description">fnderjfgnreopn nfdewjfn wreo fnewjif njkfkew nji fn jekwf njfedww nfdefnewdi fewjq nffemdwkom fdmkwf mfewmkqoffewkqo fnfew klf</div> </div> <div id="blue-section-button"><span>more about</span> </div> </div>
Comments
Post a Comment