ฉันจะทำให้ Flexbox Item เป็นไฮเปอร์ลิงก์ได้อย่างไร

ฉันมี 3 รายการ (กล่อง) ภายใน flexbox ของฉันที่ฉันต้องการใช้เป็นไฮเปอร์ลิงก์ อย่างไรก็ตาม เมื่อฉันใส่แท็กเข้าไป จะทำให้เลย์เอาต์เสียหายโดยสิ้นเชิง ฉันจะตั้งค่าแต่ละรายการ (กล่อง) เป็นไฮเปอร์ลิงก์เพื่อให้ผู้ใช้สามารถคลิกพื้นที่ทั้งหมดและพาไปยังเว็บไซต์อื่นได้อย่างไร ณ ตอนนี้ฉันมีข้อความในกล่องที่ตั้งค่าเป็นลิงก์ แต่ฉันต้องการใช้ทั้งกล่องเป็นลิงค์

นี่คือ Codepen สำหรับมัน: https://codepen.io/mrhoward/pen/dqqOxj

   HTML:
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
    <link rel="shortcut icon" href="/thimg/misc/favicon.png">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>Flexbox Problem.</title>
    <link href="/thcss/ton.css" rel="stylesheet">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Press+Start+2P|Open+Sans">
  </head>
  <body>
    <h1 class="col">Each Square as Hyperlink</h1>
    <h2 class="col">This is getting annoying</h2>
    <div class="maincontain">
      <div class="col gaming"><a href="/th"><h3 class="title">1</h3></a></div>
      <div class="col music"><a href="/th"><h3 class="title">2</h3></a></div>
      <div class="col dev"><a href="/th"><h3 class="title">3</h3></a></div>
    </div>
  </body>
</html>

ซีเอสเอส:

body {
  background: #333;
  color: #fff;
  padding: 20px;
}
a {
  text-decoration: none;

}

/* FLEXBOX */

* {
  box-sizing: border-box;
}

.col {
  padding: 20px;
}

.maincontain {
  display: flex;
  display: -webkit-flex;
  display: -ms-flexbox;
  justify-content: space-between;
}
.maincontain .col {
  width: 32%;
  height:400px;
  align-items: stretch;

}

@media only screen and (max-width: 40em) {
  .maincontain {
    flex-direction: column;
    height: 300px;
    margin: 0 0 10px 0;
  }
}

@media only screen and (max-width: 40em) {
.maincontain .col {width: 100%;}
.maincontain h3 { font-size: 1.3vh}

}


/* Item Stylig */
.gaming {
  background: #d836eb;

}

.music {
  background: #0000ff;
}

.dev {
  background: #00ff00;
}

/* Font Styling */

h1 {
  font-size:5vw;
  font-family: 'Open Sans', sans-serif;
  font-weight: lighter;
  text-align: center;
  padding: 50px;
}

h2 {
  font-size:2vw;
  font-family: 'Press Start 2P', cursive;
  text-align: center;
  padding: 0px 0px 20px 0px;
}

h3 {
  font-size: 1.3vw;
  font-family: 'Press Start 2P', cursive;
  padding-top: 10px;
  object-fit: cover;
}

.title{
  color: white;
  text-shadow: 1px 1px 4px #000000;
}

person Josh    schedule 16.09.2018    source แหล่งที่มา
comment
ใช่ ‹a href=›‹/a› รอบรายการทำให้เลย์เอาต์เสียหายโดยสิ้นเชิง   -  person Josh    schedule 16.09.2018
comment
เพื่อชี้แจงให้กระจ่าง ฉันหมายถึงการมี ‹a href› รอบๆ div ทำให้มันพัง   -  person Josh    schedule 16.09.2018
comment
นี่คือเอฟเฟกต์ที่คุณต้องการใช่ไหม? codepen.io/anon/pen/zJJNBP   -  person Chris Li    schedule 16.09.2018
comment
ปัญหาที่ฉันพบคือการปรับขนาดเบราว์เซอร์สำหรับมือถือ ทำให้มันเลอะเทอะไปหมด   -  person Josh    schedule 16.09.2018
comment
ใช่แล้ว ปรากฎว่าฉันสะกดผิดแน่นอน.. ขออภัยด้วย   -  person Chris Li    schedule 16.09.2018
comment
codepen.io/anon/pen/zJJNBP ตรวจสอบอีกครั้งเพื่อดูว่าทำงานถูกต้องหรือไม่   -  person Chris Li    schedule 16.09.2018
comment
แสดงลิงก์เป็นแบบยืดหยุ่นและตั้งค่าความสูงเป็น 100%   -  person luenib    schedule 03.11.2020


คำตอบ (3)


ด้านล่างนี้เป็นลิงค์ไปยังปากกาที่ฉันแยกและบันทึก => https://codepen.io/kipomaha/pen/OooWXL

ด้านล่างนี้คือ HTML ฉันเปลี่ยนคลาสจาก div และวางไว้บน a element ที่ฉันล้อม div


<!DOCTYPE html>
<html lang="en">
  <head>
     <meta charset="utf-8">
     <meta http-equiv="X-UA-Compatible" content="IE=edge">
     <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
     <link rel="shortcut icon" href="/thimg/misc/favicon.png">
     <meta name="description" content="">
     <meta name="author" content="">
     <title>Flexbox Problem.</title>
     <link href="/thcss/ton.css" rel="stylesheet">
     <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Press+Start+2P|Open+Sans">
  </head>
  <body>
     <h1 class="col">Each Square as Hyperlink</h1>
     <h2 class="col">This is getting annoying</h2>
     <div class="maincontain">
        <a href="/th#" class="col gaming"><div><h3 class="title">1</h3></div></a>
        <a href="/th#" class="col music"><div><h3 class="title">2</h3></div></a>
        <a class="col dev" href="/th#"><div><h3 class="title">3</h3></div></a>
     </div>
  </body>
</html>
person Community    schedule 16.09.2018
comment
ขอบคุณ มันได้ผล มันตลกดีที่คุณใช้เวลาหลายชั่วโมงเพื่อพยายามคิดอะไรที่เรียบง่ายขนาดนี้ - person Josh; 16.09.2018
comment
พักหายใจบ้าง! :) - person ; 16.09.2018

ตรวจสอบตัวอย่างนี้:

<div id="select">
    <p class="options left">
        <a id="leftq" href="/th#selectionSet">the quick brown fox jumps over the lazy</a>
    </p>
    <p class="options right">
        <a id="rightq" href="/th#selectionSet">dog</a>
    </p>
</div>



#select {
    color: #fff;
    float: left;
    height: 188px;
    width: 631px;
}
#select p.options {
    color: #FFFFFF;
    float: left;
    font-family: 'ComfortaaBold',cursive;
    font-size: 20px;
    height: 100%;
    margin: 0 auto;
    text-align: center;
    width: 48%;  
}
p.options.left {
    align-items: center;
    background: none repeat scroll 0 0 #EBEBEB;
    border-bottom-left-radius: 100px;
    border-right: 2px solid #FFFFFF;
    border-top-left-radius: 100px;
    display: flex;
    justify-content: center;
    padding-left: 5px;
    padding-right: 5px;
}
p.options.right {
    align-items: center;
    background: none repeat scroll 0 0 #EBEBEB;
    border-bottom-right-radius: 100px;
    border-left: 2px solid #FFFFFF;
    border-top-right-radius: 100px;
    display: flex;
    justify-content: center;
    padding-left: 5px;
    padding-right: 5px;
}
#select p.options a {
    color: #636363;
    padding: 80px 0;
    text-decoration: none;
    display:block;
    width:100%;
}
#select p.options a:hover {
    color: #FFFFFF;
}
p.options.right:hover, p.options.left:hover {
    background-color: #00AEEF !important;
}

.rightq {
    width: 100%;
}
person Siavash    schedule 16.09.2018

ลองเพิ่มแท็ก <a> ภายในองค์ประกอบ <h3> เหมือนด้านล่าง

<h3><a hrer =""><a></h3>

กับ

 . maincontain a{
     display :block;
} 
person Abhijit    schedule 16.09.2018