css制作一个网页,分左右两部分,左边固定,右边可滑动
时间: 2023-07-04 12:24:56 浏览: 112
可以使用CSS的`float`属性实现左右两部分的布局。左边部分设置`float: left; width: 固定宽度;`,右边部分设置`overflow-y: scroll;`属性,可实现右边部分可滑动。
HTML代码示例:
```
<div class="wrapper">
<div class="left">
左边固定部分
</div>
<div class="right">
右边可滑动部分
</div>
</div>
```
CSS代码示例:
```
.wrapper {
width: 100%;
overflow: hidden;
}
.left {
float: left;
width: 200px;
}
.right {
overflow-y: scroll;
}
```
相关问题
用html与css写一个左右各自滑动的网页
非常感谢您的提问!以下是一个简单的 HTML 和 CSS 代码示例,可以实现左右各自滑动的网页:
```html
<!DOCTYPE html>
<html>
<head>
<title>左右滑动网页</title>
<style>
body {
margin: 0;
padding: 0;
overflow-x: hidden;
}
.container {
display: flex;
flex-wrap: nowrap;
overflow-x: auto;
scroll-snap-type: x mandatory;
scroll-behavior: smooth;
height: 100vh;
}
.section {
flex: 0 0 100%;
height: 100vh;
scroll-snap-align: start;
background-color: #f2f2f2;
display: flex;
align-items: center;
justify-content: center;
font-size: 3rem;
font-weight: bold;
}
.section:nth-child(even) {
background-color: #ccc;
}
</style>
</head>
<body>
<div class="container">
<div class="section">左侧内容</div>
<div class="section">右侧内容</div>
</div>
</body>
</html>
```
这个网页使用了 Flexbox 布局和 CSS 的滚动特性来实现左右滑动。其中,`.container` 元素使用了 `display: flex` 和 `flex-wrap: nowrap` 属性来让两个 `.section` 元素排成一行,并且不换行。`.container` 元素还使用了 `overflow-x: auto` 属性来让它可以水平滚动,而 `scroll-snap-type: x mandatory` 和 `scroll-behavior: smooth` 属性则让滚动更加平滑和自然。
每个 `.section` 元素都占据整个视口的高度,并且使用了 `scroll-snap-align: start` 属性来让它们在滚动时自动对齐。左侧和右侧的 `.section` 元素分别使用了不同的背景颜色来区分。
希望这个示例能够帮助您实现左右滑动的网页!
css左边固定右边自适应
可以使用CSS中的float属性和width属性来实现左边固定,右边自适应的效果。
示例代码如下:
```html
<div class="container">
<div class="left">左边固定</div>
<div class="right">右边自适应</div>
</div>
```
```css
.container {
overflow: hidden; /* 防止浮动元素溢出 */
}
.left {
float: left;
width: 200px; /* 左边固定宽度 */
}
.right {
margin-left: 200px; /* 右边距离左边200px */
}
```
这样,左边的元素就会固定在页面左侧,而右边的元素会自适应填充剩下的宽度。