The portion in the yellow box given in below page ink should be in center and it should be increased or decreased according to the text. In that case i do not want to use width:px because if i use width:px then i can not write text with different length.
page link: http://dot.kr/z-test/01/test4.php
Try this:
<div style="color:black; display:table; text-align:center; background:cyan;">
<div style="display:table-cell; background:yellow; display:inline-block;">
<p> dynamic text </p>
</div>
</div>
1 Like
thanks a lot! After adding width: its working fine.
You don’t need a width just use display:table and auto margins to center the element.
<div class="wrap"><div class="content">Dynamic content</div></div>
CSS:
.wrap{margin:20px;background:yellow}
.content{display:table;margin:auto;background:cyan}
Full example.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
.wrap{margin:20px;background:yellow}
.content{display:table;margin:auto;background:cyan}
</style>
</head>
<body>
<div class="wrap"><div class="content">Dynamic content</div></div>
<div class="wrap"><div class="content">Dynamic content with more text</div></div>
<div class="wrap"><div class="content">Dynamic</div></div>
<div class="wrap"><div class="content">Dynamic content</div></div>
</body>
</html>
1 Like
system
Closed
August 14, 2016, 3:32pm
6
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.