4

サンプルフォーム:

<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
* {font:13px arial; color:white;}
body {background:black;}
label {display:inline-block; width:50px;}
input, textarea {margin:0; border:1px solid red; padding:0; background:green;}
textarea {width:300px; height:100px;}
</style>
</head>
<body>
<form action="#">
<div><label for="entry_0">Name</label><input type="text" id="entry_0"></div>
<div><label for="entry_1">Email</label><input type="text" id="entry_1"></div>
<div><label for="entry_2">URL</label><input type="text" id="entry_2"></div>
<div id="parent"><textarea id="entry_3"></textarea></div>
<div><input type="submit" value="Submit"></div>
</form>
</body>
</html>

フォームスタイルと一致しないため、textareaスクロールバーを削除/非表示にします。jQueryプラグインを使用してスクロールバーのスタイルを設定できることは知っていますが、異なるブラウザー/システム間で確実に機能するわけではありません。スクロールバーを非表示にするために使用できますtextarea {width:300px; height:100px; overflow:hidden;}が、Firefoxがマウスとキーボードをスクロールするのを完全に停止します。また、次の回避策を試しました。

#parent {width:284px; height:102px; overflow:hidden;}
textarea {width:300px; height:100px; overflow-x:hidden; overflow-y:scroll;}

親の分割幅を計算するスクリプトを追加すると、正確に機能するはずです。

var textareaWidth = document.getElementById('entry_3').scrollWidth;
document.getElementById('parent').style.width = textareaWidth + 'px';

しかし、とにかく上記のアプローチはChrome/Safariでは機能しないようです。
デモ: http: //jsfiddle.net/RainLover/snTaP/

上記のデモをChrome/Safariで開きます>>テキストエリアにテキストを挿入します>>行を強調表示/選択し、マウスを右にドラッグすると、スクロールバーが表示されます。または、キーボードのキーPage Upとを使用しますPage Down

修正やその他の解決策はありますか?

4

1 に答える 1

1

ハッキーですが、うまくいくようです...

::after疑似要素を使用する

#parent {width:302px; overflow:hidden; position: relative;}
textarea {width:300px; height:100px; overflow-x:hidden; overflow-y:scroll;}
textarea:focus {
    outline-offset: 0;
    outline-style: none;
}

#parent::after {
    position: absolute;
    width: 17px;
    top: 0;
    right: 0px;
    height: 102px;
    border-left:1px solid red;
    background-color: black;
    content: "";
    display: block;   
}

http://jsfiddle.net/tarabyte/snTaP/3/

または追加のdivを使用する

HTML:

<div id="parent">
  <textarea id="entry_3"></textarea>
  <div id="hidescroll"></div>
</div>

CSS:

#parent {width:302px; overflow:hidden; position: relative;}
textarea {width:300px; height:100px; overflow-x:hidden; overflow-y:scroll;}
textarea:focus {
    outline-offset: 0;
    outline-style: none;
}
#hidescroll {
    position: absolute;
    width: 17px;
    top: 0;
    right: 0;
    z-index: 1000;
    height: 102px;
    border-left:1px solid red;
    background-color: black;
}

http://jsfiddle.net/tarabyte/snTaP/2/

于 2012-12-06T22:10:24.347 に答える