跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • 初学 CSS,问一个比较基础的问题
未分類
8 10 月 2020

初学 CSS,问一个比较基础的问题

初学 CSS,问一个比较基础的问题

資深大佬 : nurupo 2

不使用 position:absolute,如何把元素放在两个 div 中间? 比如说把图中乔氏家的 h3 标签放在上下两个 div 中间。

初学 CSS,问一个比较基础的问题

<!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <meta name="viewport" content="width=device-width, initial-scale=1.0">     <title>Document</title>     <style>         * {             margin: 0;             padding: 0;         }          .product {             width: 560px;             height: 880px;             border: 3px solid #eeeeee;             margin: 20px;         }          .product-header {             width: 560px;             height: 560px;             background-color: #f8f8f8;             display: table-cell;             text-align: center;             vertical-align: middle;         }                  .product-img {             width: 455px;             height: 455px;         }          .product-content {             position: relative;             margin: 40px;         }          .product-brand {             position: absolute;             border: 1px solid #cda3b1;             background-color: #cda3b1;             color: #ffffff;             top: -70px;             padding: 10px;             font-size: 26px;             font-weight: 400;         }          .product-title {             font-weight: 400;             display: -webkit-box;             word-break: break-word;             -webkit-line-clamp: 2;             overflow: hidden;             -webkit-box-orient: vertical;             text-overflow: ellipsis;             font-size: 40px;         }          .product-discount {             float: left;             list-style: none;             border: 1px solid #c82b50;             margin: 20px 10px 0px 0px;             font-size: 26px;             color: #c82b50;             padding: 2px;         }          .product-price {             clear: both;             float: left;             list-style: none;             line-height: 70px;             margin: 10px 0px;         }          .product-price-text {             font-size: 40px;             font-weight: 700;             color: #f10604;         }          .product-similar {             float: right;             list-style: none;             width: 160px;             height: 70px;             border: 1px solid #ffe6ea;             background-color: #ffe6ea;             border-radius: 999em;             text-align: center;             line-height: 70px;             margin: 10px 0px;         }          .product-similar-text {             font-size: 30px;             font-weight: 700;             color: #cd2852;         }     </style> </head> <body>     <div class="product">         <div class="product-header">             <img class="product-img" src="http://img.alicdn.com/imgextra/i2/3161207834/O1CN01Lwd1Q427k1MvtNOA3_!!3161207834.jpg">         </div>         <div class="product-content">             <h3 class="product-brand">乔氏家</h3>             <h1 class="product-title">风衣外套女 2020 新款中长款流行英伦风过膝春秋韩版宽松气质大衣</h1>             <ul>                 <li class="product-discount">                     <p class="product-discount-info">每 300 减 30</p>                 </li>                 <li class="product-discount">                     <p class="product-discount-info">满 128 减 10</p>                 </li>             </ul>             <ul>                 <li class="product-price">                     <span class="product-price-text">¥&nbsp;168</span>                 </li>                 <li class="product-similar">                     <span class="product-similar-text">看相似</span>                 </li>             </ul>         </div>              </div> </body> </html> 

大佬有話說 (8)

  • 資深大佬 : seki

    为什么不用?

  • 主 資深大佬 : nurupo

    @seki 想问问有没有什么其他的方法?

  • 資深大佬 : jjplay

    用负 margin,我弄了个演示,方便查看 背景色改成了 pink

    jsrun.net/KN6Kp

  • 資深大佬 : zhangkunduanfei

    单纯放中间的话 中间那个 div display:flex,然后 justify-content 和 align-items 给 center 就可以

  • 主 資深大佬 : nurupo

    @jjplay 感谢大佬解答

  • 主 資深大佬 : nurupo

    @zhangkunduanfei 不是要居中的效果,不过还是谢谢了

  • 資深大佬 : zachlhb

    margin 设置水平居中,line-height 设置垂直居中

  • 資深大佬 : MiracleKagari

    brand float,title margin top,

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具