使文本和图像并排显示并根据设备更改大小

时间:2019-07-01 13:37:09

标签: html css twitter-bootstrap

我正在尝试创建自己的个人网站。我想做两件事:

  1. 在页面的左侧显示图片,在右侧显示一些文本。

  2. 根据设备调整图像和文本的大小。

这是我正在使用(使用)的代码:

<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<div class="row">
 <div class="indexbox">
   <div class="col-xs-5 col-sm-6 col-lg-4 col-md-4">
     <img class="img-responsive img-border img-left" src="https://upload.wikimedia.org/wikipedia/en/thumb/1/17/Bugs_Bunny.svg/300px-Bugs_Bunny.svg.png" height="190" width="142" alt="">
     </img>
   </div>
   <div class="col-xs-7 col-sm-6 col-lg-8 col-md-8">
     <p class="visible-xs">
       <p> Hi I'm XXXXXXX, a PhD Candidate in XXXX at XXXXX, XXXXXXXXXXX. <br /> <br /> 
                  Before joining the YYYYYYYY PhD program at YYYYYYYY, I received a BA in YYYYYYYY from YYYYYYYY, YYYYYYYY and a MS in YYYYYYYY Economics from YYYYYYYY, YYYYYYYY. My research broadly focuses on YYYYYYYY.  
       </p>
     </p>
   </div>
 </div>
</div>

不幸的是,我似乎无法获得理想的结果。我认为这里的两个代码:col-xs-7 col-sm-6 col-lg-8 col-md-8img-responsive img-border img-left应该能够实现结果,但是它似乎并非一直有效。有人可以帮我一下吗?

P.S。我在这里测试代码:

https://www.w3schools.com/html/tryit.asp?filename=tryhtml_intro

3 个答案:

答案 0 :(得分:1)

尝试一下

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

<div class="row">
  <div class="col-4">
    <img class="img-responsive img-thumbnail" src="https://upload.wikimedia.org/wikipedia/en/thumb/1/17/Bugs_Bunny.svg/300px-Bugs_Bunny.svg.png" height="190" width="142" alt="">
  </div>
  <div class="col-8">
    <p class="visible-xs">
      <p> Hi I'm XXXXXXX, a PhD Candidate in XXXX at XXXXX, XXXXXXXXXXX. <br />
        <br /> Before joining the YYYYYYYY PhD program at YYYYYYYY, I received a BA in YYYYYYYY from YYYYYYYY, YYYYYYYY and a MS in YYYYYYYY Economics from YYYYYYYY, YYYYYYYY. My research broadly focuses on YYYYYYYY.
      </p>
    </p>
  </div>
</div>

答案 1 :(得分:1)

https://jsfiddle.net/16e7qkn8/11/

<tr class="row" style="display:inline-block;">

图片:style=" width: 100%;height: auto;"

您可以像这样使用Tables和CSS

答案 2 :(得分:0)

也许您的Bootstrap连接不正确。 试试这个:

https://jsfiddle.net/

<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
  <div class="row">
    <div class="col-sm-6">
      <img class="img-responsive img-border img-left" src="https://upload.wikimedia.org/wikipedia/en/thumb/1/17/Bugs_Bunny.svg/300px-Bugs_Bunny.svg.png" height="190" width="142" alt="">
    </div>
    <div class="col-sm-6">
   <p> Hi I'm XXXXXXX, a PhD Candidate in XXXX at XXXXX, XXXXXXXXXXX. <br /> 
<br /> 
                Before joining the YYYYYYYY PhD program at YYYYYYYY, I received a BA in YYYYYYYY from YYYYYYYY, YYYYYYYY and a MS in YYYYYYYY Economics from YYYYYYYY, YYYYYYYY. My research broadly focuses on YYYYYYYY.  
    </p>
    </div>

  </div>
</div>
</body>
</html>