Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
715 views
in Technique[技术] by (71.8m points)

html - css border-width percentage

I have one div wrapping another like so

<div id="container"><div id="box"></div></div>

Let's say the container has a dimension 100px by 100px. I want to box to have 0px height and 0px width. However, I want the left border of the box to fill up 50% of the container, and the right border of the box to fill up the the other 50% of the container.

How do I do this with css?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can do what you are after, but using linear-gradients instead of borders.

Use the following markup:

<div class="box"></div>?

And the following styles (example: http://jsfiddle.net/HxbnK/):

.box {
    background-image: linear-gradient(154deg, red 50%, transparent 50%),
                      linear-gradient(26deg, red 50%, transparent 50%);
    background-position: 0 0, 100% 0;
    background-repeat: no-repeat;
    background-size: 50% 100%;
    height: 100px;
    width: 100px;
}?

Just keep in mind that the .box element needs to be a square for this to work correctly.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...