简体   繁体   中英

Centered image with a min-height and 100% width

I want to create a header image that is the background for part of the page. The requirements are as follows:

  • width: 100%
  • min-height: 400px
  • be below the header bar
  • be able to place text and/or an overlay on top of it
  • most importantly I want the image to be centered no matter the screen-size

There is a header bar above where I want the image and the rest of the page will proceed below the image. Basically trying to create the image as a background for the title of the page.

HTML for your pages:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>WebSite</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link href="style.css" rel="stylesheet" type="text/css" />

</head>
<body>
<div id="banner">Text floating over image goes here</div>

And then in the .css file, you describe id-"banner":

#banner {
height: 400px;
padding: 0;
background: #1d1e8a url(./images/website_banner.png) no-repeat;
color: #333;    
background-size: 100% 100%;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM