2013-02-23 3 views
0

저는 HTML/CSS의 초보자입니다.하지만 고정 h1 요소를 중심에 배치하는 데 문제가 있습니다. 그것은 스스로를 중심에 두지 않고 페이지의 왼쪽에 붙어 있습니다. 나는 자동 여백을 설정하려고 시도했지만, 그것은 일을하지 않습니다. 어떻게해야합니까, 그래서고정 요소를 센터링하는 방법은 무엇입니까?

<!DOCTYPE html> 
<html> 
<head> 
    <link href="Fonts/stylesheet.css" rel="stylesheet" type="text/css"> 
    <title>Webpage</title> 
</head> 
<body> 
    <div id="navbar"></div> 
    <div class="sidebar"></div> 
    <h1>Hello World!</h1> 
</body> 
</html> 

:

h1 { 
color: #580101; 
font-family: RobotoRegular; 
position: fixed; 
text-align: center; 
} 

* { 
background-color: #ecebe9; 
} 

#navbar { 
color: #000653; 
background-color: #00001a; 
height: 40px; 
border-radius: 3px; 
} 

.sidebar { 
background-color: black; 
width: 90px; 
height: 500px; 
float: left; 
margin: 30px 0px 0px 0px; 
} 

그리고 HTML : 여기에 코드입니까?

+0

h1을 div.sidebar 옆에 가져 오려고합니까? h1은 divs 위의 thetwo 아래에 현재있을 것입니다 ...? – cliffbarnes

+0

아래쪽 투표에 대한 의견이 없습니까?!?!?! – cliffbarnes

답변

1

당신이 다음 h1 CSS 스타일에 대한 width: 100%; CSS 규칙을 추가 고정 된 위치를 사용하려면 position:relative로 변경 <h1>position:fixed.

기타 그냥 작동 할 position을 제거하십시오.

+0

그랬습니다. 감사! – user2101752

+0

@ user2101752 언제나 환영합니다 –

1

페이지 측면에 붙어있는 이유는 이름이 고정되어 있기 때문입니다. 당신은 '기본적으로'요소를 요구 한 경우 그 의미

을 만드는 경우에 당신은 당신이

<style> 
.test{ 
    position:fixed; 
    right:0; 
    left:0; 
    text-align:center; 
    background:#EEEEEE; 
</style> 
<h1 class="test">test</h1> 
-1

position를 사용하여, 그것은 위치의 지정 할 수있는, 고정 자유롭게 중앙에 떠있는 그것을 말할 수 없다. .. left, top 또는 right, bottom.

+0

어떻게 하시겠습니까? 예를 든다. – user2101752

관련 문제