[英]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.