I have two child divs next to each other inside a parent div. I don't know what the height of either div has to be, because its generated by viewport-height.
My problem is that in the left div I have an image and I don't know how I can get that image the same size as the right div which needs to have height: auto. The parent div has to be adjust to the second child div.
HTML
<div class="post-info">
<a href="" class="post-link">
<div class="post-info_img"></div>
<div class="post-info_content">
<p class="categorie_info">Category</p>
<p class="titel">Header</p>
<p class="info">
Lorem ipsum dolor sit amet...
</p>
<p class="date">June 2018</p>
</div>
</a>
</div>
CSS
.post-info {
width: 90vw;
border-radius: 15px;
background-color: #F6F6F6;
box-shadow: 0px 3px 0px 0px rgba(0,0,0,0.2);
margin-bottom: 2.5vh;
display: table;
}
.post-info_img {
background-image: url('http://via.placeholder.com/350x150');
width: 30vw;
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
border-radius: 15px 0 0 15px;
display: table-cell;
}
.post-info_info {
padding: 5% 4vw;
display: table-cell;
}
.categorie_info {
color: #5B7AEB;
}
.titel {
font-size: 14px;
color: #2B2B2B;
margin: 0;
}
.info {
font-size: 14px;
margin-top: 5px;
}
.date {
font-size: 12px;
color: #707070;
}
.post-info {
width: 90vw;
border-radius: 15px;
background-color: #F6F6F6;
box-shadow: 0px 3px 0px 0px rgba(0, 0, 0, 0.2);
margin-bottom: 2.5vh;
display: table;
}
.post-info_img {
background-image: url('http://via.placeholder.com/350x150');
width: 30vw;
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
border-radius: 15px 0 0 15px;
display: table-cell;
}
.post-info_info {
padding: 5% 4vw;
display: table-cell;
}
.categorie_info {
color: #5B7AEB;
}
.titel {
font-size: 14px;
color: #2B2B2B;
margin: 0;
}
.info {
font-size: 14px;
margin-top: 5px;
}
.date {
font-size: 12px;
color: #707070;
}
<div class="post-info">
<a href="" class="post-link">
<div class="post-info_img"></div>
<div class="post-info_content">
<p class="categorie_info">Category</p>
<p class="titel">Header</p>
<p class="info">
Lorem ipsum dolor sit amet...
</p>
<p class="date">June 2018</p>
</div>
</a>
</div>
Looks like you've misspelled a classname in your CSS.
Find .post-info_info and replace it with .post-info_content:
.post-info {
width: 90vw;
border-radius: 15px;
background-color: #F6F6F6;
box-shadow: 0px 3px 0px 0px rgba(0, 0, 0, 0.2);
margin-bottom: 2.5vh;
display: table;
}
.post-info_img {
background-image: url('http://via.placeholder.com/350x150');
width: 30vw;
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
border-radius: 15px 0 0 15px;
display: table-cell;
}
.post-info_content {
padding: 5% 4vw;
display: table-cell;
}
.categorie_info {
color: #5B7AEB;
}
.titel {
font-size: 14px;
color: #2B2B2B;
margin: 0;
}
.info {
font-size: 14px;
margin-top: 5px;
}
.date {
font-size: 12px;
color: #707070;
}
<div class="post-info">
<a href="" class="post-link">
<div class="post-info_img"></div>
<div class="post-info_content">
<p class="categorie_info">Category</p>
<p class="titel">Header</p>
<p class="info">
Lorem ipsum dolor sit amet...
</p>
<p class="date">June 2018</p>
</div>
</a>
</div>
Issues
.post-info_info doesn't exist in HTML.
.post-link and .post-info_content don't exist in CSS.
.post-info is display:table yet its only child was .post-link that had no styles at all.
The 2 divs that have display:table-cell were .post-info_img (not a child of an element with display:table) and .post-info_info (doesn't exist in HTML).
That pretty much guarantees that your layout wouldn't even come close to the expected results.
Solutions
Made all classes very simple and semantic.
Changed all of the div tags to a semantic equivalent.
Assigned .link as display:flex so its children .img and .content sit side-by-side.
Changed background image into an img tag then assigned display:block, and object-fit:cover
Replaced percentage dimensions with intrinsic dimensions (ex. width:20% to width:20vw)
Added the Boba Fett because he pwns.
Demo
.info {
width: 90vw;
border-radius: 15px;
background-color: #F6F6F6;
box-shadow: 0px 3px 0px 0px rgba(0, 0, 0, 0.2);
margin-bottom: 2.5vh;
display: table;
font-size: 14px;
margin-top: 5px;
}
.link {
display: flex;
justify-content: center;
}
.img {
position: relative;
width: 35vw;
min-height: 40vh;
display: table-cell;
padding: 0;
overflow:hidden
}
.img img {
position: absolute;
top: 0;
bottom: 0;
right: .5em;
left: .5em;
width: 35vw;
min-height: 35vh;
object-fit: cover;
border-radius: 15px 0 0 15px;
overflow:hidden;
}
.content {
width: 50vw;
min-height: 40vh;
}
.category {
color: #5B7AEB;
font-variant: small-caps;
font-size: 1.25em
}
.title {
color: #2B2B2B;
margin: 0;
letter-spacing: 2px;
font-size: 16px;
line-height: 1.83em
}
.date {
color: #707070;
}
<section class="info">
<a href="" class="link">
<figure class="img">
<img src='https://www.sideshowtoy.com/wp-content/uploads/2018/01/star-wars-boba-fett-deluxe-version-sixth-scale-figure-hot-toys-feature-903352-900x600.jpg'>
</figure>
<article class="content">
<header class="category">Profile
<h1 class="title">Boba Fett</h1>
</header>
<p class="text">
"I am the best bounty hunter in the galaxy. I will find your rebel scum or the next carbonite bath is on me," Specializes in Jedi location...
</p>
<footer class="date"><small>June 2018</small></footer>
</article>
</a>
</section>
Related
THIS IS A RESPONSIVE DESIGN, MAKE SURE TO TURN ON TOGGLE DEVICE TOOLBAR ON YOUR BROWSER
I am trying to make a progress bar. First I want to increase the height of the transparent black background. I can't find a way to do that. I am confused. And secondly, I want to add spacing and align the 2nd and 3rd text properly.
/* progress bar */
.center {
height: 300px;
width: 100%;
position: absolute;
left: 50%;
margin-top: 140px;
transform: translate(-50%, -50%);
padding: 20px;
background-color: rgba(0, 0, 0, 0.678);
box-shadow: 0 2px 60px rgba(0, 0, 0, .5);
border-radius: 10px;
color: white;
}
.center #progress{
margin: 0px;
padding: 0;
color: #fff;
text-transform: uppercase;
letter-spacing: 8px;
border-radius: 20px;
height: auto;
background-color: rgba(0, 0, 0, 0);
}
.skillbar{
box-sizing: border-box;
width: 100%;
margin: 20px 0;
}
/* skillbar languages */
.skillbar-html p{
color: #fff;
text-transform: uppercase;
margin: 0 0 10px;
padding: 0;
font-weight: bold;
letter-spacing: 3px;
}
.skillbar-html p:nth-child(2){
float: right;
position: relative;
top: -30px;
}
.skillbar-css p{
color: #fff;
text-transform: uppercase;
margin: 0 0 10px;
padding: 0;
font-weight: bold;
letter-spacing: 3px;
}
.skillbar-css p:nth-child(2){
float: right;
position: relative;
top: -30px;
}
.skill_percentage{
background-color: #262626;
padding: 4px;
box-sizing: border-box;
border: 1px solid #0fffb7;
border-radius: 6px;
}
.skill_level{
background-color: #0fffb7;
width: 100%;
height: 10px;
border-radius: 6px;
}
<section>
<div class="center">
<h1 id="progress">Progress</h1>
<div class="skillbar-html">
<p>HTML</p>
<p>90%</p>
<div class="skill_percentage">
<div class="skill_level" style="width: 90%;"></div>
</div>
<div class="skillbar-css">
<p>CSS</p>
<p>70%</p>
<div class="skill_percentage">
<div class="skill_level" style="width: 80%;"></div>
</div>
<div class="skillbar-javascript">
<p>JavaScript</p>
<p>50%</p>
<div class="skill_percentage">
<div class="skill_level" style="width: 50%;"></div>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
</div>
</section>
</section>
You can take advantage of the <br> element in your HTML.
Line break and tab elements can be used when you need a little more control over how the browser renders the text. The <BR> element is used to force a line break.
-W3.org
/* progress bar */
.center {
height: 300px;
width: 100%;
position: absolute;
left: 50%;
margin-top: 140px;
transform: translate(-50%, -50%);
padding: 20px;
background-color: rgba(0, 0, 0, 0.678);
box-shadow: 0 2px 60px rgba(0, 0, 0, .5);
border-radius: 10px;
color: white;
}
.center #progress{
margin: 0px;
padding: 0;
color: #fff;
text-transform: uppercase;
letter-spacing: 8px;
border-radius: 20px;
height: auto;
background-color: rgba(0, 0, 0, 0);
}
.skillbar{
box-sizing: border-box;
width: 100%;
margin: 20px 0;
}
/* skillbar languages */
.skillbar-html p{
color: #fff;
text-transform: uppercase;
margin: 0 0 10px;
padding: 0;
font-weight: bold;
letter-spacing: 3px;
}
.skillbar-html p:nth-child(2){
float: right;
position: relative;
top: -30px;
}
.skillbar-css p{
color: #fff;
text-transform: uppercase;
margin: 0 0 10px;
padding: 0;
font-weight: bold;
letter-spacing: 3px;
}
.skillbar-css p:nth-child(2){
float: right;
position: relative;
top: -30px;
}
.skill_percentage{
background-color: #262626;
padding: 4px;
box-sizing: border-box;
border: 1px solid #0fffb7;
border-radius: 6px;
}
.skill_level{
background-color: #0fffb7;
width: 100%;
height: 10px;
border-radius: 6px;
}
<section>
<div class="center">
<h1 id="progress">Progress</h1>
<br>
<div class="skillbar-html">
<p>HTML</p>
<p>90%</p>
<div class="skill_percentage">
<div class="skill_level" style="width: 90%;"></div>
</div>
<br>
<div class="skillbar-css">
<p>CSS</p>
<p>70%</p>
<div class="skill_percentage">
<div class="skill_level" style="width: 80%;"></div>
</div>
<br>
<div class="skillbar-javascript">
<p>JavaScript</p>
<p>50%</p>
<div class="skill_percentage">
<div class="skill_level" style="width: 50%;"></div>
</div>
</div>
</div>
</div>
</div>
</section>
The Height: - I noticed a fixed height of 300px, and that you were centering the parent div by using margins and translations in your CSS. I went ahead and removed those margins and translations, also removed your absolute positioning. You can adjust your fixed height of 300px to expand the grey background. For this example, I made it 100 view height.
/* progress bar */
.center {
height: 100vh;
width: 100%;
padding: 20px;
position: relative;
background-color: rgba(0, 0, 0, 0.678);
box-shadow: 0 2px 60px rgba(0, 0, 0, .5);
border-radius: 10px;
color: white;
}
.center #progress{
margin: 0px;
padding: 0;
color: #fff;
text-transform: uppercase;
letter-spacing: 8px;
border-radius: 20px;
height: auto;
background-color: rgba(0, 0, 0, 0);
}
.skillbar{
box-sizing: border-box;
width: 100%;
margin: 20px 0;
}
/* skillbar languages */
.skillbar-html p{
color: #fff;
text-transform: uppercase;
margin: 0 0 10px;
padding: 0;
font-weight: bold;
letter-spacing: 3px;
}
.skillbar-html p:nth-child(2){
float: right;
position: relative;
top: -30px;
}
.skillbar-css p{
color: #fff;
text-transform: uppercase;
margin: 0 0 10px;
padding: 0;
font-weight: bold;
letter-spacing: 3px;
}
.skillbar-css p:nth-child(2){
float: right;
position: relative;
top: -30px;
}
.skill_percentage{
background-color: #262626;
padding: 4px;
box-sizing: border-box;
border: 1px solid #0fffb7;
border-radius: 6px;
}
.skill_level{
background-color: #0fffb7;
width: 100%;
height: 10px;
border-radius: 6px;
}
<section>
<div class="center">
<h1 id="progress">Progress</h1>
<br>
<div class="skillbar-html">
<p>HTML</p>
<p>90%</p>
<div class="skill_percentage">
<div class="skill_level" style="width: 90%;"></div>
</div>
<br>
<div class="skillbar-css">
<p>CSS</p>
<p>70%</p>
<div class="skill_percentage">
<div class="skill_level" style="width: 80%;"></div>
</div>
<br>
<div class="skillbar-javascript">
<p>JavaScript</p>
<p>50%</p>
<div class="skill_percentage">
<div class="skill_level" style="width: 50%;"></div>
</div>
</div>
</div>
</div>
</div>
</section>
If I understood properly, what you want to increase the height is for that black bar containing your actual progress bar, right? If that's the case, I think this should work:
.skill-percentage {
height: x (here you place how much height you want);
}
That should give you the height that you want.
And, in order to add the spacing, you can take advantage of CSS padding or margin, depending on what you exactly need.
I'll give you a small snippet here so you can see exactly what I mean. Note that I modified a bit your HTML to fit what you wanted to do, but this may not be necessary on your original file.
/* progress bar */
* {
margin: 0;
padding: 0;
}
.center {
height: 500px;
width: 100%;
background-color: rgba(0, 0, 0, 0.678);
color: white;
}
.center #progress{
margin: 0px;
padding: 0;
color: #fff;
text-transform: uppercase;
letter-spacing: 8px;
border-radius: 20px;
height: auto;
background-color: rgba(0, 0, 0, 0);
}
.skillbar{
box-sizing: border-box;
width: 100%;
margin: 0;
}
/* skillbar languages */
.text-container {
display: flex;
width: 100%;
justify-content: space-between;
}
.text-container p {
padding: 0 40px; /* this is the one that changes the position of your text. Be carefull, you don't want this to change the position too much, just a bit, if you need to change the full position, better try something like grid, or modifying the flex */
}
.skillbar-html {
display: flex;
flex-direction: column;
justify-content: center;
}
.skillbar-html p {
margin: 10px;
}
.skillbar-html > div {
margin: 10px;
}
.skillbar-css {
display: flex;
flex-direction: column;
justify-content: center;
}
.skillbar-css p {
margin: 10px;
}
.skillbar-css > div {
margin: 10px;
}
.skillbar-javascript {
display: flex;
flex-direction: column;
justify-content: center;
}
.skillbar-javascript p {
margin: 10px;
}
.skillbar-javascript > div {
margin: 10px;
}
.skill_percentage{
height: 20px; /* this is the one that changes your height, now it's changing nothing, but you can modify the height by changing this value */
background-color: #262626;
padding: 4px;
box-sizing: border-box;
border: 1px solid #0fffb7;
border-radius: 6px;
}
.skill_level{
background-color: #0fffb7;
width: 100%;
height: 10px;
border-radius: 6px;
}
<section>
<div class="center">
<h1 id="progress">Progress</h1>
<div class="skillbar-html">
<div class="text-container">
<p>HTML</p>
<p>90%</p>
</div>
<div class="skill_percentage">
<div class="skill_level" style="width: 90%;">
</div>
</div>
</div>
<div class="skillbar-css">
<div class="text-container">
<p>CSS</p>
<p>70%</p>
</div>
<div class="skill_percentage">
<div class="skill_level" style="width: 80%;">
</div>
</div>
</div>
<div class="skillbar-javascript">
<div class="text-container">
<p>JavaScript</p>
<p>50%</p>
</div>
<div class="skill_percentage">
<div class="skill_level" style="width: 50%;">
</div>
</div>
</div>
</div>
</section>
<ul class="child ">
<div style="text-align:right;"> <li class="nameBar">{{patientInfo.data.fname}} {{patientInfo.data.lname}}</li></div>
<li class="age">{{patientInfo.data.age}}|{{ patientInfo.data.gender}}</li>
<img class="breadcrumb-image" src="assets/images/user/user6.jpg" alt="...">
<li class='uhid'>UHID: {{patientInfo.data.uhid}}</li>
<li class="address">{{patientInfo.data.city}}</li>
</ul>
CSS:
.nameBar{
color:#00bcd4;
font-weight:bold;
margin: -7px 0px 0px -100px;
position: absolute;
font-size: 12px;
text-transform: capitalize;
}
.uhid{
margin:-39px 0px 0px 58px;
color:#00bcd4;
font-weight:bold;
font-size: 12px;
}
.age{
margin: 15px 0px 0px -35px;
font-size: 10px;
position: absolute;
}
.address{
margin: 4px 0px 0px 59px;
font-size: 10px;
}
.child {
position: fixed;
top: 72px;
left: 50px;
padding: 1em;
margin: 0px 0px 0px 571px;
}
.li{
border-width: 1px;
text-align:center;
float:left;
}
Always I need to start the name from right side of the image I tried with margin-right:calc(50% -(somePx)) not able to fix that name lable near the image as right side Uhid and place can any help me out in this thanks
it's not a good idea to use too much margins and absolute positioning.
take a look at this and change it to your needs.
.child {
position: fixed;
top: 0;
left: 0;
width: 100%;
padding: 1em;
display: flex;
justify-content: center;
}
.child>img {
width: 40px;
height: 40px;
margin: 0 5px;
}
.nameBar {
text-transform: capitalize;
}
.bold {
color: #00bcd4;
font-weight: bold;
font-size: 12px;
}
.small {
font-size: 10px;
}
.left,
.right {
line-height: 20px;
padding-top: 5px;
}
.left {
text-align: left;
}
.right {
text-align: right;
}
<div class="child">
<div class="right">
<div class="nameBar bold">John Doe</div>
<div class="age small">26 Male</div>
</div>
<img src="https://picsum.photos/40" alt="...">
<div class="left">
<div class='uhid bold'>UHID: 1234</div>
<div class="address small">Paris</div>
</div>
</div>
I'm using Bootstrap and would like to have three boxes of the same height align vertically.
Here you can see those three blocks, however I need them to be of equal height that will occupy maximum space. I can manually add some padding so it looks like that:
However when the block becomes smaller (bootstrap's grid) it breaks.
Any ideas?
Here's CSS code I'm using and HTML layout.
.caption {
height: 150px;
overflow: hidden;
position: relative;
padding: 0!important;
}
.caption-info{
width: 70%;
height: 100%;
display: inline-block;
padding: 9px;
}
.caption-flag:hover{
background: rgba(235, 75, 75, 1);
transition: background 0.2s ease;
}
.caption-flag{
cursor: help!important;
transition: background 0.2s ease;
position: absolute;
background: rgba(235, 75, 75, 0.75);
color: white;
font-weight: bold;
width: 100%;
text-align: center;
top: 20px;
z-index: 9999;
font-size: 20px;
}
.caption-info h4 { margin-top: 5px; margin-bottom:5px;}
.caption-prices{
width: 32%;
height: 100%;
display: inline-block;
position: absolute;
top: 0;
text-align: center;
}
.caption-prices h4{
margin-top: 0;
margin-bottom: 0;
font-weight: bold;
}
.caption-square, .caption-cost, .caption-total{
box-shadow: inset 10px 0px 20px -10px rgba(0,0,0,0.5);
padding-left: 0!important;
color: white;
font-size: 0.85em;
padding: 5.5px;
}
.caption-square{
background: green;
}
.caption-cost{
background: orange;
}
.caption-total{
background: red;
}
.thumbnail {
padding: 0;
position: relative;
}
<div class="row">
<div class="col-sm-4 col-lg-4 col-md-4">
<div class="thumbnail">
<img src="http://placehold.it/320x150" alt="">
<div class="caption">
<div class="caption-info">
<h4>Product Title</h4>
<p>This is a short description. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
<div class="caption-prices">
<div class="caption-square">
площадь
<h4>$24.99</h4>
</div>
<div class="caption-cost">
цена за м<sup>2</sup>
<h4>$24.99</h4>
</div>
<div class="caption-total">
стоимость
<h4>$24.99</h4>
</div>
</div>
</div>
</div>
</div>
</div>
Change this rule
.caption-square, .caption-cost, .caption-total{
box-shadow: inset 10px 0px 20px -10px rgba(0,0,0,0.5);
padding-left: 0!important;
color: white;
font-size: 0.85em;
padding: 5.5px;
height: 33%; /* added */
box-sizing: border-box; /* added */
}
Sample snippet
.caption {
height: 150px;
overflow: hidden;
position: relative;
padding: 0!important;
}
.caption-info{
width: 70%;
height: 100%;
display: inline-block;
padding: 9px;
}
.caption-flag:hover{
background: rgba(235, 75, 75, 1);
transition: background 0.2s ease;
}
.caption-flag{
cursor: help!important;
transition: background 0.2s ease;
position: absolute;
background: rgba(235, 75, 75, 0.75);
color: white;
font-weight: bold;
width: 100%;
text-align: center;
top: 20px;
z-index: 9999;
font-size: 20px;
}
.caption-info h4 { margin-top: 5px; margin-bottom:5px;}
.caption-prices{
width: 32%;
height: 100%;
display: inline-block;
position: absolute;
top: 0;
text-align: center;
}
.caption-prices h4{
margin-top: 0;
margin-bottom: 0;
font-weight: bold;
}
.caption-square, .caption-cost, .caption-total{
box-shadow: inset 10px 0px 20px -10px rgba(0,0,0,0.5);
padding-left: 0!important;
color: white;
font-size: 0.85em;
padding: 5.5px;
height: 33%;
box-sizing: border-box;
}
.caption-square{
background: green;
}
.caption-cost{
background: orange;
}
.caption-total{
background: red;
}
.thumbnail {
padding: 0;
position: relative;
}
<div class="row">
<div class="col-sm-4 col-lg-4 col-md-4">
<div class="thumbnail">
<img src="http://placehold.it/320x150" alt="">
<div class="caption">
<div class="caption-info">
<h4>Product Title</h4>
<p>This is a short description. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
<div class="caption-prices">
<div class="caption-square">
площадь
<h4>$24.99</h4>
</div>
<div class="caption-cost">
цена за м<sup>2</sup>
<h4>$24.99</h4>
</div>
<div class="caption-total">
стоимость
<h4>$24.99</h4>
</div>
</div>
</div>
</div>
</div>
</div>
I'm trying to create a template for some rotating spotlights we create here at work, and what I'm trying to do should be rather simple.
Here is my fiddle: http://jsfiddle.net/aeromax/2t4k4cf9/
What I'm trying to do, is to get #spotlightCTA to float right (easily doable) and align to the bottom of the #spotlightTitle, so that the call to action moves up or down depending on how tall the title is.
Here is the styles associated with these two divs:
#spotlightTitle {
width: auto;
height: auto;
display: inline-block;
bottom: 0px;
}
#spotlightCTA {
position: relative;
display: inline-block;
width: 300px;
text-align: right;
cursor: pointer;
right: 0px;
float: right;
}
And my HTML
<div id="spotlightContent">
<div id="spotlightTitle">
<div class="title">This is a test title.<br>Let's make it longer.
</div>
</div>
<div id="spotlightCTA" class="animate">
<span>This is a call to action.</span>
<button type="">Test button</button>
</div>
</div>
If I float right, it aligns to the top. If I remove the float, it aligns to the bottom but I can't get it to align to the right.
Thanks in advance!
Flexbox can do that.
div {
background-color: rgba(10, 10, 10, .2);
}
/*Containers*/
#spotlightContainer {
position: relative;
height: 200px;
width: 646px;
padding: 10px 20px 0px 20px;
background-color: rgba(0, 0, 0, .4);
}
#spotlightContent {
width: 646px;
height: auto;
padding: 30px 0px 0px 0px;
display: flex;
justify-content: space-between;
align-items: flex-end;
}
#spotlightTitle {
width: auto;
height: auto;
display: inline-block;
bottom: 0px;
}
/*CTA*/
#spotlightCTA {
position: relative;
display: inline-block;
width: 300px;
text-align: right;
cursor: pointer;
right: 0px;
float: right;
}
#spotlightCTA span {
font-family: "Open Sans", "Helvetica Neue", helvetica, arial, sans-serif;
font-weight: 300;
color: #fff;
display: inline-block;
padding: 5px 0px 0px 0px;
}
#spotlightCTA button {
background-color: #ffd200;
border-radius: 0px;
border: none;
margin: 0px 0px 0px 15px;
padding: 5px;
vertical-align: text-bottom;
}
.title {
font-family: "Oswald", "Helvetica Neue", helvetica, arial, sans-serif;
color: #fff;
font-weight: 600;
max-width: 400px;
font-size: 32px;
line-height: 1.2;
display: inline-block;
}
<div id="spotlightContainer">
<div id="spotlightContent">
<div id="spotlightTitle">
<div class="title">This is a test title.
<br>Let's make it longer.
</div>
</div>
<div id="spotlightCTA" class="animate">
<span>This is a call to action.</span>
<button type="">Test button</button>
</div>
</div>
</div>
This is my css:
.content {
background-color: #fff;
position: relative;
margin: 45px 10px 0px 10px;
}
#logData {
font-family: "Courier New";
font-size: 13px;
line-height: 1.3;
margin-left: 0px;
color: #000;
}
.logMess {
color:#000;
padding: 4px 5px 2px 3px;
min-width: 100%;
}
.logMessBg {
color:#000;
padding: 4px 5px 2px 3px;
min-width: 100%;
background: rgb(245, 245, 245);
}
And this is HTML:
<div class="content">
<div id="logData">
<p class="logMessBg">some loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong text</p>
<p class="logMess">some loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong text</p>
</div>
</div>
And the problem is with horizontal scroll. Because backgroud ends when <p class="logMessBg"> text ends, but I want it to end when the longest <p> text ends. So, I want to background width all width.
Here is the screen:
Add display: inline-block; to the .content or #logData like this:
JSFiddle - DEMO
.content {
background-color: #fff;
position: relative;
margin: 45px 10px 0px 10px;
display: inline-block;
}