右对齐但不破坏垂直对齐
aligning right but not breaking the vertical align
我仍然有很多问题,现在甚至很难描述这个问题。黄色文本区域应位于粉红色 div 的边缘(右侧边缘),黄色区域 div 与左侧其他区域(包含绿色和红色区域)。
如果我在 'home-featured-class-3' 中添加 'float:right;',问题就解决了,但这会产生一个新问题,即黄色文本区域 div 移到顶部。
如何让黄色文字div向右浮动,同时垂直居中浮动? (不调整任何东西的height/width)
HTML & CSS:
.home-featured-class-3{
width: 630px;
height:auto;
margin:0 0 0 30px;
display: inline-block;
vertical-align: middle;
background:#CF0;
}
.home-featured-class-4{
width:298px;
height:auto;
margin:0 0px 0 0;
border: 1px solid #211c20;
display: inline-block;
vertical-align: middle;
}
.home-featured-class-A{
width:960px;
height:auto;
background:#C3C;
vertical-align:middle;
}
.clear {
clear: both;
}
h6{
font-family:arial,verdana,helvetica,sans-serif;
font-size:18px;
color:#201c1f;
text-decoration:none;
text-transform:uppercase;
font-weight:100;
margin:0;
padding:10px;
background:#DB1D1D;
text-align:center;
border-top:1px solid #211c20;
}
h6 a:link{
color:#201c1f;
text-decoration:none;
}
h6 a:visited{
color:#201c1f;
text-decoration:none;
}
h6 a:hover{
color:#201c1f;
text-decoration:underline;
}
#home-featured-classes-wrap{
width:auto;
height:auto;
margin: 30px 0 0 0;
}
.home-featured-class:hover .products {
text-decoration: underline;
}
.home-featured-class-end{
width:298px;
height:auto;
margin:0 0 0 0;
border: 1px solid #211c20;
float:left;
}
.home-featured-class-end:hover .products {
text-decoration: underline;
}
<div id="home-featured-classes-wrap">
<div class="home-featured-class-A">
<div class="home-featured-class-4"><a href="products.html"><img name="RP-TEXT" src="http://upload.wikimedia.org/wikipedia/commons/d/de/Color-Green.JPG" width="298" height="148" alt="RP-TEXT" style="background-color: #3366FF" /></a>
<h6 class="products"><a href="products.html" title="RP-TEXT">RP-TEXT</a></h6>
</div>
<div class="home-featured-class-3">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</div>
<div class="clear"></div>
</div>
</div>
这是你的问题(在 CSS 评论中描述):
.home-featured-class-3{
width: 630px;
height:auto;
margin:0 0 0 30px; /* Here you set the margin to 30px on the left. */
display: inline-block;
vertical-align: middle;
background:#CF0;
margin: 0; /* Here you set it back to 0 again. Simply remove this line. */
}
此外,您还必须删除 <div class="home-featured-class-3">
上方的换行符(或将其注释掉)。 HTML 引擎会创建一个额外的白色 space 字符,因为这个换行符让你只剩下大约 27px 的 space 而不是 30px。您必须删除这些换行符才能设置 30 像素的距离。
这就是您的 HTML 需要的:
<div id="home-featured-classes-wrap">
<div class="home-featured-class-A">
<div class="home-featured-class-4">
<a href="products.html"><img name="RP-TEXT" src="http://upload.wikimedia.org/wikipedia/commons/d/de/Color-Green.JPG" width="298" height="148" alt="RP-TEXT" style="background-color: #3366FF" /></a>
<h6 class="products"><a href="products.html" title="RP-TEXT">RP-TEXT</a></h6>
</div><!--
--><div class="home-featured-class-3">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</div>
<div class="clear"></div>
</div>
</div>
我仍然有很多问题,现在甚至很难描述这个问题。黄色文本区域应位于粉红色 div 的边缘(右侧边缘),黄色区域 div 与左侧其他区域(包含绿色和红色区域)。
如果我在 'home-featured-class-3' 中添加 'float:right;',问题就解决了,但这会产生一个新问题,即黄色文本区域 div 移到顶部。
如何让黄色文字div向右浮动,同时垂直居中浮动? (不调整任何东西的height/width)
HTML & CSS:
.home-featured-class-3{
width: 630px;
height:auto;
margin:0 0 0 30px;
display: inline-block;
vertical-align: middle;
background:#CF0;
}
.home-featured-class-4{
width:298px;
height:auto;
margin:0 0px 0 0;
border: 1px solid #211c20;
display: inline-block;
vertical-align: middle;
}
.home-featured-class-A{
width:960px;
height:auto;
background:#C3C;
vertical-align:middle;
}
.clear {
clear: both;
}
h6{
font-family:arial,verdana,helvetica,sans-serif;
font-size:18px;
color:#201c1f;
text-decoration:none;
text-transform:uppercase;
font-weight:100;
margin:0;
padding:10px;
background:#DB1D1D;
text-align:center;
border-top:1px solid #211c20;
}
h6 a:link{
color:#201c1f;
text-decoration:none;
}
h6 a:visited{
color:#201c1f;
text-decoration:none;
}
h6 a:hover{
color:#201c1f;
text-decoration:underline;
}
#home-featured-classes-wrap{
width:auto;
height:auto;
margin: 30px 0 0 0;
}
.home-featured-class:hover .products {
text-decoration: underline;
}
.home-featured-class-end{
width:298px;
height:auto;
margin:0 0 0 0;
border: 1px solid #211c20;
float:left;
}
.home-featured-class-end:hover .products {
text-decoration: underline;
}
<div id="home-featured-classes-wrap">
<div class="home-featured-class-A">
<div class="home-featured-class-4"><a href="products.html"><img name="RP-TEXT" src="http://upload.wikimedia.org/wikipedia/commons/d/de/Color-Green.JPG" width="298" height="148" alt="RP-TEXT" style="background-color: #3366FF" /></a>
<h6 class="products"><a href="products.html" title="RP-TEXT">RP-TEXT</a></h6>
</div>
<div class="home-featured-class-3">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</div>
<div class="clear"></div>
</div>
</div>
这是你的问题(在 CSS 评论中描述):
.home-featured-class-3{
width: 630px;
height:auto;
margin:0 0 0 30px; /* Here you set the margin to 30px on the left. */
display: inline-block;
vertical-align: middle;
background:#CF0;
margin: 0; /* Here you set it back to 0 again. Simply remove this line. */
}
此外,您还必须删除 <div class="home-featured-class-3">
上方的换行符(或将其注释掉)。 HTML 引擎会创建一个额外的白色 space 字符,因为这个换行符让你只剩下大约 27px 的 space 而不是 30px。您必须删除这些换行符才能设置 30 像素的距离。
这就是您的 HTML 需要的:
<div id="home-featured-classes-wrap">
<div class="home-featured-class-A">
<div class="home-featured-class-4">
<a href="products.html"><img name="RP-TEXT" src="http://upload.wikimedia.org/wikipedia/commons/d/de/Color-Green.JPG" width="298" height="148" alt="RP-TEXT" style="background-color: #3366FF" /></a>
<h6 class="products"><a href="products.html" title="RP-TEXT">RP-TEXT</a></h6>
</div><!--
--><div class="home-featured-class-3">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</div>
<div class="clear"></div>
</div>
</div>