css 将文本放在左侧,图像放在另一侧[已关闭]

pinkon5k  于 2023-02-01  发布在  其他
关注(0)|答案(3)|浏览(161)

**已关闭。**此问题需要debugging details。当前不接受答案。

编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
昨天关门了。
Improve this question
我想有文字在左边的用户屏幕和右边的图像。看看我提供的原型![输入图像描述在这里][1]我找不到解决方案请帮助
我不能上传图片,但这里有一个链接到它https://photos.app.goo.gl/97ZLoYcLBsVsRnjc6
我试着用浮动来做。但是没有成功,因为按钮离文本太远了。图像不应该占用任何空间,它应该显示在右边

mrfwxfqh

mrfwxfqh1#

在这种情况下,我们可以使用flex
更多变更请参考CSS flex〉〉CSS Flex

* {
  padding: 0;
  margin: 0
}

.container {
  display: flex;
  justify-content: space-around;
  align-items:center;
  background-color: black;
  color: white;
  height:100vh
}

.container-button {
  border: none;
  background-color: white;
  color: black;
  padding: 0px 20px;
}

.container-img {
  height: 100px;
  width: 200px;
}
<div class="container">
  <div class="container-text">
    <h2>Hello World</h2>
    <h4>This is some Text</h4>
    <button class="container-button">button</button>

  </div>
  <img class="container-img" src="https://via.placeholder.com/200x100/FFFFFF/000000">
</div>
kg7wmglp

kg7wmglp2#

你可以这样做:

.container{
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.container-right-side img{
  margin-right: 2rem;
  max-width: 60vw;
  width: 100%;
}

.container-left-side{
  margin-left: 2rem;
}

@media screen and (min-width: 0px) and (max-width: 600px){
  .container{
    flex-direction: column; 
    
  }
  .container-left-side{
    margin-left: 0;
  }
}
<div class="container">
  <div class="container-left-side">
    <h2>Hello World</h2>
    <h4>This is Some text</h4>
    <button>button</button>
  </div>
  <div class="container-right-side">
    <img src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__340.jpg" />
  </div>
</div>
qvsjd97n

qvsjd97n3#

您可以使用类似于以下内容的内容:

.container {
  display: flex;
  justify-content: space-between;
  padding: 70px;
  background-color: black;
}

.text {
  display: flex;
  flex-direction: column;
  justify-content: center;
/*   align-items: center; */
  width: 50%;
  padding: 50px;
  color: white;
}

.image {
  width: 50%;
}

img {
  width: 100%;
  height: auto;
  border: 1px solid white;
}

button {
  max-width: 100px;
}
<div class="container">
  <div class="text">
    <h1>Hello World</h1>
    <p>This is Some Text</p>
    <button>Button</button>
  </div>
  <div class="image">
    <img src="https://via.placeholder.com/300 " alt="Image">
  </div>
</div>

相关问题