css 如何扩大侧边栏?

y3bcpkx1  于 2023-06-25  发布在  其他
关注(0)|答案(1)|浏览(136)

我正在学习CSS,我想知道如何正确地扩展侧栏,因为Gestion des utilisateurs部分不在一行上。

关于信息,我通过Stackblitz创建了一个插图下面,也许它可以帮助你。
Example
下面是HTML/Angular的代码

<div class="sidebar" [class.sidebar-close]="!openSidebar">
  <div class="logo-details">
    <img src="assets/images/logo.png" />
  </div>
  <ul class="nav-links" id="nav-links">
    <li *ngFor="let item of menuSidebar" #itemEl routerLinkActive="active">
      <div *ngIf="item.sub_menu.length == 0" class="dropdown-title">
        <a [routerLink]="[item.link]">
          <i [class]="item.icon"></i>
          <span class="link_name">{{ item.link_name }}</span>
        </a>
      </div>
      <div
        *ngIf="item.sub_menu.length > 0"
        class="dropdown-title"
        (click)="showSubmenu(itemEl)"
      >
        <a>
          <i [class]="item.icon"></i>
          <span class="link_name">{{ item.link_name }}</span>
        </a>
        <i class="bx bxs-chevron-down arrow"></i>
      </div>
      <ul class="sub-menu" [class.blank]="item.sub_menu.length == 0">
        <li>
          <a class="link_name">{{ item.link_name }}</a>
        </li>
        <li *ngFor="let item_sub of item.sub_menu" routerLinkActive="active">
          <a [routerLink]="[item_sub.link]">{{ item_sub.link_name }}</a>
        </li>
      </ul>
    </li>
  </ul>
</div>
<section class="home-section">
  <div class="home-header">
    <div class="hamburger-menu">
      <input
        type="checkbox"
        id="checkbox-hamburger-menu"
        [(ngModel)]="openSidebar"
      />
      <label class="label-hamburger-menu" for="checkbox-hamburger-menu">
        <div class="bar"></div>
        <div class="bar"></div>
        <div class="bar"></div>
      </label>
    </div>
    <!-- Votre dernière connexion -->
    <span class="title">
      <h4 class="titleOne">Votre dernière connexion : 23/06/2023 11:41:05</h4>
    </span>
    <span class="title">
      <div class="container"></div>
    </span>
  </div>
  <div class="home-view">
    <router-outlet></router-outlet>
  </div>
</section>

这是CSS中的代码。

.home-section {
  position: relative;
  background: #f3f6f2;
  height: 100vh;
  left: 270px;
  width: calc(100% - 270px);
  transition: all 0.5s ease;
  display: flex;
  flex-direction: column;
}

.home-section .home-header {
  min-height: 120px;
  display: flex;
  align-items: center;
  background-color: #1b32b1;
  /* #bbe7aa */
}

.home-section .home-header .title {
  color: #fff;
  margin: 0 auto;
}

/* Sidebar */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 270px;
  background: #fff;
  z-index: 100;
  transition: all 0.5s ease;
}

.sidebar.sidebar-close {
  width: 60px;
}

.sidebar .logo-details {
  width: 100%;
  padding: 20px 10px;
  border-bottom: 1px solid #e0e0e0;
}

.sidebar .logo-details img {
  height: 78px;
  width: 65%;
  display: block;
  margin: 0 auto;
}

.sidebar .nav-links {
  height: 100%;
  width: 270px;
  padding-bottom: 150px;
  overflow: auto;
}

.sidebar .nav-links::-webkit-scrollbar {
  display: none;
}

.sidebar .nav-links li {
  list-style: none;
}

.sidebar .nav-links > li {
  position: relative;
  width: fit-content;
  border-bottom: 1px solid #ccc;
}

.sidebar .nav-links li:hover {
  background: #eaeaea;
}

/* Dropdown Title */

.sidebar .nav-links .dropdown-title {
  width: 270px; // 260px;
  overflow: hidden;
  transition: all 0.52s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
}

.sidebar.sidebar-close .nav-links .dropdown-title {
  width: 60px;
}

.sidebar .nav-links li i {
  height: 50px;
  min-width: 60px;
  text-align: center;
  line-height: 50px;
  color: #004a65;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.sidebar .nav-links li:hover i,
.sidebar .nav-links li.active i {
  color: #004a65;
}

.sidebar .nav-links li.showMenu i.arrow {
  transform: rotate(-180deg);
}

/* a Tag */

.sidebar .nav-links li a {
  display: flex;
  align-items: center;
  text-decoration: none;
  width: 100%;
}

/* Link Name */

.sidebar .nav-links li a .link_name,
.sidebar .nav-links li a .link_logout {
  font-size: 16px;
  font-weight: 600;
  color: #004a65;
  transition: all 0.4s ease;
}

.sidebar .nav-links li:hover a .link_name,
.sidebar .nav-links li.active a .link_name,
.sidebar .nav-links li:hover a .link_logout,
.sidebar .nav-links li.active a .link_logout {
  color: #004a65;
}

.sidebar.sidebar-close .nav-links li a .link_name,
.sidebar.sidebar-close .nav-links li a .link_logout {
  pointer-events: none;
}

/* Sub Menu */

.sidebar .nav-links li .sub-menu {
  background: #fff;
  display: none;
  transition: all 0.4s ease;
}

.sidebar .nav-links li.showMenu .sub-menu {
  display: block;
}

.sidebar .nav-links li .sub-menu a {
  color: #004a65;
  font-size: 13px;
  white-space: nowrap;
  transition: all 0.3s ease;
  padding: 7px 0px;
}

.sidebar .nav-links li .sub-menu li {
  padding-left: 10px;
}

.sidebar .nav-links li .sub-menu li:hover a,
.sidebar .nav-links li .sub-menu li.active a {
  color: green;
  font-size: 13px;
  font-weight: 600;
}

.sidebar .nav-links li .sub-menu li:hover {
  background: #e8f5f9;
}

.sidebar .nav-links li .sub-menu li:not(:first-child) {
  padding: 5px 60px;
  border-top: 1px solid #e0e0e0;
}

.sidebar .nav-links li .sub-menu li:last-child {
  padding: 5px 60px;
  border-top: 1px solid #e0e0e0;
}

.sidebar.sidebar-close .nav-links li .sub-menu {
  position: absolute;
  left: 100%;
  top: -10px;
  margin-top: 0;
  padding: 0;
  border-radius: 0 6px 6px 0;
  opacity: 0;
  display: block;
  pointer-events: none;
  transition: 0s;
  overflow: hidden;
}

.sidebar.sidebar-close .nav-links li .sub-menu li {
  padding: 6px 15px;
  width: 200px;
}

.sidebar.sidebar-close .nav-links li:hover .sub-menu {
  top: 0;
  opacity: 1;
  pointer-events: auto;
  transition: all 0.4s ease;
}

.sidebar .nav-links li .sub-menu .link_name,
.sidebar .nav-links li .sub-menu .link_logout {
  display: none;
}

.sidebar.sidebar-close .nav-links li .sub-menu .link_name,
.sidebar.sidebar-close .nav-links li .sub-menu .link_logout {
  font-size: 16px;
  font-weight: 600;
  display: block;
}

.sidebar.sidebar-close .nav-links li .sub-menu li:first-child {
  background: #fff;
  pointer-events: none;
}

.sidebar .nav-links li .sub-menu.blank {
  pointer-events: auto;
  opacity: 0;
  pointer-events: none;
}

.sidebar .nav-links li:hover .sub-menu.blank,
.sidebar .nav-links li.active .sub-menu.blank {
  top: 50%;
  transform: translateY(-50%);
}

.sidebar.sidebar-close ~ .home-section {
  left: 60px;
  width: calc(100% - 60px);
}

.sidebar.sidebar-close .logo-details img {
  width: 37px;
  height: 50px;
  transform: scale(1.2) translateX(-3px);
}

.wrapper-component {
  width: 95%;
  margin: 0 auto;
}

.titleOne {
  margin-top: 6px;
  margin-bottom: 10px;
}

.subtitle {
  margin-left: 5px;
  color: #e32319;
  // color: #E40808;
}

.portfolio {
  margin-top: 8px;
  margin-bottom: 10px;
}

.limit {
  font-weight: normal;
}

谢谢你的帮助和你的时间。

sxissh06

sxissh061#

在我看来,这是你需要增加的适用声明。.home-section的位置与.sidebar的宽度有关

.home-section {
  left: 270px;
}

.sidebar {
  width: 270px;
}

.sidebar .nav-links {
  width: 270px;
}

相关问题