简体   繁体   English

我如何将一个div分为两个,用于在左侧显示文本,在右侧显示图像

[英]how i can divide one div on two, for display text on left, and image on right side

i want to "divide" my div on two, for displaying text on the left side, and image on right. 我想将我的div分为“两个”,以便在左侧显示文本,在右侧显示图像。 The div that is mentioned in topic about has an orange background color, and red line. 关于主题的div具有橙色背景色和红线。 It's just for show you, how it should look like. 只是为了向您展示它的外观。

HTML 的HTML

 #header { height: 100px; background-color: white; } .headerLinksClass { float: right; text-align: center; vertical-align: middle; line-height: 70px; padding: 15px; font-size: 20px; } #content { height: 300px; background-color: orange; font-size: 20px; } #aboutUs { background-color: red; height: 300px; } body { background-color: gray; } 
 <div id="header"> <div class="headerLinksClass">Lorem Ipsum</div> <div class="headerLinksClass">Lorem Ipsum</div> <div class="headerLinksClass">Lorem Ipsum</div> <div class="headerLinksClass">Lorem Ipsum</div> <div class="headerLinksClass">Lorem Ipsum</div> <div style="clear:both;"></div> </div> <div id="content"> <div id="AboutUs"> <h1>Lorem ipsum</h1> Lorem ipsum...</div> </div> 

它看起来像什么

Use flexbox. 使用flexbox。 Display flex for the parent div, create two children divs each of them with the flex property set to 1. 显示父级div的flex,创建两个子级div,并将其flex属性设置为1。

.wrapper {
    display: flex;
}

.block {
    flex: 1;
}

<div class=“wrapper>
    <div class=“block”>text</div>
    <div class=“block”>img</div>
</div>

Simplest way is to use divs and floats: 最简单的方法是使用div和float:

 * { box-sizing: border-box; } .container { max-width: 80%; } .one-half { float: left; width: 50%; border: 1px dashed red; } .one-half img { width: 100%; } @media screen and (max-width: 600px) { width: 100%; } 
 <div class="container"> <div class="one-half">Some stuff here lorem ipsum and a half</div> <div class="one-half"><img src="http://placehold.it/200x200"></div> </div> 

I think what you are wanting is best accomplished using a table. 我认为您想要的是使用表格最好地完成。

<div id = "content">
<table id ="AboutUs"><tr><td class="mytext"><h1>Lorem ipsum</h1> Lorem ipsum...</td></tr>
<tr><td class="mypic"><img src='...pic.jpg'></td></tr></table>
</div>

with some class to define the pictures width, etc. Also, make the table fit the containing div by setting width, height to 100% 用一些类来定义图片的宽度等。另外,通过将width,height设置为100%,使表格适合包含的div

.mytext{
    width:70%;
}
.mypic{
width: 30%;
/*other formatting you want here*/
/*the red line between pic and text*/
border-left-style: solid;
border-left-color: red;
}
#aboutUs{
background-color:red;
height:100%;
width: 100%;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将div分为两列(左侧和右侧) - How to divide div into two columns(left side and right side) 如何让一个文本显示在左侧,另一个显示在div的右侧 - how to have one piece of text display on left hand side and the other on the right hand side of a div 如何在html中显示图像以及左侧和文本右侧 - how to display image and left side and text right side in html 如果div是屏幕的中心,如何在底部左侧和右侧显示文本 - How to display the text left and right side at the bottom if div is the center of the screen 如何在html中一一显示两个div的右侧 - how to display two div's right side one by one in html 如何并排显示两个div,左div具有固定位置,右div具有垂直滚动 - how to display two divs side by side, left div with fixed position, right div having vertical scroll 我该如何定位两个 <div> ? 一个从左到右的引导程序模态? - How can I position two <div>? One from the left and one from the right of a bootstrap modal? 如何创建侧面(左侧或右侧)具有适当间距的图像 - How can I create an image with text on the side (left or right) with proper spacing in between 如何有两个div,父div的一个左侧和另一个右侧? - How to have two divs, one left side another right side of parent div? 如何为一个主要div使用一个背景图像,该背景有两个div,一个在左边,一个在右边 - How to use one background Image for a main div which have two div, one on left and one on right
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM