gpt4 book ai didi

html - 我在放置 div 时遇到问题

转载 作者:行者123 更新时间:2023-11-28 04:34:03 26 4
gpt4 key购买 nike

所以我正在使用 bootstrap 并尝试创建一个场景,其中一半行是橙色,另一半是绿色,但就在中间我想要蓝色六边形。我遇到的问题是我可以让蓝色六边形位于桌面的中央,但我想设计它适合移动设备。有什么想法可以让六边形直接位于中间,这两个 div 在移动设备友好时也会相遇并留在那儿吗?

这是我的 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">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Hexagon | Home</title>

<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css?family=Arima+Madurai" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Bungee+Shade" rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>

<body>
<header>
<div class="container-fluid">
<div class="row">
<div class="col-md-6 red-500">
</div>
<div class="col-md-6 green-500">
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="col-md-6 hex-cont">
<div class="hexagon">
<i class="fa fa-handshake-o logo" aria-hidden="true" style="font-size:7em;"></i>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6 white">
<h1 class="text-center wit">Friend Zone</h1>
<h3 class="text-center wit">Mediation Service</h3>
</div>
</div>

</div>
</header>

这是我的相关 CSS

body{


font-family: 'Arima Madurai', cursive;
}

.hexagon {
position: relative;
width: 200px;
height: 115.47px;
background-color: #64C7CC;
margin: 57.74px 0;
display:block;
}

.hexagon:before,
.hexagon:after {
content: "";
position: absolute;
width: 0;
border-left: 100px solid transparent;
border-right: 100px solid transparent;
}

.hexagon:before {
bottom: 100%;
border-bottom: 57.74px solid #64C7CC;
}

.hexagon:after {
top: 100%;
margin-left:-83%;
width: 0;
border-top: 57.74px solid #64C7CC;
}

.red-500{
background:#FF4500;
height:250px;
z-index:0;
display:block;
}

.green-500{
background:#4CA64C;
height:250px;
z-index:-5;

}

最佳答案

如果你用橙色/绿色制作了行,将六边形元素放在该行中,将 position: relative; 添加到行(parent),将六边形元素设置为 position: absolute; 并使用 left: 50%; 的组合transform: translateX(-50%); 使其居中。

body{


font-family: 'Arima Madurai', cursive;
}
.row {
position: relative;
}
.hexagon {
position: relative;
width: 200px;
height: 115.47px;
background-color: #64C7CC;
display:block;
position: absolute;
top: 50%; left: 50%;
transform: translate(-50%,-50%);
}

.hexagon:before,
.hexagon:after {
content: "";
position: absolute;
width: 0;
border-left: 100px solid transparent;
border-right: 100px solid transparent;
}

.hexagon:before {
bottom: 100%;
border-bottom: 57.74px solid #64C7CC;
}

.hexagon:after {
top: 100%;
margin-left:-83%;
width: 0;
border-top: 57.74px solid #64C7CC;
}

.red-500{
background:#FF4500;
height:250px;
z-index:0;
display:block;
}

.green-500{
background:#4CA64C;
height:250px;
z-index:-5;

}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<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">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Hexagon | Home</title>

<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet" />
<link href="https://fonts.googleapis.com/css?family=Arima+Madurai" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Bungee+Shade" rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>

<body>
<header>
<div class="container-fluid">
<div class="row">
<div class="col-md-6 red-500">
</div>
<div class="hexagon">
<i class="fa fa-handshake-o logo" aria-hidden="true" style="font-size:7em;"></i>
</div>
<div class="col-md-6 green-500">
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="col-md-6 hex-cont">

</div>
</div>
</div>
<div class="row">
<div class="col-md-6 white">
<h1 class="text-center wit">Friend Zone</h1>
<h3 class="text-center wit">Mediation Service</h3>
</div>
</div>

</div>
</header>

关于html - 我在放置 div 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41580811/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com