我试图将我的 html 页面分成两列。一列应该由图像填充,另一列由文本填充。我面临以下问题:
列不占据确切的 50-50 宽度。
在图像开始之前,左边有一个细小的边距。需要删除那个边距。
两列之间存在巨大的差距。
如果有人可以查看此代码并提出更正建议,那将非常有帮助:
.container img {
width: 100%;
}
.thin-black-border {
border-color: black;
border-width: 05px;
border-style: solid;
}
.header {
font: 200 80px'Oleo Script', Helvetica, sans-serif;
color: #2b2b2b;
text-shadow: 4px 4px 0px rgba(0, 0, 0, 0.1);
}Run Code Online (Sandbox Code Playgroud)
<link href='http://fonts.googleapis.com/css?family=Oleo+Script' rel='stylesheet' type='text/css'>
<div style="width:100%; height: 100px;background-color:green" class="bg-faded">
<!-- Main Div -->
<h1 class="text-center header">Madhubala</h1>
</div>
<div style="float:left;width:50%;" class="container">
<img src="https://nehamalude.files.wordpress.com/2011/02/madhubala.jpg" class="thin-black-border" />
</div>
<div style="float:left; width:50%; background-color:red; ">
Right
</div>Run Code Online (Sandbox Code Playgroud)
您可以简单地使用 table :方法 1:
<table border="1">
<tr>
<td>You can add content here</td>
<td>You can add content here</td>
</tr>
</table>Run Code Online (Sandbox Code Playgroud)
方法二:
<div style="display:block; width:100%;">
<div style="width:50%; float: left; display: inline-block;">Your content</div>
<div style="width:50%; float: left; display: inline-block;">Your content</div>
</div>Run Code Online (Sandbox Code Playgroud)
方法 3(使用 Flex):
<div class="flexbox-container" style="display:flex;">
<div class="sidebar" style="flex:1;">Test column 1</div>
<div class="main" style="flex:1;">Test column 2</div>
</div>Run Code Online (Sandbox Code Playgroud)
body{
margin: 0;
padding: 0;
}
.container img {
width: 100%;
}
.thin-black-border {
border-color: black;
border-width: 05px;
border-style: solid;
}
.header {
font: 200 80px'Oleo Script', Helvetica, sans-serif;
color: #2b2b2b;
text-shadow: 4px 4px 0px rgba(0, 0, 0, 0.1);
}
.main-wrap{
display: flex;
flex-direction: row;
}
.main-wrap > div{
flex: 1;
}Run Code Online (Sandbox Code Playgroud)
<link href='http://fonts.googleapis.com/css?family=Oleo+Script' rel='stylesheet' type='text/css'>
<div style="width:100%; height: 100px;background-color:green" class="bg-faded">
<!-- Main Div -->
<h1 class="text-center header">Madhubala</h1>
</div>
<div class="main-wrap">
<div class="container">
<img src="https://nehamalude.files.wordpress.com/2011/02/madhubala.jpg" class="thin-black-border" />
</div>
<div style="background-color:red; ">
Right
</div>
</div>Run Code Online (Sandbox Code Playgroud)
使用怎么样display: flex?