[英]CSS Textarea and Div side by side
I'm trying to get my textarea and div to be side by side and have the run button underneath but I'm not sure why it isn't working. 我试图让我的textarea和div并排放置,并且在下面有运行按钮,但是我不确定为什么它不起作用。
The output looks like this: 输出看起来像这样:
http://codeeplus.net/test.php http://codeeplus.net/test.php
CSS: CSS:
.CodeMirror { height: 400px; width: 500px; border: 1px solid #ddd; }
.CodeMirror-scroll { max-height: 400px; }
.CodeMirror pre { padding-left: 7px; line-height: 1.25; }
#drawing { border: 1px solid #555555; float:left; width:480px; height: 400px; }
HTML: HTML:
<div style="position: absolute; left: 10px; top: 10px; padding: 10px; width:50%; height: 50%; border: 1px solid #000000;">
<div style="float:left">
<textarea align="left" style="overflow:auto;" id="demotext" name="textarea">
<html>
<head>
<title>Learning HTML</title>
</head>
<body>
<p>I'm learning HTML! This is my first line of code!</p>
</body>
</html></textarea>
</div>
<div style="float:left;">
<div id="drawing" style="text-align:left;padding:10px;"></div>
</div>
<input type="button" id="run" value="Run" />
</div>
I would use two div's one to wrap around your text area and one to wrap around your other div. 我将使用两个div来环绕您的文本区域,使用一个div来环绕您的另一个div。 This way you can just use
float: left;
这样,您可以只使用
float: left;
to put them both side by side :) 将它们并排放置:)
You should use display: inline-block;
您应该使用
display: inline-block;
property here, on the elements you want to align in one line 属性,在您要对齐的元素上
div {
display:inline-block;
}
The default value for div tags is display:block;
div标签的默认值为
display:block;
I have checked your page. 我已经检查过您的页面。 The div that you're trying to alight in is not aligning, because your parent div has
width:50%
and it's simply not fitting in there. 您尝试下移的div没有对齐,因为您的父div的
width:50%
并且根本不适合该区域。 Try changing it to, let's say widht:100%
and see that it really works! 尝试将其更改为,例如
widht:100%
,看看它确实有效!
Also remember, that if you use padding , as you apparently do on your page, it's affecting the actual (final) width of the element. 还要记住,如果您使用padding ,就像您在页面上所做的那样,它会影响元素的实际(最终) 宽度 。 For example, if you set the parent div 's
width: 1200px
and padding as padding:10px;
例如,如果您将父div的
width: 1200px
设置为width: 1200px
, 填充设置为padding:10px;
, then the actual div's size will be 1160px
, cutting 10px
on each side. ,则实际div的大小将为
1160px
, 1160px
减少10px
。
your code seems have many problems :), I made some changes: 您的代码似乎有很多问题:),我进行了一些更改:
float:left;
float:left;
from div
s div
s display:inline-block;
display:inline-block;
clear:both
tag before button
button
之前添加clear:both
标签 width:50%;
width:50%;
and height:50%
form first div
height:50%
形态第一div
look at new HTML: 查看新的HTML:
<div style="position: absolute; left: 10px; top: 10px; padding: 10px; border: 1px solid #000000;">
<div style="display:inline-block; vertical-align:top;">
<textarea align="left" style="overflow:auto;" id="demotext" name="textarea">
<head>
<title>Learning HTML</title>
</head>
<body>
<p>I'm learning HTML! This is my first line of code!</p>
</body>
</textarea>
</div>
<div style="display:inline-block">
<div id="drawing" style="text-align:left;padding:10px;"></div>
</div>
<div style="clear:both"></div>
<input type="button" id="run" value="Run" />
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.