html浏览器右侧滚动条宽度,html – CSS:如何获取浏览器滚动条宽度? (for:hover {overflow:auto}很好的边距)...

我不确定标题是否清楚,所以解释的话很少.我有几个小元素,比方说div(200px x 400px CONSTANT).在每个内部,有一个段落有大约20行文本.当然,这对于一个可怜的小div来说更是如此.我想做的是:

>通常div有溢出:隐藏属性.

>鼠标悬停(:悬停)时,此属性更改为overflow:auto;,并显示滚动条.

问题是什么?我想在段落文本和滚动条之间留一点空间(填充或边距).假设段落具有对称边距:20px;.但之后:悬停触发器打开,滚动条出现,段落的整个右侧向左移动“滚动条宽度”px.句子在其他行中被打破,整个段落看起来不同,这非常烦人且不方便用户使用.我怎样才能设置我的CSS,所以悬停后唯一的变化就是scroolbar的外观?

换一种说法:

/* Normally no scrollbar */

div {display: block; width: 400px; height: 200px; overflow: hidden;}

/* On hover scrollbar appears */

div:hover {overflow: auto;}

/* Paragraph margin predicted for future scrollbar on div */

div p {margin: 20px (20px + scrollbarwidth px) 20px 50px;}

/* With scrollbar margin is symmetrical */

div:hover p {margin: 20px;} /* With scrollbar */

我已经为它做了一个小片段,我强烈地解释了我的问题.我希望一切都很清楚:).我现在正在寻找解决方案近两个小时,所以我认为我的问题非常独特和有趣.

div.demo1 {

width: 400px;

height: 200px;

overflow: hidden;

background: #ddd;

}

div.demo1:hover {

overflow: auto;

}

div.demo1 p {

background: #eee;

margin: 20px;

}

div.demo2 {

width: 400px;

height: 200px;

overflow: hidden;

background: #ddd;

}

div.demo2:hover {

overflow: auto;

}

div.demo2 p {

background: #eee;

margin: 20px 40px 20px 20px;

}

div.demo2:hover p {

margin: 20px 20px 20px 20px;

}

This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text.

This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text.

This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text.

This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text.

This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text.

As you can see,on hover right side of the paragraph "moves" left. But I want something like:

This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text.

This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text.

This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text.

This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text.

This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text. This is a long text.

But with a "perfect" scrollbar width (in this example I used 20px)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值