나는 CSS를 처음 접했고 폭이 다른 스팬 요소가 있습니다. 즉, 길이가 다른 내용이 있습니다 (예 : 9,56 및 90). 매번 선택 요소와 스팬 요소의 중심이 일치하는지 확인하고 싶습니다.
참고 : 미래에는 각 경우마다 다양한 길이의 범위를 가질 수 있으며 선택 및 범위의 중심이 자동으로 일치하기를 원합니다.
현재 내가 가지고있는 것
.floatright {
position: absolute;
width: 500px;
height:500px;
right:0px;
top:0px;
}
select {
text-indent: 140px !important;
}
select option {
font-weight: bold !important;
}
<!DOCTYPE html>
<head>
<title>Test</title>
</head>
<body>
<div class="floatright">
<select style="width:320px;">
<option>class 1</option>
<option>class 2</option>
<option>class 1</option>
<option>class 2</option>
<option>class 1</option>
<option>class 2</option>
</select>
<div>
<span>jefsyadlmu</span>
<br />
<br />
<br />
<br />
<span>uirkvcnyuimuamjkznvuozaeff</span>
<br />
<br />
<br />
<br />
<span>inwulpbkmnthllkpwdeygewehnpxaearnbmmzidtimcfvzrvwjfpodkinhybsneirbi</span>
<br />
<br />
<br />
<br />
</div>
</div>
<link rel="stylesheet" href="test.css"/>
</body>
</html>
div{text-align:center;}
CSS에 추가 하기 만하면 됩니다.
그러나 귀하의 HTML은 매우 잘못되었습니다. 당신이 사용 안하고 <span>
와 <br>
이를 달성하기 위해, 그것은 훨씬 더 사용하는 것 <p>
'대신이야. 이렇게하면 문장 사이의 공간으로 원하는 픽셀 수를 정확하게 정의 할 수도 있습니다.
.floatright {
position: absolute;
width: 500px;
height:500px;
right:0px;
top:0px;
}
select {
text-indent: 140px !important;
}
select option {
font-weight: bold !important;}
div { text-align:center;}
p {margin-bottom:40px;}
<!DOCTYPE html>
<head>
<title>Test</title>
</head>
<body>
<div class="floatright">
<select style="width:320px;">
<option>class 1</option>
<option>class 2</option>
<option>class 1</option>
<option>class 2</option>
<option>class 1</option>
<option>class 2</option>
</select>
<div>
<p>jefsyadlmu</p>
<p>uirkvcnyuimuamjkznvuozaeff</p>
<p>inwulpbkmnthllkpwdeygewehnpxaearnbmmzidtimcfvzrvwjfpodkinhybsneirbi</p>
</div>
</div>
<link rel="stylesheet" href="test.css"/>
</body>
</html>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다