gpt4 book ai didi

html - 浏览器调整大小时如何并排放置两个图像?

转载 作者:可可西里 更新时间:2023-11-01 13:07:53 25 4
gpt4 key购买 nike

我遇到了一些麻烦。我有两张并排的图片,我希望当我的浏览器窗口调整大小时(缩小)它们始终并排位于同一行上。

发生的事情是,在某一时刻,其中一张图片被下推。我已将两张图片放在 <figure> 中并用 max-width 设置图形但这没有用。有什么帮助吗?

这是 JSFiddle:https://jsfiddle.net/srebne/ru9fmudr/

一个片段中的所有代码:

nav ul li a:hover,
nav ul li.active a {
border: 2px solid #dad9d8;
}
nav {
margin: 0 0 1em;
font-family: Helvetica, Arial, sans-serif;
display: flex;
flex-wrap: no-wrap;
justify-content: center;
}
nav ul {
margin: 0;
padding: 0;
list-style: none;
}
nav li {
display: inline-block;
}
nav a {
display: block;
padding: 0.3em;
color: black;
text-align: center;
text-decoration: none;
background-color: #ffae00;
background: -webkit-linear-gradient(top, #ffae00, #d67600);
background: -moz-linear-gradient(top, #ffae00, #d67600);
background: -o-linear-gradient(top, #ffae00, #d67600);
background: linear-gradient(top, #ffae00, #d67600);
border: 2px outset #dad9d8;
font-family: Andika, Arial, sans-serif;
letter-spacing: 0.05em;
color: #fff;
text-shadow: 0px 1px 10px #000;
-webkit-border-radius: 12px;
-moz-border-radius: 12px;
border-radius: 12px;
-webkit-box-shadow: rgba(0, 0, 0, .55) 0 1px 6px;
-moz-box-shadow: rgba(0, 0, 0, .55) 0 1px 6px;
box-shadow: rgba(0, 0, 0, .55) 0 1px 6px;
}
body {
font-family: Rockwell, “Courier Bold”, Courier, Georgia, Times, “Times New Roman”, serif;
}
html {
background: url(babybluebackgroundwallpaper.jpg) no-repeat center center fixed;
background-size: cover;
/*background-color: #D6EBFF*/
}
h1,
h2,
h3,
h4,
h5,
h6 {
color: #D6AD33;
font-size: 40px;
}
#imgbox {
display: flex;
justify-content: center;
}
#logoimg {
width: 300px;
height: 100px;
}
#dkpic,
#srpic {
border: solid 3px #D6AD33;
max-width: 100%;
}
.teampic1 {
float: left;
max-width: 45%;
}
.teampic2 {
float: right;
max-width: 45%;
}
#aboutus {
font-size: 30px;
}
#ourteam {
font-size: 30px;
}
@media only screen and (min-width: 700px) {
#philo {
width: 50%;
float: left;
clear: left;
}
#team {
width: 50%;
float: right;
}
}
@media only screen and (min-width: 1000px) {
.teampic1 {
max-width: 30%;
}
.teampic2 {
max-width: 30%;
}
}
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="description" content="About Us">
<title>FoodList About Us</title>
</head>

<body>
<div id="imgbox">
<img id="logoimg" src="logo.jpg" alt="foodlist logo">
</div>
<br>
<nav>
<ul>
<li>
<a href="index.html">Home</a>
</li>
<li>
<a href="about.html">About</a>
</li>
<li>
<a href="contact.html">Contact</a>
</li>
</ul>
</nav>

<div id="philo">
<h2>Our Philosophy</h2>
<p id="aboutus">At FoodList our mission is simple. bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla</p>
</div>
<div id="team">
<h2>Meet Our Team</h2>
<figure class="teampic1">
<img id="dkpic" src="davidko.jpg" alt="dk's picture">
<figcaption>Dvzzn Xi</figcaption>
</figure>
<figure class="teampic2">
<img id="srpic" src="srebne.png" alt="s's picture">
<figcaption>Sgfkfk Rkesn</figcaption>
</figure>
<p id="ourteam"></p>
</div>
</body>

</html>

最佳答案

在两个图形元素上使用此样式:

display: inline-block;
width: 45%;
margin: 1%; //or more just play with it a little
vertical-align: top;

应该这样做

编辑:看看这个 fiddle https://jsfiddle.net/ru9fmudr/4/

浏览器会自动将开始边距和结束边距等设置为 40px,这就是为什么当您缩小 45% 宽度 * 2 = 90% 并且浏览器边距会远远超过 10% 这就是为什么它没有工作。

干杯

关于html - 浏览器调整大小时如何并排放置两个图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29975422/

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