简体   繁体   English

如何使标题与图像缩放并保持间距比html / css

[英]How to get a heading to scale with a image and keep spacing ratio html/css

I would like to have a image on the left with a heading on the right. 我想在左边有一个图片,在右边有一个标题。 I want both of them to scale in size and spacing as the page is shrunk. 我希望两者都随着页面缩小而缩放大小和间距。 I have used this code: width: 10%; height: auto; margin: 2% 0px; 我使用了以下代码: width: 10%; height: auto; margin: 2% 0px; width: 10%; height: auto; margin: 2% 0px; to have the image on the top left of my page and scale in both spacing and size to the page when the browser is shrunk (I have also included media queries which wouldn't think would make a difference). 使图像位于页面的左上角,并在缩小浏览器时在页面的间距和大小上进行缩放(我还添加了媒体查询,认为这不会有所作为)。 I have tried using positioning: absolute which doesn't work. 我尝试使用positioning: absolute不起作用。 I am a novice to using HTML5 and CSS3. 我是使用HTML5和CSS3的新手。 This is my first project and second post on Stack Overflow. 这是我的第一个项目,也是Stack Overflow的第二篇文章。

I think this is what you are trying to do HTML 我认为这就是您要尝试做的HTML

 <div class="wrapper"><img src="yourimage.jpg"/><h1>my Heading Goes here</h1></div>

CSS CSS

div.wrapper {
   width: 100%; 
   height: auto; 
   max-width: 600px; 
   border: thin solid #333;
 }
div.wrapper:after {
   content: '';
   display: block;
   clear: both;
}
div.wrapper img {
   display: block; 
   float: left; width: 40%; 
   height: auto; 
   margin-right: 5%;
}
div.h1 {
   display: inline-block;
   line-height: 20px;
   margin: 0px;
   padding: 0px;
}

You can check it here jsfidlle 您可以在这里检查jsfidlle

Could you make a http://jsfiddle.net/ ? 您可以制作一个http://jsfiddle.net/吗? It's kinda hard to understand what you're after based on our description alone. 仅根据我们的描述很难理解您的追求。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM