I have a problem I have been trying to solve for a long time.
I have a responsive site, where I need to align a banner image and a text next to it. The banner image's max width is 1170px, but any size of image can be uploaded, so we have to force the max width by CSS.
It should look like something like this. The text should be vertical centered, and should fill the available space left by the image.
The problems arise when I have an image that is too big. In smaller screen sizes I cannot force the image to decrease it's size depending on the available screen size, so it will just overflow out of the screen.
It has to work until about 700px browser width. After that we have a breakpoint that forces the text to a new line, so we don't have this problem anymore.
So, the main points: The image's width is unknown, the amount of text is unknown (max 170 characters). The site is responsive, the max available space is 1170px, but it descreases as you make the browser window smaller.
Here is the relevant SASS code:
.logo img {
max-width: 1170px;
}
.logo, .logo-text {
text-align: center;
}
.logo-text {
font-weight: 700;
}
@media all and (min-width: breakpoint(4)) {
.logo {
@include flex(none);
@include ie8 {
width: 1px;
}
@include ie9 {
width: 1px;
}
}
.logo, .logo-text {
text-align: left;
@include ie8 {
display: table-cell;
vertical-align: middle;
}
@include ie9 {
display: table-cell;
vertical-align: middle;
}
margin-bottom: 0;
}
.logo-wrapper {
@include ie8 {
display: table;
}
@include ie9 {
display: table;
}
@include display(flex);
@include flex-direction(row);
@include flex-wrap(nowrap);
@include align-items(center);
}
.logo-text {
-ms-flex: 0 1 auto; //IE10 hack to wrap the text
}
}
Here is the relevant HTML code:
<div class="logo-wrapper">
<div class="logo">
<img src="https://xy.com/.png" alt="Logo">
</div>
<p class="logo-text" style="color: #FFF;">
This is a test This is a test This is a test This is aThis is a test This is a test This is a test This is a
</p>
</div>
It has to work in IE8+ and other major browsers!
This code have worked when the image's max width was 230px. But now it has to be increased to 1170px.