我需要在左邊框中將文本「Hello world」製作爲(垂直)中間。如何在不改變div大小的情況下垂直對齊文本中的文本
如果我更改CSS
.red-banner .text { background: rgb(32,56,100); color: white; padding-top:8px; }
隨後的「Hello world」將被一點點往下移,但黑色的背景也將被轉移和重疊的旗幟之下。
所以,我怎麼能對準盒垂直中間內的文本而不改變黑色背景的大小? (文本內容最多2行)。
#parent {
overflow: hidden;
margin:0px;
}
.right {
border-left: 2px solid;
border-color: rgb(215,217,216);
padding-left: 20px;
float: right;
width: 270px;
}
.left {
margin: 0px;
overflow: hidden;
height: 100%;
}
body {
margin:0px;
font-family: Calibri;
}
header20 {
font-size: 16pt;
}
#inner {
margin-left: 10px;
width:730px;
margin: 0 auto;
}
.banner {
position: relative;
}
.banner .text {
position: absolute;
top: 0;
left: 0;
width: 250px;
height: 100%;
display: none;
}
.banner:hover .text {
display: block;
}
.red-banner .text {
background: rgb(32,56,100);
color: white;
}
.green-banner .text {
background: green;
}
<div id="parent" class="row">
<div class="right">
<br>
<div class="banner red-banner">
<img src="http://dbclipart.com/wp-content/uploads/2016/03/Red-banner-clipart-image-1.png" style='width:250px;height:50px'>
<div class="text">
Hello world.
</div>
</div>
<br>
<div class="banner green-banner">
<img src="http://images.clipartpanda.com/banner-20clipart-normal_1283818525.jpg" style='width:250px;height:50px'>
<div class="text">
Hello world, this is a test message for the effect.
</div>
</div>
<br>
<table style='width:250px;background-color:rgb(211,238,208)'>
<tr>
<td>
<header20><span style='color:rgb(17,56,96)'><b>This is a table</b></span></header20>
<ul style='padding-left:25px;margin-top:0px;magrin-bottom:0px'>
<li>First point</li>
<li>Second point</li>
<li>Third point</li>
</ul>
</td>
</tr>
</table>
<br>
<table style='width:250px;background-color:rgb(211,238,208)'>
<tr>
<td>
<header20><span style='color:rgb(17,56,96)'><b>This is another table</b></span></header20>
<ul style='padding-left:25px;margin-top:0px;magrin-bottom:0px'>
<li>First point</li>
<li>Second point</li>
<li>Third point</li>
</ul>
</td>
</tr>
</table>
<br>
</div>
<div class="left">
<div id="inner">
<br>
<img src="smallpic.png" style='float:left;margin:0.1cm;width:85px;height:85px'>
<p style='margin-left:2cm;font-size:22.0pt;margin-top:6pt;color:rgb(0,56,96)'><b>This is the title of the page - bla bla bla <br>Timetable for the next month</b></p>
<p style='margin-left:1cm'> The first line of the content</p>
<p style='margin-left:1cm'> The second line of the content</p>
<p style='margin-left:1cm'> The third line of the content</p>
<br>
</div> \t \t \t
\t \t \t
<table align='center'>
<tr>
<td style='padding-right:25px'><img src="pic1.png" style='width:140px;height:115px'/></td>
<td style ='padding-left:25px;padding-right:25px'><img src="pic2.png" style='width:140px;height:115px'/></td>
<td style ='padding-left:25px'><img src="pic3.png" style='width:140px;height:115px'/></td>
</tr>
</table>
</div>
</div>
使用'線height',而不是填充,並設置其與母公司 –