2015-01-19 4 views
0

나는 현재이 HTML을 가지고 :테두리에서 선을 그리려면 어떻게해야합니까?

#circle { 
 
    background-color: orange; 
 
    max-width: 40px; 
 
    margin-right: 20px; 
 
    margin-bottom: 20px; 
 
    min-width: 40px; 
 
    min-height: 40px; 
 
    font-size: 12px; 
 
    border-radius: 50%; 
 
    font-weight: bold; 
 
    text-align: center; 
 
    vertical-align: middle; 
 
    line-height: 40px; 
 
    float:left; 
 
} 
 
#innerContent { 
 
    border: solid 2px black; 
 
    padding: 3px; 
 
} 
 
#pointerDiv{ 
 
    float:left; 
 
}
<div id="circle"><span id='innerContent'>123</span></div><div id='pointerDiv'>text goes here</div>

내가이 효과 달성하기 위해 노력하고있어 : 기본적으로

Desired effect

, 가리 키도록 경계에서가는 선을 요소를 설명하는 텍스트로 채울 수 있습니다. 어떻게해야합니까?

+0

을 그릴 수있는 CSS 경계 또는 SVG를 사용 할 수 있습니다 텍스트가 포함 된 요소? –

+0

Woops, 내 잘못. 결정된! – ohyeah

+0

줄이 항상 같은 길이가 될 수 있습니까 (또는) 텍스트를 포함하는 요소의 화면상의 위치가 다를 수 있습니까? – Harry

답변

2

가 아래 필요 절대적 위치이어서 가상 요소를 사용하여 달성 한 샘플링 방법이다.

그래서도를 margin-right가 (난 그냥 그림에 대한 대답 50 픽셀하는 문제의 20 픽셀에서 그것을 수정했다) 50 픽셀이 + 상자의 테두리 원 내부에 몇 픽셀이며, 때문에 left: -58px에 대한 이유는 고려해야 만했다. 라인의 widthleft 값보다 작아서 pointerDiv 직전의 라인 끝을 만듭니다.

#circle에 추가했다는 점에 유의하십시오. 이러한 경우 더 많은 항목을 하나씩 추가하려고합니다. 필요하지 않은 경우 제거 할 수 있습니다. 어디

#circle { 
 
    background-color: orange; 
 
    max-width: 40px; 
 
    margin-right: 50px; 
 
    margin-bottom: 20px; 
 
    min-width: 40px; 
 
    min-height: 40px; 
 
    font-size: 12px; 
 
    border-radius: 50%; 
 
    font-weight: bold; 
 
    text-align: center; 
 
    vertical-align: middle; 
 
    line-height: 40px; 
 
    float: left; 
 
    clear: both; 
 
} 
 
#innerContent { 
 
    border: solid 2px black; 
 
    padding: 3px; 
 
} 
 
#pointerDiv { 
 
    float: left; 
 
    position: relative; 
 
    height: 40px; 
 
    line-height: 40px; 
 
} 
 
#pointerDiv:before { 
 
    content: ''; 
 
    position: absolute; 
 
    border: 1px solid black; 
 
    top: 50%; 
 
    left: -58px; 
 
    width: 55px; 
 
}
<div id="circle"><span id='innerContent'>123</span> 
 
</div> 
 
<div id='pointerDiv'>text goes here</div> 
 

 
<div id="circle"><span id='innerContent'>123</span> 
 
</div> 
 
<div id='pointerDiv'>some lengthy text goes here</div> 
 

 
<div id="circle"><span id='innerContent'>123</span> 
 
</div> 
 
<div id='pointerDiv'>short txt</div>

+1

내 상황에 대한 설정하기 전에 pointerDiv adjusing 비트를 가져 갔지만, 지금은 대단한 감사합니다! – ohyeah

1

항상 의사 요소를 사용할 수 있습니까? I은 기본 모형 아래 만들었다 :

.circle { 
 
    height: 55px; 
 
    width: 55px; 
 
    border-radius: 50%; 
 
    background: orange; 
 
    position: relative; 
 
    display: inline-block; 
 

 
} 
 
.circle:before { 
 
    position: absolute; 
 
    content: "hi"; 
 
    height: 60%; 
 
    top: 20%; 
 
    left: 20%; 
 
    width: 60%; 
 
    border: 2px solid black; 
 
} 
 
.circle:after { 
 
    position: absolute; 
 
    content: ""; 
 
    width: 100%; 
 
    right: -85%; 
 
    top: 50%; 
 
    border-bottom: 1px solid black; 
 
} 
 
.tooltip { 
 
    display: inline-block; 
 
    margin-left: 55px; 
 
    height: 60px; 
 
    width:60px; 
 
} 
 
.wrapper{ 
 
    display:block; 
 
    }
<div class="wrapper"> 
 
    <div class="circle"></div> 
 
    <div class="tooltip">text goes here</div> 
 
</div>

+1

거의 비슷한 아이디어가 짝을 지니지 만, OP는 단 하나의 대답 만 허용 할 수 있으므로 귀하의 노력에 보상을 원합니다. 비슷한 생각에 대해 동정심이 많지만 상호간의 감사로 간주하지 마십시오. – Harry

+1

@ 해리 : 우리의 대답은 대부분 비슷합니다 (어쨌든 대부분의 경우). 그래서 보통 사이에 게시물에 가장 빠른 답변, 글쎄, 당신이 날 웹 티키와 chipChocolate.py : P – jbutler483

2

당신은 라인 (일부 브라우저와 호환되지 않을 수 있습니다)

#circle { 
 
    background-color: orange; 
 
    max-width: 40px; 
 
    margin-bottom: 20px; 
 
    min-width: 40px; 
 
    min-height: 40px; 
 
    font-size: 12px; 
 
    border-radius: 50%; 
 
    font-weight: bold; 
 
    text-align: center; 
 
    vertical-align: middle; 
 
    line-height: 40px; 
 
    float: left; 
 
} 
 
#innerContent { 
 
    border: solid 2px black; 
 
    padding: 3px; 
 
} 
 
#pointerDiv { 
 
    float: left; 
 
    line-height: 40px; 
 
} 
 
#line-svg { 
 
    float: left; 
 
    margin-top: 20px; 
 
    margin-left: -6px; 
 
    width: 100px; 
 
}
<div id="circle"><span id='innerContent'>123</span> 
 
</div> 
 
<svg id="line-svg"> 
 
    <line x1="0" y1="0" x2="100%" y2="0" style="stroke:rgb(0,0,0);stroke-width:4" /> 
 
</svg> 
 
<div id='pointerDiv'>text goes here</div>

+0

재미있는 대답, 감사합니다! 그러나, 나는 오히려 호환성 이유로 CSS를 사용하고 싶습니다. – ohyeah

+0

SVG는 CSS3와 매우 흡사하여 예전의 학교와 잘 어울립니다. – Jaay

+0

좋은 대안 아이디어 :) – Harry

관련 문제