Javascript 如何将文本与div元素中的图像垂直居中?
我试图制作一个小片段,在左侧有一个图像,文本垂直居中于图像右侧。对于下面的第二幅图像,我希望图像位于右侧,文本垂直居中于图像左侧Javascript 如何将文本与div元素中的图像垂直居中?,javascript,jquery,html,css,css-float,Javascript,Jquery,Html,Css,Css Float,我试图制作一个小片段,在左侧有一个图像,文本垂直居中于图像右侧。对于下面的第二幅图像,我希望图像位于右侧,文本垂直居中于图像左侧 <div id="Segment2"> <h2>Fig Tree is a discussion tool that helps organizations innovate</h2> <h3>We took the basics of a discussion thread and added...&l
<div id="Segment2">
<h2>Fig Tree is a discussion tool that helps organizations innovate</h2>
<h3>We took the basics of a discussion thread and added...</h3>
<div style="height:259px;" id="Branching">
<section class=LeftBoundPic>
<h4>Discussion Branching</h4>
<img src="SomePhoto.png" alt="FigTree"/>
</section>
<span>
Bunch of text <br>
that should be next to the image.
</span>
</div>
<div style="height: 259px; margin-top: 50px;" id="ContentHubs">
<section class=RightBoundPic>
<h4>Content Hub</h4>
<img src="SomePhoto.png" alt="FigTree"/>
</section>
<span>
More text that should <br>
be on the left of the photo now.
</span>
</div>
</div>
Fig Tree是一个帮助组织创新的讨论工具
我们学习了讨论主题的基础知识,并添加了。。。
讨论分支
一堆文本
应该在图像旁边。
内容中心
更多应该
现在在照片的左边。
这是它的html部分,但我想不出一种用css来设计它的方式
.div表{
显示:表格单元格;
边框:1px纯黑;
}
.div单元{
显示:表格单元格;
填充物:5px;
垂直对齐:中间对齐;
}
.分区行{
显示:表格行;
垂直对齐:中间对齐;
}
讨论分支
应该位于图像旁边的一组文本
更多的文本,而且越来越多。
更多的文本。
讨论分支
应该位于图像旁边的一组文本。
.div表{
显示:表格单元格;
边框:1px纯黑;
}
.div单元{
显示:表格单元格;
填充物:5px;
垂直对齐:中间对齐;
}
.分区行{
显示:表格行;
垂直对齐:中间对齐;
}
讨论分支
应该位于图像旁边的一组文本
更多的文本,而且越来越多。
更多的文本。
讨论分支
应该位于图像旁边的一组文本。
.div表{
显示:表格单元格;
边框:1px纯黑;
}
.div单元{
显示:表格单元格;
填充物:5px;
垂直对齐:中间对齐;
}
.分区行{
显示:表格行;
垂直对齐:中间对齐;
}
讨论分支
应该位于图像旁边的一组文本
更多的文本,而且越来越多。
更多的文本。
讨论分支
应该位于图像旁边的一组文本。
.div表{
显示:表格单元格;
边框:1px纯黑;
}
.div单元{
显示:表格单元格;
填充物:5px;
垂直对齐:中间对齐;
}
.分区行{
显示:表格行;
垂直对齐:中间对齐;
}
讨论分支
应该位于图像旁边的一组文本
更多的文本,而且越来越多。
更多的文本。
讨论分支
应该位于图像旁边的一组文本。
如果您不需要支持IE9,它非常适合这种情况(现在非常流行)
如果您不需要支持IE9,那么它非常适合这种情况(现在非常流行)
如果您不需要支持IE9,那么它非常适合这种情况(现在非常流行)
如果您不需要支持IE9,那么它非常适合这种情况(现在非常流行)
我建议使用display:table和display:table cell,这是几乎所有浏览器中最受支持的布局
<style>
#Branching {display: table;}
#Branching .RightCenteredText{
display: table-cell;
text-align: center;
vertical-align: middle;
}
#Branching .LeftBoundPic {display: table-cell;}
#ContentHubs {display: table;}
#ContentHubs .LeftCenteredText{
display: table-cell;
text-align: center;
vertical-align: middle;
}
#ContentHubs .RightBoundPic {display: table-cell;}
</style>
<div id="Segment2">
<h2>Fig Tree is a discussion tool that helps organizations innovate</h2>
<h3>We took the basics of a discussion thread and added...</h3>
<div id="Branching">
<section class=LeftBoundPic>
<h4>Discussion Branching</h4>
<img src="SomePhoto.png" alt="FigTree"/>
</section>
<span class="RightCenteredText">
Bunch of text <br>
that should be next to the image.
</span>
</div>
<div id="ContentHubs">
<span class="LeftCenteredText">
More text that should <br>
be on the left of the photo now.
</span>
<section class=RightBoundPic>
<h4>Content Hub</h4>
<img src="SomePhoto.png" alt="FigTree"/>
</section>
</div>
</div>
#分支{显示:表;}
#分支。RightCenteredText{
显示:表格单元格;
文本对齐:居中;
垂直对齐:中间对齐;
}
#分支.LeftBoundPic{display:table cell;}
#ContentHubs{display:table;}
#ContentHubs.LeftCenteredText{
显示:表格单元格;
文本对齐:居中;
垂直对齐:中间对齐;
}
#ContentHubs.RightBoundPic{display:table cell;}
Fig Tree是一个帮助组织创新的讨论工具
我们学习了讨论主题的基础知识,并添加了。。。
讨论分支
一堆文本
应该在图像旁边。
更多应该
现在在照片的左边。
内容中心
至少在所有浏览器开始支持css3 flex和flex-box布局之前,我们可以使用它。我建议使用display:table和display:table cell,这是几乎所有浏览器中最受支持的布局
<style>
#Branching {display: table;}
#Branching .RightCenteredText{
display: table-cell;
text-align: center;
vertical-align: middle;
}
#Branching .LeftBoundPic {display: table-cell;}
#ContentHubs {display: table;}
#ContentHubs .LeftCenteredText{
display: table-cell;
text-align: center;
vertical-align: middle;
}
#ContentHubs .RightBoundPic {display: table-cell;}
</style>
<div id="Segment2">
<h2>Fig Tree is a discussion tool that helps organizations innovate</h2>
<h3>We took the basics of a discussion thread and added...</h3>
<div id="Branching">
<section class=LeftBoundPic>
<h4>Discussion Branching</h4>
<img src="SomePhoto.png" alt="FigTree"/>
</section>
<span class="RightCenteredText">
Bunch of text <br>
that should be next to the image.
</span>
</div>
<div id="ContentHubs">
<span class="LeftCenteredText">
More text that should <br>
be on the left of the photo now.
</span>
<section class=RightBoundPic>
<h4>Content Hub</h4>
<img src="SomePhoto.png" alt="FigTree"/>
</section>
</div>
</div>
#分支{显示:表;}
#分支。RightCenteredText{
显示:表格单元格;
文本对齐:居中;
垂直对齐:中间对齐;
}
#分支.LeftBoundPic{display:table cell;}
#ContentHubs{display:table;}
#ContentHubs.LeftCenteredText{
显示:表格单元格;
文本对齐:居中;
垂直对齐:中间对齐;
}
#ContentHubs.RightBoundPic{display:table cell;}
Fig Tree是一个帮助组织创新的讨论工具
我们学习了讨论主题的基础知识,并添加了。。。
讨论分支
一堆文本
应该在图像旁边。
更多应该
现在在照片的左边。
内容中心
至少在所有浏览器开始支持css3 flex和flex-box布局之前,我们可以使用它。我建议使用display:table和display:table cell,这是几乎所有浏览器中最受支持的布局
<style>
#Branching {display: table;}
#Branching .RightCenteredText{
display: table-cell;
text-align: center;
vertical-align: middle;
}
#Branching .LeftBoundPic {display: table-cell;}
#ContentHubs {display: table;}
#ContentHubs .LeftCenteredText{
display: table-cell;
text-align: center;
vertical-align: middle;
}
#ContentHubs .RightBoundPic {display: table-cell;}
</style>
<div id="Segment2">
<h2>Fig Tree is a discussion tool that helps organizations innovate</h2>
<h3>We took the basics of a discussion thread and added...</h3>
<div id="Branching">
<section class=LeftBoundPic>
<h4>Discussion Branching</h4>
<img src="SomePhoto.png" alt="FigTree"/>
</section>
<span class="RightCenteredText">
Bunch of text <br>
that should be next to the image.
</span>
</div>
<div id="ContentHubs">
<span class="LeftCenteredText">
More text that should <br>
be on the left of the photo now.
</span>
<section class=RightBoundPic>
<h4>Content Hub</h4>
<img src="SomePhoto.png" alt="FigTree"/>
</section>
</div>
</div>
#分支{显示:表;}
#分支。RightCenteredText{
<style>
#Branching {display: table;}
#Branching .RightCenteredText{
display: table-cell;
text-align: center;
vertical-align: middle;
}
#Branching .LeftBoundPic {display: table-cell;}
#ContentHubs {display: table;}
#ContentHubs .LeftCenteredText{
display: table-cell;
text-align: center;
vertical-align: middle;
}
#ContentHubs .RightBoundPic {display: table-cell;}
</style>
<div id="Segment2">
<h2>Fig Tree is a discussion tool that helps organizations innovate</h2>
<h3>We took the basics of a discussion thread and added...</h3>
<div id="Branching">
<section class=LeftBoundPic>
<h4>Discussion Branching</h4>
<img src="SomePhoto.png" alt="FigTree"/>
</section>
<span class="RightCenteredText">
Bunch of text <br>
that should be next to the image.
</span>
</div>
<div id="ContentHubs">
<span class="LeftCenteredText">
More text that should <br>
be on the left of the photo now.
</span>
<section class=RightBoundPic>
<h4>Content Hub</h4>
<img src="SomePhoto.png" alt="FigTree"/>
</section>
</div>
</div>