简体   繁体   English

如何制定只影响文本而不影响图像的 CSS 规则?

[英]How do I make a CSS rule that only affects text but not the image?

I am using a php script that outputs the post like this:我正在使用一个 php 脚本来输出这样的帖子:

<div class="postoutput">
  <p>
    <img src="content/xeon.png" alt="xeon.png">
    This is text, Xeon is great.```
  </p>
</div>

I can't touch the output but I can modify the CSS, is there way to add a margin that ONLY applies to the text using only CSS我无法触摸输出,但我可以修改 CSS,有没有办法添加仅适用于仅使用 CSS 的文本的边距

The image is 100% wide and this is okay.图像是 100% 宽,这是可以的。

The desired goal is to keep the image as it is but make the text ONLY have a 10px margin on each side.所需的目标是保持图像原样,但使文本每边只有 10 像素的边距。 Remember, I only have access to the CSS file.请记住,我只能访问 CSS 文件。

Long story short... no you cannot apply css directly to the text in your case.长话短说……不,您不能将 css 直接应用于您的案例中的文本。

You could probably emulate something close though.不过,您可能可以模仿一些接近的东西。

Assuming your image is fullwidth you could probably use something like:假设您的图像是全角,您可能会使用以下内容:

p {
   padding:10px;
}

p > img {
   margin:-10px -10px 10px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用CSS缩小图像? - How do I make an image smaller with CSS? 如何在 CSS flex 或 grid 中使单个图像响应并具有图像文本列? - How do I make a single image responsive in CSS flex or grid and have image-text columns? 如何在 5 秒后隐藏图像并仅使用 HTML 和 CSS 将其更改为文本区域 - how can i make image hide after 5 seconds and change it to text area using HTML and CSS only 如何使用图像和文字制作表格 - How do i make a form with an image and text 如何使文本出现在配方图像的中心下方,并且与 css 之间的距离相等? - How do I make the text appear under the center of the recipe image and be an equal distance from each other with css? 如何仅使用CSS将图像(或文本)放置在段落中两个或多个单词下面? - How do I place an image (or text) below two or more words in a paragraph using CSS only? 如何在 HTML/CSS 中的每个图像上制作带有文本的图像表? - How do I make table of images with text over each image in HTML/CSS? 如何使用CSS制作图像轮播? - How can I make an image carousel with only CSS? 如何让我的 css 根规则适用于我的网站 - How do i make my css root rule work for my website 使用 css 在站点范围内缩进段落后,如何从该规则中排除居中文本? - After using css to indent paragraphs site wide, how do I exclude centered text from this rule?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM