CSS样式文本未按预期工作

时间:2016-05-24 15:08:45

标签: html css

您好我刚开始使用CSS我发现这种风格看起来很简单我想为什么不试着让它学习如何更好地使用CSS,

但当然我失败了,基本上我试图制作这样的风格,因为看起来这样做很简单?

想要的结果: Wanted style http://img.prntscr.com/img?url=http://i.imgur.com/C5rjjXG.png

我的结果: My Style http://img.prntscr.com/img?url=http://i.imgur.com/cHB1tBe.png

严重失败我知道有人能告诉我如何处理文字位置和内容吗?

非常感谢。

onCreate()

样式代码:

<div class="menu">
<ul>
    <li>
        <img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcSJGaeBPpPWONWkvBvhN3GcQxb_RVoIyAY7AxKuUuKFf0LFNkAUFVbuAZmEUtihSS0de0zFDx9v"/>
        <h3><a href="index.html">Jetliner with 155 on board loses chassis during takeoff in Russia</a></h3>
        <span>Pravda - </span><span>Mar 9, 2016</span>
        <p>A Boeing 737-400 en route Tyumen-Novy Urengoy lost chassis during takeoff on March 9 in Russia. Representatives of Yamal airline told ...</p>
    </li>

    <li>
        <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAdHx8kKDQsJCYxJx8fLT0tMTU3Ojo6Iys/RD84QzQ5OjcBCgoKDQwNGg8PGjclHyU3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3N//AABEIAGQAZAMBIgACEQEDEQH/xAAcAAABBAMBAAAAAAAAAAAAAAAABAUGBwECAwj/xAA3EAACAQMCBAQDBwMEAwAAAAABAgMABBEFEgYhMUETUWFxFCKBByMyQpGhwTOx0VJi8PEWJCX/xAAZAQADAQEBAAAAAAAAAAAAAAAAAgMBBAX/xAAfEQACAgMBAAMBAAAAAAAAAAAAAQIRAxIhMSJBURP/2gAMAwEAAhEDEQA/ALxoopJcajawD55lz5A5NY3QCutZJEj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J98f37YqpbNGcGdhiM5A/wB5/wAVYPAPEpO3RdQfJ62shP1KH+P08q6M8Xpw5sTW3Sa6lfQ2dlJcSERRxLliP7VL+Erqzv8AQrW8sGLRzLltx+YMOTKfUHIqkPtK1vbd2+mRN8iESz47n8oP05/UUp4G4xueG5p1wJrCRRM8JPRuhK+R5e1LhhUbZuadui/6KbtC1qx13T0vdPl3xt1U8mQ+TDsacaqTCiiigDyDIx3HnXJnGMHmPKt7llL5UbfMUnJpxUdll2jkOldvGhuFAJ2TL0pBM6xqHkOF7DuaT7pGIk5Rqxyo6k1lhQ82uq3mlMxspQEY/eQv+Fj5111C+TWVheWMxeEx3AHIb0FNro0kLyMd3hrnpzz5VotwCoC8lHICl0jdj7yqhw8TxH5DAUYAHYV1hGWZ+jAjaw6jHcUktzhSxrt4pSPAHuacma6xNLcP8TO5klZyXY9STRbzFrEbTzTKt7GsMviQHeRzpJZsY5mib8LjFAEs4e4nv+H5IL/T5MYAWWM/hkXyI+lX5wdxZYcVaf8AEWjBJ0A8a3Y/NGf5HrXmO1YZe1kJ65U04aJq17oOspd6ZMY5YyB6MO4I7j0rGrBM9WUVE9B490fUdNjnvLmKyuPwyQyN0I7jzFYpaGs80SdTWsIDOA3Ss0U7MG1mM94PE5jOAOwpQ53XGD0HSs0ViNF8Dk2yKcYZRn1poi5EgdjiiihmDlbk+Evua3JPhj1NFFaYYlP3ApOv9RT3BrFFAIU3J2PFIvJs0vCKJi2OZ61iigCZcG6RZ6rps097HvkW4ZAfIBV/zRRRQB//2Q=="/>
        <h3><a href="index.html">How Much Should You Spend on College and Student Loans?</a></h3>
        <span>Black Enterprise - </span><span>Apr 20, 2016</span>
        <p>The National Center for Education Statistics has a website that can help you calculate costs. CNN Money's College Cost Calculator is a great ...</p>
    </li>

</ul>
</div>

3 个答案:

答案 0 :(得分:1)

你可以尝试像这样的somtehing

#container{
  width: 500px;
 height: 200px;
 
}
#imgContainer{
  width: 30%;
  height: 100%;
  float:left;
  
}
#imgContainer img{
  width: 100%;
  height: 100%;
}
#textContainer{
padding:12px;
float: left;
}
  <div id="container">
   <div id="imgContainer"><img src="http://lorempixel.com/200/400/" alt=""></div>
 <div id="textContainer">
     <h2>Hello world this is some text </h2>
     <p> and here is some smaller text </p>
 </div>
  
 </div>

`

答案 1 :(得分:0)

可能听起来很刺耳,但是如果你开始删除所有的CSS,并提供你的图片float:left;并将其移到li的底部可能会让你继续前进。 古德勒克

答案 2 :(得分:0)

您可以将<li>中的元素放入<section>并应用此link

中的样式
      <ul>
    <li>
      <section>
        <div class="left">
          <img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcSJGaeBPpPWONWkvBvhN3GcQxb_RVoIyAY7AxKuUuKFf0LFNkAUFVbuAZmEUtihSS0de0zFDx9v" />
        </div>
        <div class="right">
          <h3><a href="index.html">Jetliner with 155 on board loses chassis during takeoff in Russia</a></h3>
          <span>Pravda - </span><span>Mar 9, 2016</span>
          <p>A Boeing 737-400 en route Tyumen-Novy Urengoy lost chassis during takeoff on March 9 in Russia. Representatives of Yamal airline told ...</p>
        </div>

      </section>
    </li>
  </ul>

查看对原始代码的修改:

https://jsfiddle.net/xwaLsd8p/