I'm trying to have texts stay next to divs like this image. However, when I resize the window, the text is under the div even though some text could fit between the gap. Is there any way to make them stay together? Both are display: inline-block;, and I have tried word-break: break-all; and overflow-wrap: break-word; but both don't work. Also, float left just messes up the whole thing and pushes everything up.
h3 {
position: relative;
color: var(--font-color);
font-size: 20px;
text-transform: uppercase;
display: inline-block;
margin-left: 5px;
word-break: break-all;
overflow-wrap: break-word;
}
.divider {
display: inline-block;
height: 15px;
width: 2px;
position: relative border-radius: 30px;
background: #0099ff;
margin-left: 35px;
}
<div class="divider"></div>
<h3>global average temperature</h3>
You can use the flexbox structure. Due to its structure, the elements in it will be inline-block automatically. I've tested it, they don't come bottom to bottom in the case of any width at the moment.
If you don't want to build this structure, you can also edit your code according to the resolution sizes with media query.
CSS:
h3{
margin-left: 5px;
}
.divider {
height: 15px;
width: 2px;
border-radius: 30px;
background: #0099ff;
margin-left: 35px;
}
.container-content {
display: flex;
align-items: center;
}
HTML:
<div class="container-content">
<div class="divider"></div>
<h3>global average temperature</h3>
</div>
Related
I have a gallery of masonry images and I want to place on each image a div with buttons.
My problem is that the div is not responsive and when I reduce the screen some buttons disappear rather than slow down and follow the movement of the screen.
I intend that by decreasing the screen the buttons will decrease and still appear all within the div.
HTML
<ul class="mdc-image-list mdc-image-list--masonry masonry-image-list second">
<li class="mdc-image-list__item" *ngFor="let image of list; let i = index;">
<img [src]="image" class="mdc-image-list__image">
<div class="mdc-image-list--with-text-protection">
<div class="mdc-image-list__supporting">
</div>
</div>
</li>
</ul>
The main problem to solve here is to align the icons next to each other, without using margin-left or float: left;. You can do this with display: flex; and justify-content: space-between; to the parent class (.mdc-image-list__label). This makes sure that each item gets displayed next to each other and the space-between ensures that there is equal space between each element. Read more about flexbox at MDN.
Updated StackBlitz for the adjustments.
.Pin{
margin-top: 8px;
width: 30px;
height: 30px;
cursor: pointer;
}
.Inbox{
width: 30px;
height: 30px;
margin-top: 8px;
cursor: pointer;
}
.Chat{
width: 30px;
margin-top: 10px;
height: 27px;
cursor: pointer;
}
.Task{
width: 30px;
height: 30px;
cursor: pointer;
margin-top: 8px;
}
// Adjusting this class
.mdc-image-list__label {
display: flex;
justify-content: space-between;
padding: 0 10px;
box-sizing: border-box; // To make sure it encapsulates the padding styling
}
Individual class to each image is unwarranted, so you can remove it and it's related css as well. The below css will fix your issue, it's more generic and better.
.mdc-image-list__supporting a {
width: 25%;
display: inline-block;
text-align: center;
}
.mdc-image-list__supporting a img {
width: 25px;
height: 25px;
cursor: pointer;
margin: 10px 0;
}
Regarding https://jsfiddle.net/postiffm/74cxr092/
> <div id="Tagline">
> I'm in the center.
> <div id="TaglineLeft"></div>
> <div id="TaglineRight">I am a phone #</div> </div>
How can I align the text in the TaglineRight so it has some space above it like the text in the center section? I've tried some padding and margin stuff, but nothing seems to work.
Thanks.
add line-height:30px; to #TaglineRight a
#TaglineLeft, #TaglineRight {
position: absolute;
color: white;
font-weight: normal;
text-align: center;
height: 100%;
width: 30%;
top: 0;
border-radius: 7px;
height: 20px;
padding: 5px;
}
you may add height: 20px; and padding: 5px; to #TaglineLeft, #TaglineRight { class
an old fashion way is to treat the child element as an table data by set it to display: table-cell, vertical-align: middle; & set it's parent to display: table;.
in that way you can change the height of the parent to whatever/whenever you like to and the child element will always stay vertical aligned. not like CSS3 solutions, it will work in old browsers too and cross browser support of course.
https://jsfiddle.net/ryf0w7rp/ - try to change the "#Tagline" element's height from 20px to other value and see the result.
*if you don't want main wrapper elements to use display: table so you can create another level of element to use display: table.
*for the example i made the solution just for the "#TaglineRight" element which has an inner <a> element. to make the other elements work the same, add the same structure and set the CSS to the right elements.
Instead of playing around with position:absolute/relative.
Consider using display:flex
check this solution
#Tagline {
color: white;
font-weight: normal;
letter-spacing: 2px;
text-align: center;
margin-bottom: 10px;
border: 0 solid #ff9706;
border-radius: 7px;
background-color: #ff9706;
display: flex;
height:30px;
line-height: 30px;
justify-content: space-between;
}
#TaglineLeft,
#TaglineRight {
color: white;
height: 100%;
width: 30%;
border-radius: 7px;
text-align: center;
}
#TaglineLeft {
margin-top: 0px;
background-color: #6673aa;
order: -1;
}
#TaglineRight {
border: 0 solid #7e922e;
background-color: #7e922e;
}
#TaglineRight a {
color: white;
letter-spacing: 1px;
text-decoration: none;
}
<div id="Tagline">
I'm in the center.
<div id="TaglineLeft">left line</div>
<div id="TaglineRight">I am a phone #
</div>
</div>
Hope it helps
In this style of using line-height and inline-block, why is the green item a few pixels below the middle? Shouldn't there be exactly 15px above and below?
.container{
height: 45px;
line-height: 45px;
background-color: red;
display: inline-block
}
.item{
height: 15px;
width: 15px;
background-color: green;
vertical-align: middle;
display: inline-block
}
<div class="container">
<div class="item">
</div>
</div>
I know there are other ways of vertically aligning items (including JS, absolute positions, and many more). I'm not trying to solve the general "how to vertically align a div".
The culprit here is not so much the line-height, but rather the vertical-align: middle. It tries to align your box with the text that may hypothetically be inside the parent box. Where the inner box ends up depends on the font-size of that text. You can push the box further down by increasing the font-size of its parent:
.container{
height: 45px;
width: 100%;
line-height: 45px;
font-size: 45px;
background-color: red;
display: inline-block
}
.item{
height: 15px;
width: 40px;
background-color: green;
vertical-align: middle;
display: inline-block;
}
<div class="container">
job
<div class="item">
</div>
</div>
As you can see, the text is closer to the bottom of its container than to the top (the "j" overflows the container while the "b" does not).
In the same way, you can move the box closer to the center by decreasing the font-size. Since you asked in comments, here's how you get it optimally centered with this method: Set font-size to 0 on the container.
.container{
height: 45px;
width: 100%;
line-height: 45px;
font-size: 0px;
background-color: red;
display: inline-block
}
.item{
height: 15px;
width: 40px;
background-color: green;
vertical-align: middle;
display: inline-block;
}
<div class="container">
job
<div class="item">
</div>
</div>
Changes in your style may help you
.container {
background-color: #ff0000;
display: table-cell;
height: 45px;
vertical-align: middle;
}
.item {
background-color: #008000;
display: table-cell;
height: 15px;
vertical-align: middle;
width: 15px;
}
Please use dividable size to make this work. Also remove vertical align attribue
https://jsfiddle.net/guc6uxc7/
.container{
height: 42px;
line-height: 42px;
background-color: red;
display: inline-block
}
.item{
height: 12px;
width: 12px;
background-color: green;
display: inline-block;
}
I have a basic block(purple) that has some text inside it of variable length. The div is position relative and is also responsive so its width etc is in %.
Some of our users on Chrome latest (v43.0.2357.65) and WinXP see the text overflows to the edge of the purple box. This happens on a whim so its hard to reproduce. I am trying to fix the CSS so that text does not overflow. I have a max-width and break-word property too on the div that contains the text.
The site is in dutch.
<div class="mt-landing__section-notification">
<div class="mt-landing__section-notification__info-icon icon-info"></div>
<div class="mt-landing__section-notification__close-icon"></div>
<div class="mt-landing__section-notification__content">
<div class="mt-landing__section-notification__message">
This is where the text is.
</div>
</div>
</div>
And here is the CSS on the outermost div and the one containing the text :
.mt-landing__section-notification {
z-index: 1;
width: 64.5%;
background-color: #411E4E;
padding: 20px;
color: #fff;
box-sizing: border-box;
position: relative;
float: left;
margin-top: 0px;
display: block;
}
.mt-landing__section-notification__message {
line-height: 24px;
margin-top: -3px;
word-wrap: break-word;
max-width: 100%;
}
.mt-landing__section-notification__content {
margin: 0px 50px;
}
.mt-landing__section-notification__info-icon {
width: 50px;
float: left;
font-size: 24px;
}
.info-icon {
font-family: mt-icons;
font-style: normal;
font-weight: 400;
font-variant: normal;
text-transform: none;
line-height: 1;
}
.info-icon::before {
content: '\e617';
}
Any ideas why text is overflowing ?
It looks like your info-icon might be the culprit here.
either
a) Set the icon to position:absolute and the container to position:relative, which will take the icon out of the flow, so it won't push the text to the right,
or
b)
maybe use the icon as a background-image. Simply increase the padding-left of the container and add it as a background-image. I find this to be the easiest way to keep things in order, whilst still flexible and responsive:
https://jsfiddle.net/svArtist/s3xc3nro/
.mt-landing__section-notification {
z-index: 1;
width: 64.5%;
padding: 20px;
color: #fff;
box-sizing: border-box;
position: relative;
float: left;
margin-top: 0px;
display: block;
}
.mt-landing__section-notification__message {
line-height: 24px;
margin-top: -3px;
word-wrap: break-word;
max-width: 100%;
}
.icon-info{
background: url(http://www.grafik-wunder.de/klafo/images/info.png) #411E4E no-repeat 10px center;
padding-left: 50px;
min-height: 50px;
box-sizing:border-box;
}
<div class="mt-landing__section-notification icon-info">
<div class="mt-landing__section-notification__close-icon"></div>
<div class="mt-landing__section-notification__content">
<div class="mt-landing__section-notification__message">This is where the text is.</div>
</div>
</div>
I have been trying to align two elements, a h2 and a div side by side without having one of them colapse when the window changes to a smaller size. I've searched the web a bit but found nothing similar that would help and my solutions just wouldn't work so I though here there would be someone able to help me.
So I want it to be displayed like this at all times:
https://imagizer.imageshack.us/v2/912x135q90/631/ZYR7sc.png (Can't post images sorry!)
But when window size changes dispite the fact the div should adapt at some point it just breaks to next line:
https://imagizer.imageshack.us/v2/730x144q90/912/yRBpkc.png
Here is my code on this one:
HTML
<div id='pagetitle'>
<h2 id='subtitle'>Weapons</h2>
<div id='hline'></div>
</div>
CSS
#pagetitle { /* This div is for centering both of the elements. */
width: 90%;
margin: 0 auto;
display: block;
}
#subtitle {
display: inline-block;
color: #72c9b9;
font-size: 30px;
font-weight: 300;
text-align: center;
}
#hline {
display: inline-block;
background-color: #72c9b9;
width: 70%;
height: 1px;
position: relative;
bottom: 4px;
margin-left: 20px;
}
So this is it guys, any sugestions? Thanks in advance.
cs.almeida
Here's a way how to do it:
demo
<div id='pagetitle'>
<h2 id='subtitle'><span>Weapons</span></h2>
</div>
#pagetitle {
width: 90%;
margin: 0 auto;
display: block;
}
#subtitle {
border-bottom: #72c9b9 solid 2px;
height: 18px;
display: block;
color: #72c9b9;
font-size: 30px;
font-weight: 300;
}
#subtitle > span {
background-color: white;
padding: 10px 20px;
}