This question already has answers here:
Why is the paragraph not floating beside the profilePic?
(3 answers)
Closed 6 years ago.
Why does making span float:left or display:inline-block or both move the span class below the profilePic?
.content {
margin-top: 30px;
margin-left: 20px;
padding-bottom: 20px;
float: left;
}
.mainContent {
width: 1000px;
float: left;
}
.infoBit {
display: inline-block;
font-size: 1.1em;
padding-right: 10px;
padding-top: 10px;
}
.profilePic {
border: 1px blue solid;
height: 59px;
display: inline-block;
width: 44px;
margin: 0px;
float: left;
margin-right: 3px;
}
span {
margin-top: 0px;
float: left;
}
<div class="content">
<div class="mainContent">
<div class="infoBit">
<div class="profilePic"></div>
<span> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam quis enim ut sapien sodales commodo. Fusce congue, elit a finibus fermentum, diam eros mollis massa, at eleifend sapien dui eget mauris. Donec nec diam enim. Vivamus commodo placerat risus vitae auctor. Cras leo elit, egestas eget dolor vitae, facilisis consequat sem. Mauris facilisis ipsum in porttitor ullamcorper. Nam vel massa sed quam venenatis facilisis. Quisque vitae mollis urna. In egestas nunc sed felis consequat, in malesuada dolor feugiat. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</span>
<div class="social">
<div class="Like"></div>
<div class="Dislike"></div>
<div class="share"></div>
</div>
</div>
</div>
</div>
you need to float only one thing
try this
CSS
.content
{
margin-top : 30px;
margin-left: 20px;
padding-bottom: 20px;
}
.mainContent
{
width: 1000px;
float: left;
}
.infoBit
{
display: inline-block;
font-size: 1.1em;
padding-right: 10px;
padding-top: 10px;
}
.profilePic
{
border:1px blue solid;
height: 59px;
display: inline-block;
width: 44px;
margin: 0px;
float: left;
margin-right: 3px;
}
span
{
margin-top: 0px;
}
Related
there is a box with text, at the right of the box there is an image
The box of text is have z index higher than image, so box of text look like in front of image
I used text-align center, to center all components inside div, and this is a must
Now I want the only text, only the text in box of text is align left
How can I achieve this?
.button-yellow, .button-red {
font: 16px AdobeCaslonPro;
text-decoration: none;
padding: 6px 12px 6px 12px;
border-right: 1px solid #333333;
border-bottom: 1px solid #333333;
border-radius: 4px;
moz-border-radius: 4px;
webkit-border-radius: 4px;
font-style: italic;
}
.button-yellow {
background-color: #ccb96b;
color: #430615;
}
.button-red {
background-color: #430615;
color: #ccb96b;
margin-top: -20px;
}
#section-welcome-content {
text-align: center;
}
#welcome-content{
width: 45%;
margin: 0 0 0 0 ;
}
#welcome-content-inner {
background-color: #ccb96b;
color: #430615;
padding: 50px;
z-index: 10;
position: relative;
}
#welcome-content p{
}
#crop {
width: 600px;
height: 500px;
overflow: hidden;
margin: 0 0 0 -50px ;
}
#crop img {
width: 800px;
height: 600px;
margin: -75px 0 0 -100px;
z-index: 1;
}
<section id="section-welcome-content" class="pad">
<div id="welcome-content" style=" display: inline-block; " >
<div id="welcome-content-inner" >
<p>
<h3 style="font-size: 1.5em; text-transform: uppercase;"> <i>Lorem ipsum</i> </h3>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris arcu sapien, dignissim id laoreet quis, sollicitudin sed dui. Mauris mauris ligula, hendrerit sed ligula vitae, viverra auctor eros. Duis rutrum dolor a felis elementum, eu facilisis justo sollicitudin.
<br><br>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris arcu sapien, dignissim id laoreet quis, sollicitudin sed dui. Mauris mauris ligula, hendrerit sed ligula vitae, viverra auctor eros. Duis rutrum dolor a felis elementum, eu facilisis justo sollicitudin.
<br><br><br>
Read more
</p>
</div>
<div>
</div>
<div>
</div>
</div>
<div id="crop" style=" display: inline-block; ">
<img src="http://media.caranddriver.com/images/media/51/2017-10best-lead-photo-672628-s-original.jpg" alt="" style=" "/>
</div>
</section>
Any help appreciated
My answer comprises of 2 scenarios so it can help you the way you want. So you can choose the best way you want. I have also included live example so you can easily check it .
1. For all text inside to be on left, which includes both heading and text. Add this css
/* For All Left */
#welcome-content-inner {
text-align: left;
}
.button-yellow,
.button-red {
font: 16px AdobeCaslonPro;
text-decoration: none;
padding: 6px 12px 6px 12px;
border-right: 1px solid #333333;
border-bottom: 1px solid #333333;
border-radius: 4px;
moz-border-radius: 4px;
webkit-border-radius: 4px;
font-style: italic;
}
.button-yellow {
background-color: #ccb96b;
color: #430615;
}
.button-red {
background-color: #430615;
color: #ccb96b;
margin-top: -20px;
}
#section-welcome-content {
text-align: center;
}
#welcome-content {
width: 45%;
margin: 0 0 0 0;
}
#welcome-content-inner {
background-color: #ccb96b;
color: #430615;
padding: 50px;
z-index: 10;
position: relative;
}
#welcome-content p {}
#crop {
width: 600px;
height: 500px;
overflow: hidden;
margin: 0 0 0 -50px;
}
#crop img {
width: 800px;
height: 600px;
margin: -75px 0 0 -100px;
z-index: 1;
}
/* For All Left */
#welcome-content-inner {
text-align: left;
}
<section id="section-welcome-content" class="pad">
<div id="welcome-content" style=" display: inline-block; ">
<div id="welcome-content-inner">
<p>
<h3 style="font-size: 1.5em; text-transform: uppercase;"> <i>Lorem ipsum</i> </h3>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris arcu sapien, dignissim id laoreet quis, sollicitudin sed dui. Mauris mauris ligula, hendrerit sed ligula vitae, viverra auctor eros. Duis rutrum dolor a felis elementum, eu facilisis justo
sollicitudin.
<br><br> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris arcu sapien, dignissim id laoreet quis, sollicitudin sed dui. Mauris mauris ligula, hendrerit sed ligula vitae, viverra auctor eros. Duis rutrum dolor a felis elementum,
eu facilisis justo sollicitudin.
<br><br><br>
Read more
</p>
</div>
<div>
</div>
<div>
</div>
</div>
<div id="crop" style=" display: inline-block; ">
<img src="http://media.caranddriver.com/images/media/51/2017-10best-lead-photo-672628-s-original.jpg" alt="" style=" " />
</div>
</section>
2. For only text to be on left and heading on center. Add this css.
/* For only text Left and heading center */
#welcome-content-inner {
text-align: left;
}
#welcome-content-inner h3 {
text-align: center;
}
.button-yellow,
.button-red {
font: 16px AdobeCaslonPro;
text-decoration: none;
padding: 6px 12px 6px 12px;
border-right: 1px solid #333333;
border-bottom: 1px solid #333333;
border-radius: 4px;
moz-border-radius: 4px;
webkit-border-radius: 4px;
font-style: italic;
}
.button-yellow {
background-color: #ccb96b;
color: #430615;
}
.button-red {
background-color: #430615;
color: #ccb96b;
margin-top: -20px;
}
#section-welcome-content {
text-align: center;
}
#welcome-content {
width: 45%;
margin: 0 0 0 0;
}
#welcome-content-inner {
background-color: #ccb96b;
color: #430615;
padding: 50px;
z-index: 10;
position: relative;
}
#welcome-content p {}
#crop {
width: 600px;
height: 500px;
overflow: hidden;
margin: 0 0 0 -50px;
}
#crop img {
width: 800px;
height: 600px;
margin: -75px 0 0 -100px;
z-index: 1;
}
/* For only text Left and heading center */
#welcome-content-inner {
text-align: left;
}
#welcome-content-inner h3 {
text-align: center;
}
<section id="section-welcome-content" class="pad">
<div id="welcome-content" style=" display: inline-block; ">
<div id="welcome-content-inner">
<p>
<h3 style="font-size: 1.5em; text-transform: uppercase;"> <i>Lorem ipsum</i> </h3>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris arcu sapien, dignissim id laoreet quis, sollicitudin sed dui. Mauris mauris ligula, hendrerit sed ligula vitae, viverra auctor eros. Duis rutrum dolor a felis elementum, eu facilisis justo
sollicitudin.
<br><br> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris arcu sapien, dignissim id laoreet quis, sollicitudin sed dui. Mauris mauris ligula, hendrerit sed ligula vitae, viverra auctor eros. Duis rutrum dolor a felis elementum,
eu facilisis justo sollicitudin.
<br><br><br>
Read more
</p>
</div>
<div>
</div>
<div>
</div>
</div>
<div id="crop" style=" display: inline-block; ">
<img src="http://media.caranddriver.com/images/media/51/2017-10best-lead-photo-672628-s-original.jpg" alt="" style=" " />
</div>
</section>
You just need to add text-align:left; in your welcome-content-inner div and you're there.
.button-yellow, .button-red {
font: 16px AdobeCaslonPro;
text-decoration: none;
padding: 6px 12px 6px 12px;
border-right: 1px solid #333333;
border-bottom: 1px solid #333333;
border-radius: 4px;
moz-border-radius: 4px;
webkit-border-radius: 4px;
font-style: italic;
}
.button-yellow {
background-color: #ccb96b;
color: #430615;
}
.button-red {
background-color: #430615;
color: #ccb96b;
margin-top: -20px;
}
#section-welcome-content {
text-align: center;
}
#welcome-content{
width: 45%;
margin: 0 0 0 0 ;
}
#welcome-content-inner {
background-color: #ccb96b;
color: #430615;
padding: 50px;
z-index: 10;
position: relative;
text-align: left;
}
#welcome-content p{
}
#crop {
width: 600px;
height: 500px;
overflow: hidden;
margin: 0 0 0 -50px ;
}
#crop img {
width: 800px;
height: 600px;
margin: -75px 0 0 -100px;
z-index: 1;
}
<section id="section-welcome-content" class="pad">
<div id="welcome-content" style=" display: inline-block; " >
<div id="welcome-content-inner" >
<p>
<h3 style="font-size: 1.5em; text-transform: uppercase;"> <i>Lorem ipsum</i> </h3>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris arcu sapien, dignissim id laoreet quis, sollicitudin sed dui. Mauris mauris ligula, hendrerit sed ligula vitae, viverra auctor eros. Duis rutrum dolor a felis elementum, eu facilisis justo sollicitudin.
<br><br>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris arcu sapien, dignissim id laoreet quis, sollicitudin sed dui. Mauris mauris ligula, hendrerit sed ligula vitae, viverra auctor eros. Duis rutrum dolor a felis elementum, eu facilisis justo sollicitudin.
<br><br><br>
Read more
</p>
</div>
<div>
</div>
<div>
</div>
</div>
<div id="crop" style=" display: inline-block; ">
<img src="http://media.caranddriver.com/images/media/51/2017-10best-lead-photo-672628-s-original.jpg" alt="" style=" "/>
</div>
</section>
Hope it helps.
Whenever I rescale/resize my window to smaller size (smartphone sized) all of the three inner div's (.left .center .right) red,green,blue respectively, below each other doesn't align to the center. Please see the attached screenshot to understand. I want all of these three div's to be in the center of the main .container div (pink) whenever the window is scaled down. Would appreciate your inputs.
html,body {
width: 100%;
left: 0px;
top: 0px;
margin: 0px;
height: 100%;
}
.container {
width: auto;
left: 0px;
top: 0px;
float: none;
width: auto;
max-width: auto;
position: relative;
background-color: rgba(216, 86, 112, 0.5);
height: 100%;
margin-top: auto;
margin-right: 5%;
margin-left: 5%;
display: block;
right: 0px;
}
.top {
width: 100%;
left: 0px;
top: 0px;
background-color: rgba(204, 51, 0, 1);
height: 10%;
position: relative;
margin: 0px;
text-align: center;
}
.left {
float: left;
height: auto;
width: 331px;
background-color: rgba(255, 0, 0, 1);
margin-left: auto;
margin-right: auto;
position: relative;
left: auto;
top: 0px;
}
.center {
float: left;
height: auto;
width: 331px;
background-color: rgba(0, 255, 0, 1);
margin-left: 0px;
margin-right: auto;
position: relative;
left: 0px;
}
.right {
float: left;
height: auto;
width: 331px;
background-color: rgba(0, 0, 255, 1);
margin-left: 0px;
margin-right: auto;
position: relative;
left: 0px;
top: 0px;
}
<div class="container">
<div class="top"></div>
<div class="left">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
<div class="center">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
<div class="right">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
</div>
My method is to have separate code for css that overwrites the code when the conditions are met. For this you would decide what you want to max width to be before it changes and add the code:
#media only screen and (max-width: 1187px)
{
new css here
}
For your particular project you would just have to change the floats and margins (and the width that you want (the 1187 here)) so:
#media only screen and (max-width: 1187px)
{
.left {
margin-right:auto;
margin-left:auto;
float:none;
}
.center {
margin-right:auto;
margin-left:auto;
float:none;
}
.right {
margin-right:auto;
margin-left:auto;
float:none;
}
}
UPD. Three blocks int the center of the parent
I have seen the cooment about three blocks< which are centered like - - -. This is my solution.
html, body {
margin: 0px;
height: 100%;
}
.container {
background-color: rgba(216, 86, 112, 0.5);
height: 100%;
margin: 0 5%;
text-align: center;
}
.top {
width: 100%;
background-color: rgba(204, 51, 0, 1);
height: 10%;
}
.left,
.center,
.right {
display: inline-block;
width: 331px;
}
.left { background-color: rgba(255, 0, 0, 1); }
.center { background-color: rgba(0, 255, 0, 1); }
.right { background-color: rgba(0, 0, 255, 1); }
<div class="container">
<div class="top"></div>
<div class="left">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
<div class="center">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
<div class="right">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
</div>
Media query
I prefer the mobile first design. The first step is to adjust the webpage for a smartphone. Then determine the changes that occur when the screen becomes wider. Then describe the changes for an even wider screen. And so on.
Let's calculate the width of the screen, in which the three blocks will fit in the same row. Three 331px wide blocks occupied by 993px. This is 90% of the screen width. 10% falls on the margins of the container. Therefore
993px x 100% / 90% = 1104px
So I've added a media query for this breakpoint.
Also I've commented out the parts that are not needed to solve described problem. Please check the result.
html, body {
margin: 0px;
height: 100%;
/*
width: 100%;
left: 0px;
top: 0px;
*/
}
.container {
background-color: rgba(216, 86, 112, 0.5);
height: 100%;
margin-right: 5%;
margin-left: 5%;
/*
margin-top: auto;
display: block;
right: 0px;
width: auto;
left: 0px;
top: 0px;
float: none;
width: auto;
max-width: auto;
position: relative;
*/
}
.top {
width: 100%;
background-color: rgba(204, 51, 0, 1);
height: 10%;
text-align: center;
/*
left: 0px;
top: 0px;
position: relative;
margin: 0px;
*/
}
.left,
.center,
.right {
width: 331px;
margin-left: auto;
margin-right: auto;
}
#media (min-width: 1104px) {
.left,
.center,
.right {
float: left;
height: auto;
width: 331px;
/*
position: relative;
left: auto;
top: 0px;
*/
}
}
.left { background-color: rgba(255, 0, 0, 1); }
.center { background-color: rgba(0, 255, 0, 1); }
.right { background-color: rgba(0, 0, 255, 1); }
<div class="container">
<div class="top"></div>
<div class="left">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
<div class="center">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
<div class="right">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
</div>
Is this what you want ? https://jsfiddle.net/xofoh5yp/
Just removed floats and left position styles.
<div class="container">
<div class="top"></div>
<div class="left">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
<div class="center">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
<div class="right">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
</div>
html,body {
width: 100%;
left: 0px;
top: 0px;
margin: 0px;
height: 100%;
}
.container {
width: auto;
left: 0px;
top: 0px;
float: none;
width: auto;
max-width: auto;
position: relative;
background-color: rgba(216, 86, 112, 0.5);
height: 100%;
margin-top: auto;
margin-right: 5%;
margin-left: 5%;
display: block;
right: 0px;
}
.top {
width: 100%;
left: 0px;
top: 0px;
background-color: rgba(204, 51, 0, 1);
height: 10%;
position: relative;
margin: 0px;
text-align: center;
}
.left {
height: auto;
width: 331px;
background-color: rgba(255, 0, 0, 1);
margin-left: auto;
margin-right: auto;
position: relative;
}
.center {
width: 331px;
background-color: rgba(0, 255, 0, 1);
margin-left: auto;
margin-right: auto;
position: relative;
}
.right {
height: auto;
width: 331px;
background-color: rgba(0, 0, 255, 1);
margin-left: auto;
margin-right: auto;
position: relative;
}
Here is the code if you want them to be in one line :
Fiddle: https://jsfiddle.net/xofoh5yp/1/
Basically, added container DIV and then added % widths.
<div class="container">
<div class="top"></div>
<div>
<div class="left">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
<div class="center">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
<div class="right">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vehicula quis dolor sed euismod. Fusce id tellus est. Nam eu rutrum urna. Donec mattis a libero faucibus euismod. Suspendisse iaculis placerat sapien in ultrices.
</div>
</div>
</div>
html,body {
width: 100%;
left: 0px;
top: 0px;
margin: 0px;
height: 100%;
}
.container {
width: auto;
left: 0px;
top: 0px;
float: none;
width: auto;
max-width: auto;
position: relative;
background-color: rgba(216, 86, 112, 0.5);
height: 100%;
margin-top: auto;
margin-right: 5%;
margin-left: 5%;
display: block;
right: 0px;
}
.top {
width: 100%;
left: 0px;
top: 0px;
background-color: rgba(204, 51, 0, 1);
height: 10%;
position: relative;
margin: 0px;
text-align: center;
}
.left {
height: auto;
width: 33%;
background-color: rgba(255, 0, 0, 1);
margin-left: auto;
margin-right: auto;
position: relative;
float:left;
}
.center {
width: 33%;
background-color: rgba(0, 255, 0, 1);
margin-left: auto;
margin-right: auto;
position: relative;
float:left;
}
.right {
height: auto;
width: 34%;
background-color: rgba(0, 0, 255, 1);
margin-left: auto;
margin-right: auto;
position: relative;
float:left;
}
Another fiddle with margin : https://jsfiddle.net/xofoh5yp/2/
I'm showing more text on :hover, so the container <div> is changing height automatically but the background-color doesn't expand. Is there any solution please?
Here is the jsFiddle that shows the problem.
#related {
width: 100%;
left: 0;
min-height: 360px;
height: auto;
background-color: #3f5673;
color: white;
}
#related .inner {
width: 63%;
margin: auto;
color: white;
}
#related .inner .abox .thumb {
text-decoration: none;
}
#related .inner .abox .thumb .sgn {
display: block;
padding-left: 15px;
color: #36C7E3;
}
#related .inner a {
color: white;
}
#related .inner h3 {
font-size: 25px;
color: white;
}
#related .inner h4 {
color: white;
}
#related .inner .col {
float: left;
width: 30%;
margin-right: 30px;
}
#related .inner .col strong {
padding-left: 15px;
color: #36C7E3;
}
#related .inner .col p {
white-space: nowrap;
overflow: hidden;
text-overflow: clip;
}
#related .inner .col p::after {
display: block;
float: right;
padding-top: 15px;
content: "..see more..";
color: #36C7E3;
}
#related .inner .col p:hover {
overflow: visible;
width: auto;
white-space: normal;
padding: 0;
}
#related .inner .col p:hover:after {
display: none;
}
#related #references {
float: left;
width: 30%;
margin-right: 30px;
}
#related #didyouknow {
float: left;
width: 30%;
margin-right: 30px;
}
/*------------------------------------------------------*/
#footer {
float: left;
left: 0;
height: 30px;
width: 100%;
background-color: #5f5f5f;
color: white;
padding-bottom: 20px;
}
#footer hr {
display: none;
}
#footer .inner .copy {
padding-left: 15px;
}
#footer .inner .menu li {
float: right;
display: inline;
padding-right: 15px;
}
#footer .inner .menu li a {
color: white;
}
<section id="related">
<div class="inner">
<section class="col" id="news">
<h3>News</h3>
<h4>Some title</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam rhoncus, lacus sed tincidunt mollis, tellus erat mollis sapien, at ullamcorper augue nisi a justo. Praesent et tellus at lorem rhoncus venenatis non id velit. Nullam vestibulum arcu
quis erat fermentum, sed venenatis arcu tristique. Quisque fermentum nisi sed porta fermentum. Nam tincidunt, ipsum et blandit sodales, turpis enim ultricies erat, a viverra tellus elit vitae enim. Etiam placerat enim orci, nec pulvinar lorem
vehicula ac. Etiam eget elementum sem. Integer nisi elit, bibendum vitae leo non, posuere tincidunt neque.
</p>
<strong>10 Dec 2014</strong>
<h4>Some title</h4>
<p>Vestibulum luctus nibh non risus semper consectetur. Sed laoreet eget metus in elementum. Ut mollis faucibus risus a faucibus. Vestibulum eget maximus purus. Maecenas vitae ipsum mattis augue feugiat rutrum. Sed tortor eros, convallis vitae libero
vitae, commodo lobortis lacus. Duis condimentum consectetur augue, vel pharetra orci aliquam sit amet.</p>
<strong>5 Jan 2015</strong>
</section>
<aside>
<div id="references" class="abox">
<h3>References</h3>
<a class="thumb d2" href="#">
<q>FitLayout is very useful for obtaining structured data from the web. We use it every dat
for obtaining statistical data about the products offered by our competitors.</q>
<span class="sgn">John Smith</span>
</a>
</div>
<div id="didyouknow" class="abox">
<h3>Did you know?</h3>
<a class="thumb d2" href="#">
<q>The FitLayout pattern matching algorithms save time and money in the specification phase.
The designers may focus on the main problem instead of manually designing complex extraction
templates.</q>
</a>
</div>
</aside>
</div>
</section>
<footer id="footer">
<div class="inner">
<hr>
<ul class="menu">
<li>Home</li>
<li>News</li>
<li>Contact</li>
</ul>
<div class="copy">Copyright © 2016 FITLayout. All rights reserved.</div>
</div>
</footer>
The issue is not background color, but element size. You need to force the parent to stretch to the height of the child:
#related {
...
overflow: hidden;
}
Demo
There's a problem in my code attached below:
The img with id listItemProfile stays always in middle no matter what padding I set, I though it might due to there's some padding in its parent, but I couldn't find any, any thoughts?
Thanks in advance!
<!DOCTYPE html>
<html>
<head>
</head>
<style type="text/css">
.accordionOm {
position: relative;
padding: 10px 0 10px 30px;
margin: 0;
font: 300 18px 'Oswald', Arial, Helvetica, sans-serif;
cursor: pointer;
}
.accordionOm:hover {
color: #000;
}
.accordionOm:before,
.accordionOm:after {
content: "";
position: absolute;
background: #333;
display: inline-block;
}
.accordionOm:before {
width: 20px;
height: 2px;
left: 0;
top: 22px;
}
.accordionOm:after {
width: 2px;
height: 20px;
left: 9px;
top: 13px;
transition: transform .5s;
transform: rotate(0);
}
.accordionOm.opened:after {
transform: rotate(90deg);
}
.accordionOm + div {
border-left: 4px solid #999;
padding: 0 15px;
margin-left: 8px;
font: 13px 'Open Sans', Arial, Helvetica, sans-serif;
color: #666;
}
* {
font-family: Arial, Verdana, sans-serif;
color: #665544;
text-align: center;}
body {
width: 100%;
margin: 0 auto;
}
#trailBar{
margin-left: 35px;
margin-right: 35px;
margin-top: 25px;
margin-bottom: 25px;
height: 180px;
background: -webkit-linear-gradient(right, #31a7de, #31a7de 35px, white 35px, white);
border: transparent;
border-radius:0.25em;
}
p.trailTextTop{
padding-top: 25px;
padding-left: 25px;
padding-right: 60px;
padding-bottom: 25px;
font-size: large;
}
p.trailTextBot{
padding-left: 25px;
padding-right: 60px;
padding-bottom: 25px;
font-size: large;
}
.left { float: left; }
.right { float: right; }
p { overflow: hidden; }
.panel-group .list-group {
margin-bottom: 0;
}
.panel-group .list-group .list-group-item {
border-radius: 0;
border-left: none;
border-right: none;
}
.panel-group .list-group .list-group-item:last-child {
border-bottom: none;
}
.panel-body{
background: #efefef;
}
#listItem{
position: relative;
height: 200px;
background: #efefef;
}
#listItemProfile{
position: absolute;
height: 80px;
width: 80px;
padding-top: 60px;
padding-bottom: 60px;
padding-left: 35px;
}
#listItemTitle{
}
#listItemSubtitle{
}
#listItemInfo{
}
#listItemArrow{
}
</style>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h4 class="accordionOm opened">
<div id="listItem">
<img id = "listItemProfile" src="images/Portrait.png">
<div id="listItemTitle">
</div>
<div id="listItemSubtitle">
</div>
<div id="listItemInfo">
</div>
<div id="listItemArrow">
</div>
</div>
</h4>
<div>
<div id="trailBar">
<p class="trailTextTop"><span class='left'>Good morning, I just start my first day trip. Happy pedal!</span></p>
<p class="trailTextBot"><span class='left'>Time 7:20</span><span class='right'>45 Miles</span></p>
</div>
<div id="trailBar">
<p class="trailTextTop"><span class='left'>Good morning, I just start my first day trip. Happy pedal!</span></p>
<p class="trailTextBot"><span class='left'>Time 7:20</span><span class='right'>45 Miles</span></p>
</div>
<div id="trailBar">
<p class="trailTextTop"><span class='left'>Good morning, I just start my first day trip. Happy pedal!</span></p>
<p class="trailTextBot"><span class='left'>Time 7:20</span><span class='right'>45 Miles</span></p>
</div>
</div>
<h4 class="accordionOm">Accordian heading</h4>
<div>
<p>Lorem ipsum dolor sit amet, adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui. Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis, massa
quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus.</p>
</div>
<h4 class="accordionOm">Accordian heading</h4>
<div>
<p>Lorem ipsum dolor sit amet, adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui. Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis, massa
quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus.</p>
</div>
<h4 class="accordionOm">Accordian heading</h4>
<div>
<p>Lorem ipsum dolor sit amet, adipiscing elit. Nullam dignissim convallis est. Quisque aliquam. Donec faucibus. Nunc iaculis suscipit dui. Nam sit amet sem. Aliquam libero nisi, imperdiet at, tincidunt nec, gravida vehicula, nisl. Praesent mattis, massa
quis luctus fermentum, turpis mi volutpat justo, eu volutpat enim diam eget metus.</p>
</div>
</body>
<script>
$('.accordionOm').next().hide();
$(".opened").next().show();
$('.accordionOm').click(function() {
if ($(this).hasClass("opened") == true) {
$(this).next().slideUp("slow");
$(this).removeClass('opened');
} else {
$(".opened").next().slideUp("slow");
$(".opened").removeClass("opened");
$(this).addClass('opened');
$(this).next().slideDown("slow");
}
});
</script>
</html>
Hi now define this css
#listItemProfile {
position: absolute;
height: 80px;
width: 80px;
/* padding-top: 60px; */
/* padding-bottom: 60px; */
/* padding-left: 35px; */
left: 50%;
top: 50%;
margin-left: -40px; // your total width img / 2
margin-top: -40px; // your total height img /2
}
You can use this css given below :
#listItemProfile {
position: absolute;
height: 80px;
width: 80px;
left: 50%;
top: 50%;
margin-left: -40px;
margin-top: -40px;
}
try with margin-left , margin-right
Example
.class-name{
margin-left:10px;
margin-right:50px;
}
How come my red border is not wrapping around my text div and my side bar div. Here's my code:
CSS:
body{
background-color: #d7d7d7;
color: #666666;
font-family: arial, sans-serif;
font-size: x-small;
}
div#header {
background-color: #323232;
height: 140px;
width: 950px;
}
div#maincontainer {
background-color: #d7d7d7;
width: 950px;
height: auto;
margin-top: 5px;
border: 1px solid red;
}
div#maintextcontainer{
//background-color: #333333;
width: 640px;
//margin-right: 10px;
margin: 1px;
float: left;
color: black;
}
div#maintextcontainer h2{
color: #4f4f4f;
}
div#sidebarcontainer {
//background-color: #333333;
width: 300px;
float: left;
color: black;
margin: 1px;
}
div#footer{
background-color: #323232;
width: 950px;
margin-top: 5px;
clear: left;
}
div#global{
width: 950px;
margin: auto;
}
HTML:
<div id="global">
<div id="header"> This is the header div</div>
<div id="maincontainer">
<div id="maintextcontainer">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi aliquam neque eu turpis euismod eget suscipit nulla ultrices. Donec sagittis mi non sem vestibulum elementum dapibus risus auctor. Praesent tristique laoreet dapibus. Integer vel ligula lorem, et pharetra lorem.
</div>
<div id="sidebarcontainer">Nam at lectus vitae est tempor lacinia sed et ante. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Praesent interdum mi id nisi aliquet pulvinar.
</div>
</div>
<div id="footer">This is Footer Text</div>
</div>
You need to add overflow:auto; to div#maincontainer. Floated elements will flow outside of their containing element, unless this attribute is set.
Also, a double slash (//) is not a valid commenting symbol in CSS.