When I have the following code:
.kitty {
height: 20vw;
width: 20vw;
}
<div class="container-fluid">
<div class="row">
<div class="content col-lg-12">
<img src="http://www.downesvets.co.uk/wp-content/uploads/2015/07/kitten-package1.png" alt="foo" class="kitty">
textextext <br> textextext
<img src="http://www.downesvets.co.uk/wp-content/uploads/2015/07/kitten-package1.png" alt="foo" class="kitty">
</div>
</div>
</div>
What I want is that the text is that the <br> element applies to the text but that the images are still in one line. like this:
Which HTML or CSS do I have to use in order to achieve this?
-
if you are using the last version of boostrap i advice you to check my answer as you can simply rely on flex and use predefined classes ;) [am not looking for upvotes or accepted answer but simply for you to get more ways that are suitable for your situation]Temani Afif– Temani Afif2018年01月08日 19:44:45 +00:00Commented Jan 8, 2018 at 19:44
3 Answers 3
There were some unnecessary elements. I removed those and made your markup simpler.
.kitty {
height: 20vw;
width: 20vw;
}
.kitty-text {
display: inline-block;
}
<div>
<img src="http://www.downesvets.co.uk/wp-content/uploads/2015/07/kitten-package1.png" alt="foo" class="kitty">
<span class="kitty-text">textextext <br> textextext</span>
<img src="http://www.downesvets.co.uk/wp-content/uploads/2015/07/kitten-package1.png" alt="foo" class="kitty">
</div>
5 Comments
.row and .col-. The simpler setup will accomplish the same fluid layout.Then you need to put all the text in one span element and display it as inline-block like this:
.kitty {
height: 20vw;
width: 20vw;
}
.content span {
display: inline-block;
}
<div class="container-fluid">
<div class="row">
<div class="content col-lg-12">
<img src="http://www.downesvets.co.uk/wp-content/uploads/2015/07/kitten-package1.png" alt="foo" class="kitty">
<span>textextext <br> textextext</span>
<img src="http://www.downesvets.co.uk/wp-content/uploads/2015/07/kitten-package1.png" alt="foo" class="kitty">
</div>
</div>
</div>
Note: I used the .content span selector, but you may have to use a different selector (perhaps give a class to the span) if you have other .content elements with span children on the same page and don't want them to behave the same.
Comments
You can simply use flex and you don't have to change your markup:
.kitty {
height: 20vw;
width: 20vw;
}
.content {
display:flex;
/* For vertical & horizontal alignment */
justify-content:space-around;
align-items:center;
/* */
}
<div class="container-fluid">
<div class="row">
<div class="content col-lg-12">
<img src="https://lorempixel.com/100/100/" alt="foo" class="kitty"> textextext <br> textextext
<img src="https://lorempixel.com/100/100/" alt="foo" class="kitty">
</div>
</div>
</div>
And it seems you are using Bootstrap, so if it's the V4, you will find ready classes for the CSS I added as this version rely on flex too.
.kitty {
height: 20vw;
width: 20vw;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">
<div class="container-fluid">
<div class="row">
<div class="content col d-flex justify-content-around align-items-center">
<img src="https://lorempixel.com/100/100/" alt="foo" class="kitty"> textextext <br> textextext
<img src="https://lorempixel.com/100/100/" alt="foo" class="kitty">
</div>
</div>
</div>