Html 文本区域旁边的中心div

Html 文本区域旁边的中心div,html,css,textarea,center,vertical-alignment,Html,Css,Textarea,Center,Vertical Alignment,如何将文本居中放置在文本区域旁边? 谢谢大家! 您可以使用Javascript获取textarea的高度,并更新右侧的行高度,将text align设置为居中您可以使用Javascript获取textarea的高度,并更新右侧的行高度,将text align设置为居中纯css 这可能对您有用: <html> <head> <title> </title> <style type="text/css">

如何将文本居中放置在文本区域旁边?


谢谢大家!

您可以使用Javascript获取textarea的高度,并更新右侧的行高度,将text align设置为居中

您可以使用Javascript获取textarea的高度,并更新右侧的行高度,将text align设置为居中

纯css

这可能对您有用:

<html>
<head>
    <title>

    </title>
    <style type="text/css">
        /* style here */

        div#main{
            position:relative;
            vertical-align:middle;
        }

        textarea{
        }

        div.right{
            position:absolute;
            top:45%;
            right:0px;
            width: 100px;
        }
    </style>

</head>
<body>
    <div id="main">
        <textarea></textarea>
        <div class="right">
            TEXT
        </div>
    </div>
</body>
</html>

/*这里的风格*/
主分区{
位置:相对位置;
垂直对齐:中间对齐;
}
文本区{
}
右分区{
位置:绝对位置;
最高:45%;
右:0px;
宽度:100px;
}
正文
JavaScript解决方案:

这可能对您有用:

<html>
<head>
    <title>

    </title>
    <style type="text/css">
        /* style here */

        div#main{
            position:relative;
            vertical-align:middle;
        }

        textarea{
        }

        div.right{
            position:absolute;
            top:45%;
            right:0px;
            width: 100px;
        }
    </style>

</head>
<body>
    <div id="main">
        <textarea></textarea>
        <div class="right">
            TEXT
        </div>
    </div>
</body>
</html>

让我知道它是否奏效

<script type="text/javascript">

        jQuery(document).ready(function(){
           // set init (default) state   
           var t = jQuery('#text_area');

           t.data('x', t.outerWidth());
           t.data('y', t.outerHeight());

           t.mouseup(function(){
              var th = jQuery(this);
              if (th.outerWidth()!= th.data('x') || th.outerHeight() != th.data('y'))

              // set new height/width
              th.data('x', th.outerWidth());
              th.data('y', th.outerHeight());
              $("#center_text").css("margin-top", (th.outerHeight()/2 - 20) + "px");
           });


        });
</script>

jQuery(文档).ready(函数(){
//设置初始(默认)状态
var t=jQuery(“#text_area”);
t、 数据('x',t.外径());
t、 数据('y',t.outerHeight());
t、 mouseup(函数(){
var th=jQuery(this);
if(th.outerWidth()!=th.data('x')| | th.outerHeight()!=th.data('y'))
//设置新的高度/宽度
th.data('x',th.outerWidth());
th.data('y',th.outerHeight());
$(“#中间#text”).css(“页边空白顶部”,(th.outerHeight()/2-20)+“px”);
});
});
纯css

这可能对您有用:

<html>
<head>
    <title>

    </title>
    <style type="text/css">
        /* style here */

        div#main{
            position:relative;
            vertical-align:middle;
        }

        textarea{
        }

        div.right{
            position:absolute;
            top:45%;
            right:0px;
            width: 100px;
        }
    </style>

</head>
<body>
    <div id="main">
        <textarea></textarea>
        <div class="right">
            TEXT
        </div>
    </div>
</body>
</html>

/*这里的风格*/
主分区{
位置:相对位置;
垂直对齐:中间对齐;
}
文本区{
}
右分区{
位置:绝对位置;
最高:45%;
右:0px;
宽度:100px;
}
正文
JavaScript解决方案:

这可能对您有用:

<html>
<head>
    <title>

    </title>
    <style type="text/css">
        /* style here */

        div#main{
            position:relative;
            vertical-align:middle;
        }

        textarea{
        }

        div.right{
            position:absolute;
            top:45%;
            right:0px;
            width: 100px;
        }
    </style>

</head>
<body>
    <div id="main">
        <textarea></textarea>
        <div class="right">
            TEXT
        </div>
    </div>
</body>
</html>

让我知道它是否奏效

<script type="text/javascript">

        jQuery(document).ready(function(){
           // set init (default) state   
           var t = jQuery('#text_area');

           t.data('x', t.outerWidth());
           t.data('y', t.outerHeight());

           t.mouseup(function(){
              var th = jQuery(this);
              if (th.outerWidth()!= th.data('x') || th.outerHeight() != th.data('y'))

              // set new height/width
              th.data('x', th.outerWidth());
              th.data('y', th.outerHeight());
              $("#center_text").css("margin-top", (th.outerHeight()/2 - 20) + "px");
           });


        });
</script>

jQuery(文档).ready(函数(){
//设置初始(默认)状态
var t=jQuery(“#text_area”);
t、 数据('x',t.外径());
t、 数据('y',t.outerHeight());
t、 mouseup(函数(){
var th=jQuery(this);
if(th.outerWidth()!=th.data('x')| | th.outerHeight()!=th.data('y'))
//设置新的高度/宽度
th.data('x',th.outerWidth());
th.data('y',th.outerHeight());
$(“#中间#text”).css(“页边空白顶部”,(th.outerHeight()/2-20)+“px”);
});
});
试试这个

<div style="display:table">     
    <label for="textarea">Description</label><br>  
    <textarea id="textarea" style="display: table-cell;"></textarea>
    <div style="vertical-align: middle; display: table-cell; width:100px; text-align:center; border:#f00 1px solid;">Text</div>
</div>

说明
正文
另外,请签入尝试使用此选项

<div style="display:table">     
    <label for="textarea">Description</label><br>  
    <textarea id="textarea" style="display: table-cell;"></textarea>
    <div style="vertical-align: middle; display: table-cell; width:100px; text-align:center; border:#f00 1px solid;">Text</div>
</div>

说明
正文

另外,请登录

您能否给出您想要实现的目标的图像?谢谢:)@shub查看更新的answer@shub-是为你工作吗?-不,对不起,这对我不起作用。它使文本水平居中,而不是垂直居中。@Umer Hayat我上传了一张图片。你能给出一张你想要实现的图片吗?谢谢:)@shub查看更新的answer@shub-是为你工作吗?-不,对不起,这对我不起作用。它使文本水平居中,而不是垂直居中。@Umer Hayat我上传了一张图片。谢谢你的帮助。我想有CSS的解决方案。有什么想法吗?嗨:)第一个解决方案实际上是纯CSS。谢谢你的帮助。我想有CSS的解决方案。有什么想法吗?嗨:)第一个解决方案实际上是纯CSS。