div+css想要文字在图片上,图片大小固定_html/css_WEB-ITnose
css:
.p1{z-index: 1;width: 20;border-top: 5;border-right: 5;border-left: 5;border-bottom: 10;border-color: black}
.p2{font-family: 时尚中黑简体;font-size: 30pt;color: gray;z-index: 2}
html:

得到效果:
如图,文字并没有在图片上面而且图片也不像css里设定的那样有边框,变大,求问为什么?
回复讨论(解决方案)
重发遍图
想要文字在图片上层
要么 P2绝对定位
要么把图片换成p1的背景图都能满足。
而且你的div没有宽高,所以没有边框。
外层加一个div
.p{
position: relative
}
.p2 {
position:absolute
// 设top,left
}
<div class="p"><div class="p1"><img src="/static/imghw/default1.png" data-src="p1.jpg" class="lazy" alt="div+css想要文字在图片上,图片大小固定_html/css_WEB-ITnose" ></div><div class="p2">sdafdsafdsa</div></div>
可以用相对定位和绝对定位来解决。而且的的border也没有加单位px,下面是修改后的,希望对你有帮助:
<html><head><title></title><link rel=stylesheet type="text/css" href="1.css"><style>.p1{z-index: 1;width:300px;height:200px;border:5px solid black;position:relative;}.p1 img{width:250px;height:180px;}.p2{font-family: 时尚中黑简体;font-size: 30px;color: gray;z-index: 2;position:absolute;left:30px;top:50px;}</style></head><body> <div class="p1"><img src="/static/imghw/default1.png" data-src="p1.jpg" class="lazy" alt="div+css想要文字在图片上,图片大小固定_html/css_WEB-ITnose" > <div class="p2">sdafdsafdsa</div> </div></body></html>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.
