I have 2 div's, one 50% width, the other 25%.
They're suppose to both sit centred horizontally on the one line.
I can get this working fine. But when I insert a paragraph they break.
Any idea why?
http://jsfiddle.net/3KuJa/
html:
<section>
<div class="twothird"> </div>
<div class="onethird"><p>test</p></div>
</section>
css:
.onethird {
width: 25%;
background: white;
min-height: 20em;
display: inline-block;
margin: 20em 3%;
-webkit-box-shadow: 2px 2px 6px 0px rgba(50, 50, 50, 0.75);
-moz-box-shadow: 2px 2px 6px 0px rgba(50, 50, 50, 0.75);
box-shadow: 2px 2px 6px 0px rgba(50, 50, 50, 0.75);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
padding: 2em;
text-align:left;
}
.twothird {
width: 50%;
background: white;
min-height: 20em;
display: inline-block;
margin: 20em 3%;
-webkit-box-shadow: 2px 2px 6px 0px rgba(50, 50, 50, 0.75);
-moz-box-shadow: 2px 2px 6px 0px rgba(50, 50, 50, 0.75);
box-shadow: 2px 2px 6px 0px rgba(50, 50, 50, 0.75);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
padding: 2em;
text-align:left;
}
Inline block elements align, by default to baseline
This should fix it if applied to both inline-block divs
CSS
display: inline-block;
vertical-align: top;
Adjusted JSfiddle Demo
You may have to widen the display window to check.
since you have box-shadow, i am proposing a solution supported by IE8+ :
use display :table /table-cell for section and div
section {
display:table; /* make parent table type */
width:60%; /* give width */
margin :0 auto; /* center your section */
border:1px solid green /* just for display */
}
.onethird {
width: 25%;
background: white;
min-height: 20em;
display:table-cell;
/* display: inline-block; changed this value */
margin: 20em 3%;
-webkit-box-shadow: 2px 2px 6px 0px rgba(50, 50, 50, 0.75);
-moz-box-shadow: 2px 2px 6px 0px rgba(50, 50, 50, 0.75);
box-shadow: 2px 2px 6px 0px rgba(50, 50, 50, 0.75);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
padding: 2em;
text-align:left;
border:1px solid red;
}
.twothird {
width: 50%;
border:1px solid red;
background: white;
min-height: 20em;
display:table-cell;
/* display: inline-block; changed this value */
margin: 20em 3%;
-webkit-box-shadow: 2px 2px 6px 0px rgba(50, 50, 50, 0.75);
-moz-box-shadow: 2px 2px 6px 0px rgba(50, 50, 50, 0.75);
box-shadow: 2px 2px 6px 0px rgba(50, 50, 50, 0.75);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
padding: 2em;
text-align:left;
}
Keep in mind : your fiddle doesn't have set width and height to html, body...always declare that, it avoids many messy problems later in DOM - rule of thumb :)
Working fiddle
The source of the problem is indeed the interaction of the baseline alignment between the p and the empty inline box to the left of it.
In addition to using vertical-align: top to fix the problem, you can also use overflow:auto applied to .onethird and .twothird, which triggers a new block formatting context which prevents the text lines from the two inline-block containers from interacting with each other.
See demo at: http://jsfiddle.net/audetwebdesign/6vnh3/
Related
I am able to display the image and text in the same line in desktop but In a mobile device, it is not displayed in the same line.It is displaying image and below text. I have to display both in the same line. Would you help me in this?
Below image:-I am getting output like this in mobile device.
Output: I have to display both i the same line.like displaying in desktop
.amazon-section{
text-align:center;
background-color: #fff;
display: table;
margin: 0px auto 0px auto;
padding: 0px 38px 5px;
border-radius: 04px;
webkit-box-shadow: 1px 1px 22px 0px rgba(50, 50, 50, 0.25);
-moz-box-shadow: 1px 1px 22px 0px rgba(50, 50, 50, 0.25);
box-shadow: 1px 1px 22px 0px rgba(50, 50, 50, 0.25);
position: relative;
top: 20px;
font-family:"Arcon-Regular";
box-sizing: border-box;
}
.amazon-section img{
width:100px;
padding:10px;
position: relative;
right: 20px;
}
.amazon-content{
display:inline-block;
}
.amazon-content h2{
font-size:18px;
color:#53585F !important;
font-weight: 600;
position: relative;
top: 15px;
}
<div class="amazon-section">
<div class="amazon">
<img src="images/amazon.png">
<div class="amazon-content">
<h2 class="amazon-text">Lorem ipsum dolor tetur<br /> adipiscing elit.</h2>
</div>
</div>
</div>
you can do this with flexbox and leave your html a little cleaner and leaner.
Basically, you can easily control both vertical and horizontal centering with justify-content (horizontal or main axis) and align-items (vertical or cross axis), which you can set on the container/parent directly.
.amazon-section
{
text-align:center;
background-color: #fff;
display: table;
margin: 0px auto 0px auto;
padding: 0px 38px 5px;
border-radius: 04px;
webkit-box-shadow: 1px 1px 22px 0px rgba(50, 50, 50, 0.25);
-moz-box-shadow: 1px 1px 22px 0px rgba(50, 50, 50, 0.25);
box-shadow: 1px 1px 22px 0px rgba(50, 50, 50, 0.25);
position: relative;
top: 20px;
font-family:"Arcon-Regular";
box-sizing: border-box;
}
.amazon { /*set children to be centered vertically and horizontally*/
display: flex;
justify-content:center;
align-items:center;
}
.amazon-section img /*children need no positional css*/
{
width:100px;
padding:10px;
}
.amazon-content h2
{
font-size:18px;
color:#53585F !important;
font-weight: 600;
}
codepen example
This piece of CSS will hide all <br> elements that are directly nested in a <h2> element at browser widths below 768px... In this case, achieving your goal as I understand it.
#media (max-width: 767px) {
h2 > br { display: none; }
}
Update
I originally thought it was the text itself you wanted on 1 line.
In order to keep the image along side the text, I would suggest using CSS3's flex. For example:
.amazon {
display: flex;
align-items: center; /* <- Helps with vertical alignment */
}
You can also specify how much of the horizontal proportions you want each of the children to occupy by default, and whether you wish to allow them to shrink or grow, etc.
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
.amazon-section
{
text-align:center;
background-color: #fff;
display: table;
margin: 0px auto 0px auto;
padding: 0px 38px 5px;
border-radius: 04px;
webkit-box-shadow: 1px 1px 22px 0px rgba(50, 50, 50, 0.25);
-moz-box-shadow: 1px 1px 22px 0px rgba(50, 50, 50, 0.25);
box-shadow: 1px 1px 22px 0px rgba(50, 50, 50, 0.25);
position: relative;
top: 20px;
font-family:"Arcon-Regular";
box-sizing: border-box;
}
.amazon-section > img
{
width:100px;
padding:10px;
position: relative;
right: 20px;
}
.amazon{
vertical-align:top;
display:inline-block;
}
.amazon-content
{
display:inline-block;
}
.amazon-content > h2
{
vertical-align:top;
font-size:18px;
color:#53585F !important;
font-weight: 600;
position: relative;
}
<div class="amazon-section">
<div class="amazon">
<img src="images/amazon.png">
<div class="amazon-content">
<h2 class="amazon-text">Lorem ipsum dolor tetur adipiscing elit.</h2>
</div>
</div>
</div>
I have a div that containing a inner box shadow, but these shadow is coverd by another div, i tried with postion:relative but nothing is changed.
Here is a example
CODE EXAMPLE
example-div{
background:#fff;
color:#000;
margin-top: 10px;
margin-bottom: 20px;
margin-left: 15px;
width:260px;
height:250px;
border-radius: 100%;
border:6px solid red;
position: relative;
-webkit-box-shadow: inset 7px 7px 5px -5px rgba(50, 50, 50, 0.75);
-moz-box-shadow: inset 7px 7px 5px -5px rgba(50, 50, 50, 0.75);
box-shadow: inset 7px 7px 5px -5px rgba(50, 50, 50, 0.75);
}
Thanks in advance !
2 things you need to do - change the z-index of your picture so that it is behind your circular div, and then change the background of your circular div so that it is transparent instead of white.
.example-div{
background: transparent; /*this way you can see behind the circle*/
color:#000;
margin-top: 10px;
margin-bottom: 20px;
margin-left: 15px;
width:260px;
height:250px;
border-radius: 100%;
border:6px solid red;
position: relative;
-webkit-box-shadow: inset 7px 7px 5px -5px rgba(50, 50, 50, 0.75);
-moz-box-shadow: inset 7px 7px 5px -5px rgba(50, 50, 50, 0.75);
box-shadow: inset 7px 7px 5px -5px rgba(50, 50, 50, 0.75);
}
.example-div img{
width:260px;
height:250px;
border-radius: 100%;
position: relative; /*needed for z-index*/
z-index: -1; /*positions behind the circular div, but you can still see because of transparent background*/
}
<div class="example-div">
<img src="http://cdn.wonderfulengineering.com/wp-content/uploads/2014/09/new-wallpaper-18.jpg"/>
</div>
how to get a good shadow (AT THE border-right OF THE SMALL DIV) that is equal to the shadow of the large div but that does cut of as it reaches the border-bottom of the small div / the border-top of the large div.
NOTE: I CANNOT use Z-index, I have a website way more complicated. Also, Spread CANNOT be used here because that doesnt cut off when it reaches the border-bottom/border-top, it won't look 3d anymore.
the html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="small"></div>
<div id="large"></div>
</body>
</html>
And here, the CSS:
#small {
border: 1px solid black;
width: 200px;
height: 50px;
}
#large {
width: 300px;
border: 1px solid black;
height: 100px;
-webkit-box-shadow: 7px 7px 5px 0px rgba(50, 50, 50, 0.75);
-moz-box-shadow: 7px 7px 5px 0px rgba(50, 50, 50, 0.75);
box-shadow: 7px 7px 5px 0px rgba(50, 50, 50, 0.75);
}
I also have a JS Bin: http://jsbin.com/vijujaweja/edit
-I know, the question is formatted a bit bad, but I hope you understand my question.-
Why not just add background color to the divs?
JS Bin Here
#small {
border: 1px solid black;
width: 200px;
height: 50px;
background-color:#fff;
}
#large {
width: 300px;
border: 1px solid black;
height: 100px;
background-color:#fff;
}
.dropshadow {
-webkit-box-shadow: 7px 7px 5px 0px rgba(50, 50, 50, 0.75);
-moz-box-shadow: 7px 7px 5px 0px rgba(50, 50, 50, 0.75);
box-shadow: 7px 7px 5px 0px rgba(50, 50, 50, 0.75);
}
Do you want it like this? http://jsbin.com/xohomaraqe/1/edit I have updated some code.
Updated
This should work then
#small{
-webkit-box-shadow: 9px 1px 3px -1px rgba(50, 50, 50, 0.75);
}
This is what I want:
And this is what I have (I want the bottom left box scooted up):
Here is my CSS so far.
.grid {
padding:0px;
margin:10px auto;
width:100%;
background-size: 100%;
}
.grid li {
display: block;
width: 361px;
float: left;
background: #fff;
margin:6px 19px 6px 0px;
margin-top: 12px;
padding: 10px;
font-family: 'Roboto', sans-serif;
-webkit-box-shadow: 0px 2px 1px rgba(50, 50, 50, 0.4);
-moz-box-shadow: 0px 2px 1px rgba(50, 50, 50, 0.4);
box-shadow: 0px 2px 1px rgba(50, 50, 50, 0.4);
opacity: 0;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}
The best way I can explain this is with a JSFiddle example: http://jsfiddle.net/8tXku/
I'm floating each .project div to the left and using some simple jQuery to make them expand to show a description when clicked, however if you click the first project it will push the third project to the right, because it's taking up too much space when expanded.
Is there a way to get the third project div to just gracefully move down the page with the expanded content rather than move over to the right?
This may be a dirty solution but its works perfectly.
Giving the .project-description a position:absolute; will allow it to .slideDown() without affecting the surrounding divs, yet some other tweaks had to be made.
I added position:relative; to .project so that each .project-description is contained within it.
Final CSS
.project {
width: 250px;
float: left;
border: 1px solid #dedede;
border-radius: 6px;
-webkit-box-shadow: 0px 0px 20px rgba(50, 50, 50, 0.4);
-moz-box-shadow: 0px 0px 20px rgba(50, 50, 50, 0.4);
box-shadow: 0px 0px 20px rgba(50, 50, 50, 0.4);
margin-right: 30px;
margin-bottom: 30px;
position:relative;
}
.project-description {
padding: 5px;
font-size: 12px;
display: none;
position:absolute;
background-color:white;
left:0;
right:0;
z-index:99;
}
Check this out : http://jsfiddle.net/AliBassam/N4U3R/
UPDATE
When .project-description contains a big text (obviously) it will be hidden under the bottom div, just add z-index:99; to .project-description
Check this out: http://jsfiddle.net/AliBassam/pMGDZ/
Replace .project-description current style with this
.project-description {
padding: 5px;
font-size: 12px;
display: none;
position: absolute;
-webkit-box-shadow: 0px 0px 20px rgba(50, 50, 50, 0.4);
-moz-box-shadow: 0px 0px 20px rgba(50, 50, 50, 0.4);
box-shadow: 0px 0px 20px rgba(50, 50, 50, 0.4);
width:325px;
border-radius: 0 0 6px 6px;
background: #FFFFFF;
z-index: 1;
}
DEMO: http://jsfiddle.net/enve/8tXku/4/