【发布时间】:2015-04-04 11:27:55
【问题描述】:
我目前正在制作我的个人网站,但在图像和小屏幕方面我遇到了困难。我基本上想将我的肖像图像放置在标题文本上方的屏幕中间,并在使用较小的屏幕尺寸时使其保持在那里。我已经尝试过 position: relative 和similar 解决方案,但我无法让它发挥作用。
我基本上想将它放在标题文本上方,并使其在使用不同的屏幕尺寸时自动缩放。我也希望它有一个固定的宽度和高度。
代码如下:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Oskar Yildiz</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/themes/smoothness/jquery-ui.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>
<link rel="stylesheet" href="main.css"
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<div id="wrapper">
<div id="bg" class="background-div">
</div>
<div id="header" class="container">
<div class="row">
<div class="col-xs-12">
<img class="img-circle" src="files/portraitcrop.jpg" />
<h1 id="main-title" class="page-title">Oskar Yildiz</h1>
<h2 class="page-description" style="font-style: normal;">
Welcome
</h2>
<h2 class="page-description">
Young tech enthusiant, web developer and content creator.
</h2>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$("#main-title").fadeIn();
</script>
CSS:
body {
margin: 0;
padding: 0;
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
font-weight: 300;
/*background-image: url("./files/bg.jpg");*/
}
.background-div {
background-image: url("./files/background.jpg");
width: 100%;
min-height: 100%;
background-repeat: no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
position: fixed;
top: 0;
left: 0;
display: table;
background-position: center;
-webkit-filter: blur(3px);
-moz-filter: blur(3px);
-o-filter: blur(3px);
-ms-filter: blur(3px);
filter: blur(3px);
}
#header {
display: table;
position: relative;
}
.page-title {
text-align: center;
text-transform: uppercase;
color: white;
margin-top: 330px;
font-size: 2em;
margin-bottom: 0px;
}
#header h2 {
margin: 0;
}
.page-description {
text-align: center;
color: white;
padding-top: 8px;
font-style: italic;
font-family: "Trebuchet MS", Helvetica, sans-serif;
font-size: 150%;
}
.portrait {
}
img {
padding: 0;
margin: 0;
min-height: 30%;
min-width: 30%;
}
.oskar {
width:100%;
height:100%;
background-size: cover;
display: table;
background: #222 no-repeat center center;
background-color: #222;
background-image: url("./files/bg.jpg");
}
【问题讨论】:
-
@AlexeyGorozhanov 但我不希望它覆盖整个屏幕。
-
“我基本上想把它放在标题文本上方,让它在使用不同的屏幕尺寸时自动缩放。我还希望它有固定的宽度和高度。”如果要自动缩放,图像的高度和宽度不可能相同。
-
@EddNewGate 好的,我明白了。但我的意思是,无论屏幕大小如何,它都会保持在同一个位置,并且不会固定在一个位置。
-
如果您希望图像在用户调整屏幕大小时保持在中间,只需在图像代码上输入这两个:'margin-left:auto'和'margin-right:auto'。而且,要小心你给它的位置。这仅适用于位置:相对或静态(默认)
标签: html css twitter-bootstrap