html - 我将如何更改元素的内容溢出

标签 html css twitter-bootstrap

我想做什么?

我为我的文本区域创建了一个自定义页脚。并想改变我的文本区域的内容溢出。这样文本就永远不会超出我的文本区域的页脚。

https://imgur.com/hOfqRQ7

正如您在图片中看到的那样,文本超出了我的文本区域的页脚(水平线是页脚开始的地方)。我将如何防止它?这样文本在到达页脚之前就开始溢出。

我的代码:

#message textarea {
  resize: none;
  min-height: 250px;
  padding-bottom: 45px;
  overflow: hidden;
}

#sendMsg #separator hr {
  margin-top: -35px;
}

#sendMsg #contactFormBtn,
#showContactErrMsg {
  position: absolute;
  margin-top: -30px;
}

#sendMsg #showContactErrMsg {
  padding-left: 40px;
  font-size: 12px;
}

#showContactErrMsg {
  font-size: 14px;
  color: maroon;
  font-family: "Century Gothic";
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />

<div class="row" id="message">
  <div class="col-xs-offset-1 col-xs-10">
    <div class="form-group">
      <label class="formLabel"><i class="fa fa-sticky-note-o"></i> Message </label>
      <textarea class="form-control" class="formInput" id='inputContactMsg'></textarea>
      <div class="row" id='sendMsg'>
        <div class="row" id='separator'>
          <div class="col-xs-offset-2 col-xs-8">
            <hr style="height: 0.5px; background-color: silver;">
          </div>
        </div>
        <div class="col-xs-8">
          <strong id='showContactErrMsg'></strong>
        </div>
        <div class="col-xs-4">
          <button type="submit" id='contactFormBtn'>Send</button>
        </div>
      </div>
    </div>
  </div>
</div>

最佳答案

#message textarea 中更改以下代码

max-height: 250px; /*max instead of min*/
overflow: auto;/*scroll or auto instead of hidden*/

一旦高度达到您的设定值,这将强制您的文本区域滚动。

希望这有帮助:)

#message textarea { 
		resize: none; 
		max-height: 250px; /*change this to max*/
		padding-bottom: 45px; 
		overflow: auto;/*change this to scroll*/
    height: 90px;
    width: 100%;
    border: none;
}
 
#message textarea:focus{
  border: none;
  outline: none;
}

#sendMsg #separator hr { 
  margin-top: -35px; 
}

#sendMsg #contactFormBtn, #showContactErrMsg { 
  position: absolute; 
  margin-top: -30px; 
}

#sendMsg #showContactErrMsg { 
  padding-left: 40px; 
  font-size: 12px;
}

#showContactErrMsg { 
  font-size: 14px; 
  color: maroon; 
  font-family: "Century Gothic"; 
}
  
div .extra {
  height: 130px;
  display: block;
  overflow: auto;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

<div class="row" id="message">
  <div class="col-xs-offset-1 col-xs-10">
    <div class="form-group">
      <label class="formLabel"><i class="fa fa-sticky-note-o"></i> Message         </label>
      <div class="extra form-control">
        <textarea class="" class="formInput" id='inputContactMsg'></textarea>
      </div>
      <div class="row" id='sendMsg'>
      <div class="row" id='separator'>
      <div class="col-xs-offset-2 col-xs-8">
        <hr style="height: 0.5px; background-color: silver;">
      </div>
    </div>
    <div class="col-xs-8">
      <strong id='showContactErrMsg'></strong>
    </div>
    <div class="col-xs-4">
      <button type="submit" id='contactFormBtn'>Send</button>
    </div>
    </div>
    </div>
  </div>
</div>

编辑:将 textarea 添加到一个 div 中并赋予它 class="extra"。

关于html - 我将如何更改元素的内容溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48381859/

相关文章:

javascript - 当我在 slider 末尾时如何禁用单击按钮

javascript - Perl CGI,多个表单和多个提交按钮,在同一页面上执行操作

html - html表格的半边框

javascript - 将一个 div 放置在另一个具有动态宽度的 div 的右侧并防止其超出屏幕

javascript - Bootstrap Material 设计 - 波纹不显示在弹出窗口中

html - 在 Bootstrap 4 上更改下拉图标

html - 由于某种原因未显示 Font Awesome 图标

Html 并排列出 - 正确的方法是什么?

javascript - 使用 CSS 防止页面滚动

ruby-on-rails - jQuery 更新后,Ruby on Rails/Twitter Bootstrap Popover 无法正常工作