如何制作容器行?

发布于 2025-01-23 09:13:45 字数 323 浏览 0 评论 0原文

我是HTML的新手,仍在学习,但是我正在努力连接行和divs。

我正在尝试做这样的事情(下图)。我希望能够单击并转到某个链接。他们俩都必须彼此相邻,但都必须与自己的链接。我知道Float是正确的选择,但是我也可以使用网格吗?

我该怎么做?

非常感谢任何帮助,谢谢!

I'm fairly new to HTML and still learning, but I'm struggling with connecting rows and divs.

I'm trying to make something like this (picture below). I want to be able to make it clickable and go to a certain link. They both have to be next to each other, but with each their own link. I know float is the right option but can I use grid too?

How do I do this?

Any help is very much appreciated, thank you!

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

失而复得 2025-01-30 09:13:45

HTML

<div class="container">
        <div class="product">
            <div class="bg-white">
                <a href="">
                    <img class="img-fluid"
                        src="https://static.wixstatic.com/media/2c0034_5e484cb9921c41a8bde8eed74b3aa810~mv2.jpg"
                        alt="" /></a>
                <h1>Demo Heading</h1>
                <p>Lorem ipsum dolor sit amet.</p>
            </div>
        </div>
        <div class="product">
            <div class="bg-white">
                <a href="">
                    <img class="img-fluid"
                        src="https://static.wixstatic.com/media/2c0034_84e67efc3df44e8ea8b6da006e6d1ba5~mv2.jpg"
                        alt="" /></a>
                <h1>Demo Heading</h1>
                <p>Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet.Lorem ipsum dolor
                    sit amet.Lorem ipsum dolor sit amet.</p>
            </div>
        </div>
    </div>

CSS

<style>
       * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }

    .img-fluid {
        max-width: 100%;
        width: 100%;
        display: block;
        height: auto;
    }

    .container {
        margin: auto;
        max-width: 1200px;
        display: flex;
        flex-wrap: wrap;
        background-color: #f6f6f6;
        padding: 1rem;
    }

    .container .product {
        flex: 0 0 50%;
        padding: 0 1rem;
    }

    .container .product .bg-white {
        background-color: white;
        box-shadow: 0px 0px 15px 5px #ddd;
        height: 100%;
    }

    .container .product h1 {
        font-size: 1rem;
        padding: 0.5rem 1rem .1rem 0;
        border-bottom: 2px solid brown;
        display: inline-block;
        margin: 0 0 .5rem .5rem;
        text-transform: uppercase;
    }

    .container .product p {
        font-size: 1rem;
        padding: 0 1rem 0.5rem 0.5rem
    }
    </style>

HTML

<div class="container">
        <div class="product">
            <div class="bg-white">
                <a href="">
                    <img class="img-fluid"
                        src="https://static.wixstatic.com/media/2c0034_5e484cb9921c41a8bde8eed74b3aa810~mv2.jpg"
                        alt="" /></a>
                <h1>Demo Heading</h1>
                <p>Lorem ipsum dolor sit amet.</p>
            </div>
        </div>
        <div class="product">
            <div class="bg-white">
                <a href="">
                    <img class="img-fluid"
                        src="https://static.wixstatic.com/media/2c0034_84e67efc3df44e8ea8b6da006e6d1ba5~mv2.jpg"
                        alt="" /></a>
                <h1>Demo Heading</h1>
                <p>Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet.Lorem ipsum dolor
                    sit amet.Lorem ipsum dolor sit amet.</p>
            </div>
        </div>
    </div>

CSS

<style>
       * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }

    .img-fluid {
        max-width: 100%;
        width: 100%;
        display: block;
        height: auto;
    }

    .container {
        margin: auto;
        max-width: 1200px;
        display: flex;
        flex-wrap: wrap;
        background-color: #f6f6f6;
        padding: 1rem;
    }

    .container .product {
        flex: 0 0 50%;
        padding: 0 1rem;
    }

    .container .product .bg-white {
        background-color: white;
        box-shadow: 0px 0px 15px 5px #ddd;
        height: 100%;
    }

    .container .product h1 {
        font-size: 1rem;
        padding: 0.5rem 1rem .1rem 0;
        border-bottom: 2px solid brown;
        display: inline-block;
        margin: 0 0 .5rem .5rem;
        text-transform: uppercase;
    }

    .container .product p {
        font-size: 1rem;
        padding: 0 1rem 0.5rem 0.5rem
    }
    </style>
一桥轻雨一伞开 2025-01-30 09:13:45

您必须在单个 col-6 类中占用两个 div ,每个> div 。在每个DIV中,您必须拍摄两张图像,而只是您的设计。

例如:

<div class="row">
<div class="col-md-6">
    <a href="link1">
        <img src="img1">
        <h2></h2>
        <p></p>
    </a>
</div>
<div class="col-md-6">
    <a href="link2">
        <img src="img2">
        <h2></h2>
        <p></p>
    </a>
</div>

You have to take two two div with class of col-6 each in single div. In each div, you have to take two images and simply your design.

For example:

<div class="row">
<div class="col-md-6">
    <a href="link1">
        <img src="img1">
        <h2></h2>
        <p></p>
    </a>
</div>
<div class="col-md-6">
    <a href="link2">
        <img src="img2">
        <h2></h2>
        <p></p>
    </a>
</div>
夜夜流光相皎洁 2025-01-30 09:13:45

这是使用flex上的两列布局的基本示例,flex-basis:50%; in flex-item

.flex-wrapper {
  display: flex;
  justify-content: space-between;
}

.flex-item {
  text-align: center;
  flex-basis: 50%;
  padding: 10px;
  box-shadow: 0px 0px 6px 2px rgb(152 139 139 / 50%);
}

img {
  max-width: 100%;
}
<div class="flex-wrapper">
  <div class="flex-item">
    <img src="https://dummyimage.com/600x400/b52ab5/fff">
    <h6>Left column</h6>
  </div>

  <div class="flex-item">
    <img src="https://dummyimage.com/600x400/2a6b25/0011ff">
    <h6>Right column</h6>
  </div>
</div>

Here is a basic example of a two column layout using a flex on the parent and flex-basis: 50%; on each flex-item.

.flex-wrapper {
  display: flex;
  justify-content: space-between;
}

.flex-item {
  text-align: center;
  flex-basis: 50%;
  padding: 10px;
  box-shadow: 0px 0px 6px 2px rgb(152 139 139 / 50%);
}

img {
  max-width: 100%;
}
<div class="flex-wrapper">
  <div class="flex-item">
    <img src="https://dummyimage.com/600x400/b52ab5/fff">
    <h6>Left column</h6>
  </div>

  <div class="flex-item">
    <img src="https://dummyimage.com/600x400/2a6b25/0011ff">
    <h6>Right column</h6>
  </div>
</div>

嘿哥们儿 2025-01-30 09:13:45

使用2个孩子(映像 - 容器,text-container

我创建一个容器,并在image-container内 (图像网格),在书籍将留下的4个相等框架中。

比我给出的第二和第四个孩子的利润

.image-grid img:nth-child(2){
  margin-top: 1rem;
}

.image-grid img:nth-child(4){
  margin-top: -1rem;
}

html{
  font-size: 25px;
}


img{
  display: block;
  max-width: 100%;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}



body{
  min-height: 100vh;
  overflow: hidden;
  display: grid;
  place-content: center;
  margin:0;
  background-color: bisque;
  font-size: 20px;
}

.container{
  width:20rem;
  height:15rem;
  background-color: whitesmoke;
  box-shadow: 0 0 1rem black;
}


.image-container{
  background-image: url(https://source.unsplash.com/random/400x200);
  height: 70%;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.image-grid{
  height: 50%;
  display: grid;
  grid-template-columns: repeat(4,1fr);
  gap:1rem;
  margin-inline: 1rem;
}

.image-grid img:nth-child(2){
  margin-top: 1rem;
}

.image-grid img:nth-child(4){
  margin-top: -1rem;
}

.text-container{
  height: 30%;
  margin-block: 1rem;
  margin-left: 1rem;
}

.text-container h2{
  font-size: 0.7rem;
  text-transform: uppercase;
  text-decoration: underline;
}

.text-container p{
  margin-top: 0.5rem;
  font-size: 0.7rem;
}
<div class="container">
      <div class="image-container">
        <div class="image-grid">
          <img src="https://source.unsplash.com/random/600x900" alt="book1" />
          <img src="https://source.unsplash.com/random/600x900" alt="book2" />
          <img src="https://source.unsplash.com/random/600x900" alt="book3" />
          <img src="https://source.unsplash.com/random/600x900" alt="book4" />
        </div>
      </div>
      <div class="text-container">
        <h2>For Pachinko Fans</h2>
        <p>Get Lost in your nex epic family story</p>
      </div>
</div>

I create a container and it has 2 childs (image-container, text-container)

Inside image-container i use background image to cover the container and i created a grid container (image-grid) which have 4 equal frame in it which the books will stay.

Than i give 2nd and 4th childs margins

.image-grid img:nth-child(2){
  margin-top: 1rem;
}

.image-grid img:nth-child(4){
  margin-top: -1rem;
}

html{
  font-size: 25px;
}


img{
  display: block;
  max-width: 100%;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}



body{
  min-height: 100vh;
  overflow: hidden;
  display: grid;
  place-content: center;
  margin:0;
  background-color: bisque;
  font-size: 20px;
}

.container{
  width:20rem;
  height:15rem;
  background-color: whitesmoke;
  box-shadow: 0 0 1rem black;
}


.image-container{
  background-image: url(https://source.unsplash.com/random/400x200);
  height: 70%;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.image-grid{
  height: 50%;
  display: grid;
  grid-template-columns: repeat(4,1fr);
  gap:1rem;
  margin-inline: 1rem;
}

.image-grid img:nth-child(2){
  margin-top: 1rem;
}

.image-grid img:nth-child(4){
  margin-top: -1rem;
}

.text-container{
  height: 30%;
  margin-block: 1rem;
  margin-left: 1rem;
}

.text-container h2{
  font-size: 0.7rem;
  text-transform: uppercase;
  text-decoration: underline;
}

.text-container p{
  margin-top: 0.5rem;
  font-size: 0.7rem;
}
<div class="container">
      <div class="image-container">
        <div class="image-grid">
          <img src="https://source.unsplash.com/random/600x900" alt="book1" />
          <img src="https://source.unsplash.com/random/600x900" alt="book2" />
          <img src="https://source.unsplash.com/random/600x900" alt="book3" />
          <img src="https://source.unsplash.com/random/600x900" alt="book4" />
        </div>
      </div>
      <div class="text-container">
        <h2>For Pachinko Fans</h2>
        <p>Get Lost in your nex epic family story</p>
      </div>
</div>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文