3

我正在尝试用左侧的图像在布尔玛制作一张水平卡片。我希望卡片边缘圆润,并具有与普通布尔玛卡片相同的响应属性。Bulma 目前不支持水平卡,但我偶然发现了这个 github 问题,人们试图让它工作。https://github.com/jgthms/bulma/pull/1596

我确实尝试过使用 css,但我无法创建一个可以工作的水平卡。这是我尝试的 HTML;

<div class="container is-fluid">
  <section class="section">
    <div class="container">
      <h1 class="title">Horizontal Card</h1>
    </div>
  </section>

  <div class="card is-horizontal is-half">
    <div class="card-image">
      <figure class="image is-4by3">
        <img src="https://picsum.photos/seed/picsum/256" alt="Placeholder image">
      </figure>
    </div>
    <div class="card-content">
      <div class="media">
        <div class="media-left">
          <figure class="image is-48x48">
            <img src="https://picsum.photos/seed/picsum/96" alt="Placeholder image">
          </figure>
        </div>
        <div class="media-content">
          <p class="title is-4">John Smith</p>
          <p class="subtitle is-6">@johnsmith</p>
        </div>
      </div>

      <div class="content">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit.
        Phasellus nec iaculis mauris. <a>@bulmaio</a>.
        <a href="#">#css</a> <a href="#">#responsive</a>
        <br>
        <time datetime="2016-1-1">11:09 PM - 1 Jan 2016</time>
      </div>
    </div>
  </div>
</div>

这是我尝试过的 css;

.card.is-horizontal {
  flex-direction: row;
  display: flex;
  flex-basis: 50ex;
  flex-grow: 0;
  flex-shrink: 1;
  box-shadow: none;
}

.card.is-horizontal .card-image {
  align-self: center;
}

.card.is-horizontal .image {
  min-height: 100%;
}

.card.is-horizontal .card-content {
  flex: 1;
}

.card.is-horizontal .card-content {
  padding-left: 1em;
  padding-top: 0;
  padding-bottom: 0;
  font-size: 0.8em;
}

.card.is-horizontal {
  ul {
    list-style: none;
    margin: 0;
  }

  .is-divider {
    margin-top: 1.5rem;
    margin-bottom: 1rem;
  }
}

这是一个方便的代码笔,我在其中进行了尝试。 https://codepen.io/rishavs/pen/zYvbgYZ?editors=0100

4

2 回答 2

2

告诉我下面的代码是否对您有帮助。在这里预览结果

HTML

<div class="container">
  <div class="columns">
    <div class="column">
      <div class="card is-fullimage">
    <div class="card-image">
      <figure class="image is-4by3">
        <img src="https://images7.alphacoders.com/303/303995.jpg" alt="Placeholder image">
      </figure>
      <div class="card-stacked">
        <div class="card-content">
          <div class="media-content">
            <p class="title is-4">John Smith</p>
            <p class="subtitle is-6">@johnsmith</p>
          </div>

          <div class="content">
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus nec iaculis mauris. <a>@bulmaio</a>.
            <a href="#">#css</a> <a href="#">#responsive</a>
            <br>
            <time datetime="2016-1-1">11:09 PM - 1 Jan 2016</time>
          </div>
        </div>
        <footer class="card-footer">
          <div class="card-footer-item has-text-left">
            <h1>Hello</h1>
          </div>
        </footer>
      </div>
    </div>
  </div>
    </div>
    <div class="column">
      <div class="card is-horizontal">
    <div class="card-image">
      <figure class="image is-square">
        <img src="https://images7.alphacoders.com/303/303995.jpg" alt="Placeholder image">
      </figure>

    </div>
        <div class="card-stacked">
        <div class="card-content">
          <div class="media-content">
            <p class="title is-4">John Smith</p>
            <p class="subtitle is-6">@johnsmith</p>
          </div>

          <div class="content">
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus nec iaculis mauris. <a>@bulmaio</a>.
            <a href="#">#css</a> <a href="#">#responsive</a>
            <br>
            <time datetime="2016-1-1">11:09 PM - 1 Jan 2016</time>
          </div>
        </div>
        <footer class="card-footer">
          <div class="card-footer-item has-text-left">
            <h1>Hello</h1>
          </div>
        </footer>
      </div>
  </div>
    </div>
  </div>
</div>

CSS

body {
  margin-top:3rem;
  margin-bottom: 3rem;
}

.card {
  &.is-horizontal {
    display: flex;

    .card-image {
      width: 100%;
      height: 100%;
    }

    .card-stacked {
      flex-direction: column;
      flex: 1 1 auto;
      display: flex;
      position: relative;

      .card-content {
        flex-grow: 1;
      }
    }
  }

  &.is-fullimage {
     background-color: transparent;
    .card-image {
      color: #fff !important;
      .card-stacked {
        position: absolute;
        bottom: 0;
        width: 100%;
        background: linear-gradient(to bottom, rgba(0,0,0,0) 0%,rgba(0,0,0,0.65) 100%);
        text-shadow: 0px 0px 2px #000000;

        .card-footer { 
          border-color: transparent;
        }

        .title, 
        .subtitle { 
          color: inherit;
        }

        a {
          color: inherit;

          &:hover {
            text-decoration: underline;
          }
        }
      } 
    }
  }

//   .card-footer {
//     .card-footer-item {
//       padding-left: 1.5rem;
//       padding-right: 1.5rem;
//     }

//     div.card-footer-item {
//       justify-content: unset;
//     }
//   }
}
于 2020-06-03T13:40:50.007 回答
0

制作 a ,然后用s 和ssection填充它narrow columnauto column

在此处了解更多信息:https ://bulma.io/documentation/columns/sizes/#narrow-column

例子:

(我在里面添加了narrow column一个。然后在我添加了一个导航栏;最后在右侧部分添加了页脚)cardauto columnauto

输出

<section class="section">
  <div class="card">
    <div class="card-content">
      <div class="content">
        <div class="columns">
          <div class="column is-narrow">
            <div class="card-image">
              <figure class="image is-64x64">
                <img
                  src="{% static 'img/profile.png' %}"
                  alt="Placeholder image"
                />
              </figure>
              <div class="media-content has-text-centered">
                <p class="title is-4">
                  {{ user.first_name }} {{ user.last_name }}
                </p>
                <p class="subtitle is-6">@{{ user.username }}</p>
              </div>
            </div>
          </div>
          <div class="column">
            <nav class="level">
              <div class="level-item has-text-centered">
                <div>
                  <p class="heading">Tweets</p>
                  <p class="title">3,456</p>
                </div>
              </div>
              <div class="level-item has-text-centered">
                <div>
                  <p class="heading">Following</p>
                  <p class="title">123</p>
                </div>
              </div>
              <div class="level-item has-text-centered">
                <div>
                  <p class="heading">Followers</p>
                  <p class="title">456K</p>
                </div>
              </div>
              <div class="level-item has-text-centered">
                <div>
                  <p class="heading">Likes</p>
                  <p class="title">789</p>
                </div>
              </div>
            </nav>
            <footer class="card-footer">
              <a href="#" class="card-footer-item has-text-centered">message</a>
              <a href="#" class="card-footer-item has-text-centered">follow</a>
              <a href="#" class="card-footer-item has-text-centered">edit</a>
              <a href="#" class="card-footer-item has-text-centered">change password</a>
            </footer>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>
于 2021-08-01T20:34:37.450 回答