Стиль CSS для логотипа и текста в одной строке - PullRequest
0 голосов
/ 31 мая 2018

Я пытаюсь добиться следующего и не могу заставить его делать то, что я хочу.

  • 90% страницы и по центру
  • 5px подчеркивание
  • логотип слева
  • текст справа, но справа внизу выровнено

.box2 {
  border-bottom: 5px solid #2ea9e0;
  overflow: hidden;
  max-width: 90%;
}

.alignleft {
  float: left;
}

.alignright {
  float: right;
  vertical-align: bottom;
  overflow: hidden;
}

img {
  width: 115px;
  height: 91px;
}
<div class="box2">
  <p class="alignleft"><img src="http://placehold.it/115x91" alt=""></p>
  <p class="alignright">Hello</p>
</div>
<div style="clear: both"></div>

Что я хочу сделать What I want to do

Что я получаю What I am getting

Ответы [ 5 ]

0 голосов
/ 31 мая 2018

Вы можете сделать это с помощью Flexbox :

.box2 {
  display: flex; /* displays flex-items (children) inline */
  align-items: flex-end; /* vertically aligns them at the bottom */
  justify-content: space-between; /* places them away from each other as far as it can */
  border-bottom: 5px solid #2ea9e0;
  overflow: hidden;
  max-width: 90%;
  margin: 0 auto;
}

img {
  width: 115px;
  height: 91px;
}
<div class="box2">
  <p class="alignleft"><img src="http://placehold.it/115x91" alt=""></p>
  <p class="alignright">Hello</p>
</div>
0 голосов
/ 31 мая 2018

.box2{
   align: center;
   border-bottom: 5px solid #2ea9e0;
   overflow: hidden;
   max-width: 90%;
   margin-left:15px
}

.alignleft {
    float: left;
}
.alignright {
    float: Right;
        vertical-align: bottom; 
        overflow:hidden;
     
        padding: 0px 0px 0px 10px;
}
<div class="box2">
<p class="alignleft"><img src="logo.jpg" alt="" width="115" height="91" /></p>
<p class="alignright">Hello</p>
</div>
0 голосов
/ 31 мая 2018

Использовать свойство flex.С этим нет необходимости для свойства float.

 

.box2{
   display: flex;
   align-items: flex-end;
   margin: 0 auto;
   border-bottom: 5px solid #2ea9e0;
   overflow: hidden;
   max-width: 90%;
}

.alignright {
     margin-left: auto;  
     margin-bottom: 0;      
     padding: 0;
}
p {
     padding: 0;
     margin-bottom: 0;      
}
<div class="box2">
<p class="alignleft"><img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxAQEBAPDxIPDQ8PDg8QDQ8PDw8PDw0PFRcWFhURFRUYHSggGB0lGxUVITEhJSktLi4uFx8zODMsNyguLjcBCgoKDg0OGBAQGi0eHR0tKy0tKzctKy4rLS0vLS0tLy0rLSsrLSsrLSs1LSstLS0tLS0rLisrLS0tLTctLS0tK//AABEIAKMBNgMBIgACEQEDEQH/xAAcAAEAAQUBAQAAAAAAAAAAAAAABwMEBQYIAQL/xABEEAABAwICBgUJBAkDBQAAAAABAAIDBBEFIQYHEjFBURMyYXGxCBQiNXJ0gZGyJUJSoSNDYoKSs8HE0TOi0hVTk9Ph/8QAGgEBAAMBAQEAAAAAAAAAAAAAAAECAwQFBv/EACcRAQACAgECBQQDAAAAAAAAAAABAgMRMSFBBBIyUWETFCKxQpHR/9oADAMBAAIRAxEAPwCcUREBERAREQEREBck60/XOI+8n6WrrZck60/XOI+8n6WoNVREUJEREBERARFk8P0dragB0FLUysdukbDJ0due3bZA7boMYi2UaA4nxp2t9qppW/kXr4l0HxBv6ph7qmm/5oNdRZOp0erI+tBJbiWDpQO8svZY1zSCQQQRvBFiPgg8REQEREBERAU3eTPvxTuof7hQipu8mffindQ/3CCckRFKBERAREQEREBERAREQEREBERAREQFyTrT9c4j7yfpautlyVrS9c4j7yfpaolMNURfVl5ZNjxF7ZZXRzR6oxCYQUzQSBtSSPJbFAzi+R3AfmTkASgxkELpHNYxrpHuIaxjGlz3k7gAMyVI2jmqiZ4EmIyeaMOfm8Wy+pcM+serHw37R5gKQNFtF6XDGfoB0tQW2lq3tAlfzawfq2dgzPElZOSRBi8L0eoKK3m1NE14z6aQdNPe1rh777P7tgrmqqXOzcST2kleyyKxnlQUaiRYyokVeolWMqZUFvUSrEV+y8Wka2QcNsB1u7krmpmWKqZUGHrcJj3xkxn8Ju5v+QsI9tiQeBIPwWxTSLX3m5J5kn80Hwi9slkHiL6smymx8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i9RB4vURB4i9RAXi9RAXgXqICIiDxSvqD6+I+zR+M69RaYfXCmT0yl5ERd7mEREBERAREQEREH//Z" alt="" width="115" height="91" /></p>
<p class="alignright">Hello</p>
</div>
0 голосов
/ 31 мая 2018

.box2{
   align: center;
   border-bottom: 5px solid #2ea9e0;
   overflow: hidden;
   max-width: 100%;
}

.alignleft {
    float: left;
    
}
.alignright {
		float: right;
        vertical-align: bottom; 
		margin-top:90px;
}
<div class="box2">
  <p class="alignleft">
   <img src="https://www.w3schools.com/howto/img_avatar.png" alt="" width="115" height="91" />
   </p>
<p class="alignright">HELLO</p>
</div>
0 голосов
/ 31 мая 2018

flex поможет вам достичь этого.Добавлено немного css в .box2.Здесь align-items: baseline; с flex решит вашу проблему.

.box2{
   align: center;
   border-bottom: 5px solid #2ea9e0;
    overflow: hidden;
    max-width: 90%;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.alignleft {
    float: left;
}
.alignright {
    float: right;
        vertical-align: bottom; 
        overflow:hidden;
}
<div class="box2">
<p class="alignleft"><img src="http://via.placeholder.com/140x100" alt="" width="115" height="91" /></p>
<p class="alignright">Hello</p>
</div>
<div style="clear: both;"></div>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...