javascript - 我如何将图像放在表格之外并使其大小相同?
问题描述
我一直在尝试使图像与表单大小相同,但我无法正常工作,你们中的某个人可以给我一个提示吗?我从一个网站得到的这个联系表,我会稍微改变一下,但需要先解决这个问题。
<!-- CODE CSS -->
.full {
display: inline-block;
}
.fullform {
width: 400px;
float: left;
display: inline-block;
}
.image {
float:left;
display: inline-block;
}
<!-- Full div -->
<div class="full">
<div class="fullform">
<div class="form-top">
<h3>Contact us</h3>
<p>Fill in the form below to send us a message:</p>
</div>
<div class="form-bottom contact-form">
<form role="form" action="KONTAKTFORM/assets/contact.php" method="post">
<div class="form-group">
<label class="sr-only" for="contact-email">Email</label>
<input type="text" name="email" placeholder="Email..." class="contact-email form-control" id="contact-email">
</div>
<div class="form-group">
<label class="sr-only" for="contact-subject">Subject</label>
<input type="text" name="subject" placeholder="Subject..." class="contact-subject form-control" id="contact-subject">
</div>
<div class="form-group">
<label class="sr-only" for="contact-message">Message</label>
<textarea name="message" placeholder="Message..." class="contact-message form-control" id="contact-message"></textarea>
</div>
<div class="form-group">
<label for="contact-antispam">Antispam question: 7 + 5 = ?</label>
<input type="text" name="antispam" placeholder="Your answer..." class="contact-antispam form-control" id="contact-antispam">
</div>
<button type="submit" class="btn">Send message</button>
</form>
</div>
</div>
<div class="image">
<img src="gavle.jpg">
</div>
</div>
<!-- End of div -->
解决方案
如果需要,请查看此技巧与位置relative
。absolute
将image
采用容器的高度,.full
即auto
,取决于.fullform
.full {
position: relative;
width: 100%;
height: auto;
background-color: yellow;
}
.fullform {
width: 50%;
background-color: tomato;
}
.image {
position: absolute;
top: 0;
right: 0;
bottom: 0;
width: 50%;
overflow: hidden;
}
.image > img { /*img take 100% width and height (optional)*/
width: 100%;
height: 100%;
}
<!-- Full div -->
<div class="full">
<div class="fullform">
<div class="form-top">
<h3>Contact us</h3>
<p>Fill in the form below to send us a message:</p>
</div>
<div class="form-bottom contact-form">
<form role="form" action="KONTAKTFORM/assets/contact.php" method="post">
<div class="form-group">
<label class="sr-only" for="contact-email">Email</label>
<input type="text" name="email" placeholder="Email..." class="contact-email form-control" id="contact-email">
</div>
<div class="form-group">
<label class="sr-only" for="contact-subject">Subject</label>
<input type="text" name="subject" placeholder="Subject..." class="contact-subject form-control" id="contact-subject">
</div>
<div class="form-group">
<label class="sr-only" for="contact-message">Message</label>
<textarea name="message" placeholder="Message..." class="contact-message form-control" id="contact-message"></textarea>
</div>
<div class="form-group">
<label for="contact-antispam">Antispam question: 7 + 5 = ?</label>
<input type="text" name="antispam" placeholder="Your answer..." class="contact-antispam form-control" id="contact-antispam">
</div>
<button type="submit" class="btn">Send message</button>
</form>
</div>
</div>
<div class="image">
<img src="https://picsum.photos/500">
</div>
</div>
<!-- End of div -->
推荐阅读
- r - 带有百分比的堆积条形图
- javascript - 使用 Javascript 在前端创建基本 URL(开发、API 和生产)
- java - 拆分字符串没有给出预期的输出
- python - 用于自动化脚本的 Web 服务
- php - laravel 上的图片上传无法在线工作:Laravel
- python - 在 Google Colab 上为 cpu 和 gpu 获取相同的运行时
- python - 如何仅过滤排列中的唯一对,python?
- javascript - 使用 PHP 在数据库中发送依赖下拉列表的值
- java - gradle 无法更改配置 ':compile' 的依赖项后,它已包含在依赖项解析中
- php - 如何使用 web.config 禁用 webDAV