body {
background: #f06d06;
font-size: 80%;
}
main {
background: white;
height: 300px;
margin: 20px;
width: 300px;
position: relative;
resize: vertical;
overflow: auto;
}
main div {
position: absolute;
top: 50%;
left: 20px;
right: 20px;
background: black;
color: white;
padding: 20px;
transform: translateY(-50%);
resize: vertical;
overflow: auto;
}
<main>
<div>
xxxxxxxxxxxxxxxxxxxxxxxxxxx
</div>
</main>
วิธีอื่น
<html>
<head>
<style type=”text/css”>
#container{
width:900px;
height:500px;
margin:auto;
border:solid 1px #000;
}
#container-left{
background-color:#FFCCFF;
float:left;
width:500px;
margin-left:30px;
height:300px;
}
#container-right{
background-color:#CC99CC;
float:right;
width:300px;
margin-right:30px;
height:300px;
}
</style>
<meta http-equiv=”Content-Type” content=”text/html; charset=windows-874”></head>
<body><div>
<div id=”container”>
<div id=”container-left”>เนื้อหาด้านซ้ายมือ
</div>
<div id=”container-right”>เนื้อหาด้านขวามือ
</div>
</div>
</body>
</html>