用h5做一个精致完美的河南旅游宣传页面,包括流动图片导航栏、合理文字加图片布局、用户名和密码登录、热门内容栏等
时间: 2024-01-26 15:02:44 浏览: 71
纯h5+js-OCR图片文字提取
很好,这个项目需要用到HTML5、CSS3和JavaScript,我会给你提供一些思路和代码示例,帮助你完成这个页面。
首先,我们需要一个流动图片导航栏。可以使用CSS3的transition属性和定位来实现图片滑动的效果。代码示例如下:
```html
<div class="slider">
<img src="image1.jpg" alt="image1">
<img src="image2.jpg" alt="image2">
<img src="image3.jpg" alt="image3">
</div>
```
```css
.slider {
position: relative;
width: 800px;
height: 400px;
overflow: hidden;
}
.slider img {
position: absolute;
top: 0;
left: 0;
transition: transform 1s ease-in-out;
}
.slider img:nth-child(2) {
transform: translateX(100%);
}
.slider img:nth-child(3) {
transform: translateX(200%);
}
.slider:hover img {
transform: translateX(-100%);
}
```
接下来是合理文字加图片布局。可以使用flex布局和grid布局来实现自适应的页面布局。代码示例如下:
```html
<div class="container">
<div class="item">
<img src="image1.jpg" alt="image1">
<h3>Title 1</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
<div class="item">
<img src="image2.jpg" alt="image2">
<h3>Title 2</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
<div class="item">
<img src="image3.jpg" alt="image3">
<h3>Title 3</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
<div class="item">
<img src="image4.jpg" alt="image4">
<h3>Title 4</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</div>
```
```css
.container {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.item {
width: calc(25% - 20px);
margin-bottom: 20px;
text-align: center;
}
.item img {
width: 100%;
height: 200px;
object-fit: cover;
}
.item h3 {
font-size: 24px;
margin-top: 10px;
margin-bottom: 5px;
}
.item p {
font-size: 16px;
color: #666;
}
```
然后是用户名和密码登录。可以使用表单元素和JavaScript实现登录功能。代码示例如下:
```html
<form id="login-form">
<div>
<label for="username">Username:</label>
<input type="text" id="username" name="username">
</div>
<div>
<label for="password">Password:</label>
<input type="password" id="password" name="password">
</div>
<button type="submit">Login</button>
</form>
```
```javascript
const form = document.getElementById('login-form');
form.addEventListener('submit', function(event) {
event.preventDefault();
const username = form.elements.username.value;
const password = form.elements.password.value;
// validate username and password
if (username === 'admin' && password === 'password') {
alert('Login successful!');
} else {
alert('Invalid username or password!');
}
});
```
最后是热门内容栏。可以使用bootstrap的组件来实现,代码示例如下:
```html
<div class="container">
<div class="row">
<div class="col-md-3">
<h3>Hot Content 1</h3>
<img src="image1.jpg" alt="image1">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
<div class="col-md-3">
<h3>Hot Content 2</h3>
<img src="image2.jpg" alt="image2">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
<div class="col-md-3">
<h3>Hot Content 3</h3>
<img src="image3.jpg" alt="image3">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
<div class="col-md-3">
<h3>Hot Content 4</h3>
<img src="image4.jpg" alt="image4">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</div>
</div>
```
以上是一个简单的HTML5页面的示例,你可以根据需求进行修改和完善。
阅读全文