I want to make the "more information" element to appear inside the div. Am I missing something?
http://jsfiddle.net/MMKdz/
HTML
<div class="aside-visitus">
<h2> H2 </h2>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat</p>
<p class="aside-caption"> More information
</p>
</div>
<div class="aside-visitus">
<h2> H2 </h2>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
<p class="aside-caption"> More information
</p>
</div>
CSS
.aside-visitus {
border:1px solid black;
margin:20px 0;
}
.aside-visitus a {
color:#4682b4;
float:right;
}
The clear and display methods don't work at all.
The most appropriate is use text-align: right propiety
http://jsfiddle.net/FelipeMartinin/MMKdz/3/
.aside-visitus a {
color:#4682b4;
text-align: right;
display: block;
}
Or you can give a display: table for the div.
You could add overflow:hidden to the parent element. This will establish a new block formatting context, thus forcing the element to contain the floated elements.
The reason this is required is because the parent element doesn't have a defined height and the child element is being floated. According to the nature of floating elements, they are essentially removed from the flow of the document; you need to reestablish the block formatting context.
jsFiddle example
.aside-visitus {
border: 1px solid black;
margin: 20px 0;
overflow: hidden;
}
Alternatively, you could use a clearfix which does the same thing. This method has more support.
I wouldn't use float. I'd add text-align:right to the .aside-caption class.
.aside-caption
{
text-align:right;
}
Fiddle: http://jsfiddle.net/MMKdz/2/
Related
When used with margin and background-image, normal <div> and <body> behaves quite differently.
Normal <div> works as expected (margin is not part of the content, thus no background image appears in the margin):
div {
background: url("http://www.w3schools.com/cssref/img_flwr.gif");
background-size: auto;
background-position: top left;
background-repeat: no-repeat;
padding-top: 40px;
border:1px solid black;
margin:60px;
}
<div>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
<p>Original image: <img src="http://www.w3schools.com/cssref/img_flwr.gif" alt="Flowers" width="224" height="162" /></p>
<p><strong>Note:</strong> The background-size property is not supported in Internet Explorer 8 and earlier versions.</p>
</div>
However, margin seems to be part of the content when it comes to <body> and the background image appears in the margin, which is unexpected:
body {
background: url("http://www.w3schools.com/cssref/img_flwr.gif");
background-size: auto;
background-position: top left;
background-repeat: no-repeat;
padding-top: 40px;
border:1px solid black;
margin:60px;
}
<body>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
<p>Original image: <img src="http://www.w3schools.com/cssref/img_flwr.gif" alt="Flowers" width="224" height="162" /></p>
<p><strong>Note:</strong> The background-size property is not supported in Internet Explorer 8 and earlier versions.</p>
</body>
If you don't set a background on the <html> element, the background of the body element is propagated to the canvas. If you don't want that, just set a background to the html element.
i.e. html { background-color: white; }
Formally, the CSS spec says
... For documents whose root element is an HTML "HTML" element or an XHTML "html" element that has computed values of 'transparent' for 'background-color' and 'none' for 'background-image', user agents must instead use the computed value of the background properties from that element's first HTML "BODY" element or XHTML "body" element child when painting backgrounds for the canvas, and must not paint a background for that child element. Such backgrounds must also be anchored at the same point as they would be if they were painted only for the root element.
html {
background-color: white;
}
body {
background: url("http://www.w3schools.com/cssref/img_flwr.gif");
background-size: auto;
background-position: top left;
background-repeat: no-repeat;
padding-top: 40px;
border:1px solid black;
margin:60px;
}
<body>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
<p>Original image: <img src="http://www.w3schools.com/cssref/img_flwr.gif" alt="Flowers" width="224" height="162" /></p>
<p><strong>Note:</strong> The background-size property is not supported in Internet Explorer 8 and earlier versions.</p>
</body>
I don't know the real reason behind this error but got a tricky solution.
give this to your css
background-position: top 70px left 70px;//change the value as you want
css
body {
background: url("http://www.w3schools.com/cssref/img_flwr.gif");
background-size: auto;
background-position: top 70px left 70px;
background-repeat: no-repeat;
padding-top: 40px;
border:1px solid black;
margin:60px;
}
I need some help...
I am trying to style a blockquote elemet:
<div class="container-fluid testimonials padding">
<div class="row-fluid">
<div class="col-xs-12 col-sm-12 col-md-5 col-md-offset-2 col-lg-5 col-lg-offset-2">
<blockquote>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vul. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vul.
</blockquote>
</div>
<div class="col-xs-12 col-sm-12 col-md-3 col-lg-3">
</div>
</div>
</div>
Styling I have so far:
.padding {padding-top:2%;padding-bottom:2%;}
blockquote {padding:60px 30px 40px 95px;border:none;position:relative;font-family: 'Comfortaa', cursive;}
blockquote::before{
content: "\201C";
font-family: 'Comfortaa', cursive;
font-size: 180px;
font-weight: bold;
color: #999;
position: absolute;
left:20px;
top:-40px;
color:#b80072;
z-index: -1;
}
blockquote::after{
content: "\201D";
font-family: 'Comfortaa', cursive;
font-size: 180px;
font-weight: bold;
color: #999;
position: absolute;
right:5%;
bottom:-45%;
color:#b80072;
z-index: -1;
opacity:0.5;
width:90px;
}
#media (max-width: 510px) {
blockquote::after {bottom:-25%;}
}
The result is almost what I want to achieve.
The before pseudo element is styled correctly and the blockquote padding itself is fine.
The problem is styling the after pseudo element as. How do I get it to stick to the bottom right hand corner of the blockquote element?
Any help would be appreciated.
The reason the placement seems difficult is because of the huge default line height on the quote marks. You can get a bit more control of it by setting
blockquote::after {line-height: 0;}
... though it's not an ideal solution.
I have a 3 div inside a div named is left-content, middle-content, right-content. What i want is that middle-content must come on top and left-content, right-content below middle-content in responsive design. Here is my code:
<div id="content">
<div id="left-content">
<p>
<b>
Lorem ipsum dolor sit amet,
consectetuer adipiscing elit, sed
diam nonummy nibh euismod
tincidunt ut laoreet dolore magna
aliquam erat volutpat. Ut wisi enim
ad minim veniam, quis nostrud
exerci tation ullamcorper suscipit
lobortis nisl ut aliquip ex ea
commodo consequat.
</b>
</p>
</div>
<div id="middle-content">
<img src="img/img1.jpg" />
</div>
<div id="right-content">
<p>
Lorem ipsum dolor sit amet,
consectetuer adipiscing elit, sed
diam nonummy nibh euismod
tincidunt ut laoreet dolore magna
aliquam erat volutpat. Ut wisi enim
ad minim veniam, quis nostrud
exerci tation ullamcorper suscipit
lobortis nisl ut aliquip ex ea
commodo consequat.
</p>
</div>
</div>
css code:
body{
margin:0;
padding 0;
}
#content{
width:900px;
height:auto;
overflow:hidden;
margin:0 auto;
margin-bottom:20px;
}
#left-content{
width:200px;
height:auto;
float:left;
}
#middle-content{
width:500px;
height:auto;
float:left;
}
img{
width:100%;
height:auto;
}
#right-content{
width:200px;
height:auto;
float:left;
}
#media (max-width:480px){
#content{
width:90%;
height:auto;
margin:0 auto;
}
#left-content{
width:100%;
height:auto;
float:left;
text-align:justify;
}
#middle-content{
width:100%;
height:auto;
float:right;
}
#right-content{
width:100%;
height:auto;
float:left;
}
}
plz help.
You could use display:flex; and mediaquerie.
DEMO set at 500px
#content {
display:flex;
}
#content>div {
flex:1;
}
img {
width:100%;
}
#media only screen and (max-width:500px){
#content {
flex-direction:column;
}
#content > div {
order:2;
}
#content #middle-content {
order:1;
width:100%;
}
}
body{
height:100%;
width:100%;
margin:0;
padding:0;
}
#content{
position:relative;
background:#dedede;
height:100vh;
}
#left-content{
border:1px solid red;
position:absolute;
bottom:0;
}
#right-content{
border:1px solid green;
position:absolute;
}
Here's a JSFiddle.
I don't think you can achieve this with pure CSS, given the fact that middle-content is, well, in the middle.
You may also want to trigger this if any window resizing occurs.
Try this: http://plnkr.co/edit/QfY8pf?p=preview
I created a separate div for the top-middle-content that was hidden at regular size and visible in the media tag. Resize the preview pane to below 480px to see the effect.
The problem with using things like flex is that only extremely recent browsers can display it. Most browsers would have no idea what it's talking about. (See https://developer.mozilla.org/en-US/docs/Web/CSS/flex Browser compatibility.)
Media itself is only supported since IE 9. So you might want to use a javascript solution instead. I'll post one soon as an edit.
EDIT:
You might try something like this:
(Or take a look at Bootstrap, if you want a more consistent and reliable solution.)
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
(
function($){
var currentWidth = 0;
var check = function() {
var newWidth = window.innerWidth;
if(currentWidth != newWidth) {
currentWidth = newWidth;
if(currentWidth < 480) {
$('#middle-content').empty();
$('#top-content').html($('#moveable').html());
$('#left-content, #middle-content, #right-content').removeClass('floatLeft');
}
else {
$('#middle-content').html($('#moveable').html());
$('#top-content').empty();
$('#left-content, #middle-content, #right-content').addClass('floatLeft');
}
}
}
setInterval(check, 300);
}
)(jQuery)
</script>
<link rel="stylesheet" href="style.css" />
<style>
.floatLeft {
float:left;
}
#left-content {
width:auto;
}
#middle-content {
width:auto;
}
#right-content {
width:auto;
}
#left-content.floatLeft,
#right-content.floatLeft {
width:200px;
}
</style>
</head>
<body>
<script type="text/template" id="moveable">
<div id="moveable-content"><h1>Middle Content</h1></div>
</script>
<div id="top-content"></div>
<div id="left-content">
<p>
<b>
Lorem ipsum dolor sit amet,
consectetuer adipiscing elit, sed
diam nonummy nibh euismod
tincidunt ut laoreet dolore magna
aliquam erat volutpat. Ut wisi enim
ad minim veniam, quis nostrud
exerci tation ullamcorper suscipit
lobortis nisl ut aliquip ex ea
commodo consequat.
</b>
</p>
</div>
<div id="middle-content"></div>
<div id="right-content">
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex
ea commodo consequat.
</p>
</div>
</body>
</html>
A non-flex based, non-javascript, fully css solution IS possible. Here are the parts, the explanation is at the end:
CSS:
body{
margin:0;
padding 0;
}
#content{
width:100%;
max-width: 900px;
height:auto;
overflow:hidden;
margin:0 auto;
margin-bottom:20px;
}
#content:after{
clear: both;
}
#left-content{
width: 33.33333%;
float:left;
left: 33.33333%;
position: relative;
}
#middle-content{
width: 33.33333%;
float:left;
right: 33.33333%;
position: relative;
}
img{
width:100%;
height: auto;
}
#right-content{
width: 33.33333%;
float:left;
position: relative;
}
#media (max-width:480px){
#content{
width:90%;
margin:0 auto;
}
#left-content{
width: 100%;
text-align:justify;
left: 0;
}
#middle-content{
width:100%;
left: 0;
}
#right-content{
width: 100%;
}
}
HTML:
<div id="content">
<div id="left-content">
<img src="img/img1.jpg"/>
</div>
<div id="middle-content">
<p>
<b>
Lorem ipsum dolor sit amet,
consectetuer adipiscing elit, sed
diam nonummy nibh euismod
tincidunt ut laoreet dolore magna
aliquam erat volutpat. Ut wisi enim
ad minim veniam, quis nostrud
exerci tation ullamcorper suscipit
lobortis nisl ut aliquip ex ea
commodo consequat.
</b>
</p>
</div>
<div id="right-content">
<p>
Lorem ipsum dolor sit amet,
consectetuer adipiscing elit, sed
diam nonummy nibh euismod
tincidunt ut laoreet dolore magna
aliquam erat volutpat. Ut wisi enim
ad minim veniam, quis nostrud
exerci tation ullamcorper suscipit
lobortis nisl ut aliquip ex ea
commodo consequat.
</p>
</div>
</div>
Okay, so as someone else already suggested, if you have a fairly complex design, you probably should consider using a responsive framework like Bootstrap or Foundation (or if you don't all of the goodness these frameworks deliver, you could use just their grid components). If you don't want to use a framework for whatever reason, you can at least learn from how they do things and one of the things both offer are ways to push/pull grid columns to change the display order. That's exactly what I did here:
I changed your source order to reflect the content as you want it to be on the smallest device size. So, you'll notice that the image is now in the left-content column.
I gave your columns a width of 100% on viewports less than 480px with a media-query. This way, each column will be the full width of the content div on those devices. Change the max-width in the media-query to whatever you want it to be.
Then, I specified that the columns should be only 33.33333% wide (yes, I used percentages to make it be more fluid, but you can use the same techniques with fixed widths if you prefer) outside the media-query and floated them ALL left.
By floating them all left, you can use positioning to offset the columns and literally change the display order. So, I gave each column position relative and on the left-content column I set the left value to 33.33333%. This essentially is "pushing" the column left by the same amount as the column width that we want it to occupy. Then I sent the right value for the middle-content column to 33.33333%, which "pulls" this column to the left to occupy the space where the other column is.
Here's a fiddle to show how it works.
How can I indent starting from the second line of a paragraph?
I've tried
p {
text-indent: 200px;
}
p:first-line {
text-indent: 0;
}
and
p {
margin-left: 200px;
}
p:first-line {
margin-left: 0;
}
and
(with position:relative;)
p {
left: 200px;
}
p:first-line {
left: 0;
}
Is it literally just the second line you want to indent, or is it from the second line (ie. a hanging indent)?
If it is the latter, something along the lines of this JSFiddle would be appropriate.
div {
padding-left: 1.5em;
text-indent:-1.5em;
}
span {
padding-left: 1.5em;
text-indent:-1.5em;
}
<div>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</div>
<span>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</span>
This example shows how using the same CSS syntax in a DIV or SPAN produce different effects.
This worked for me:
p { margin-left: -2em;
text-indent: 2em
}
Make left-margin: 2em or so will push the whole text including first line to right 2em. Than add text-indent (applicable to first line) as -2em or so.. This brings first line back to start without margin.
I tried it for list tags
<style>
ul li{
margin-left: 2em;
text-indent: -2em;
}
</style>
There is a CSS3 working draft that will (hopefully soon) allow you to write just:
p { text-indent: 200px hanging; }
Keep an eye on: https://developer.mozilla.org/en-US/docs/Web/CSS/text-indent
I needed to indent two rows to allow for a larger first word in a para. A cumbersome one-off solution is to place text in an SVG element and position this the same as an <img>. Using float and the SVG's height tag defines how many rows will be indented e.g.
<p style="color: blue; font-size: large; padding-top: 4px;">
<svg height="44" width="260" style="float:left;margin-top:-8px;"><text x="0" y="36" fill="blue" font-family="Verdana" font-size="36">Lorum Ipsum</text></svg>
dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p>
SVG's height and width determine area blocked out.
Y=36 is the depth to the SVG text baseline and same as font-size
margin-top's allow for best alignment of the SVG text and para text
Used first two words here to remind care needed for descenders
Yes it is cumbersome but it is also independent of the width of the containing div.
The above answer was to my own query to allow the first word(s) of a para to be larger and positioned over two rows. To simply indent the first two lines of a para you could replace all the SVG tags with the following single pixel img:
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" style="float:left;width:260px;height:44px;" />
If you style as list you can "text-align: initial" and the subsequent lines will all indent. I realize this may not suit your needs, but I was checking to see if there was another solution before I change my markup..
I guess putting the second line in would also work, but requires human thinking for the content to flow properly, and, of course, hard line breaks (which don't bother me, per se).
I am trying to set a nested div on the top right of its parent div and text to wrap around the nested div.
I really should understand how position, float and display work together.
Here is my sample:
CSS
.parentDiv {
width:295px;
border:1px solid black;
}
.parentDiv .childDiv1 {
width:36px;
border:1px solid black;
float:left;
}
.parentDiv .childDiv2 {
width:210px;
border:1px solid black;
float:left;
}
.parentDiv .childDiv3 {
width:44px;
right:0px;
top:0px;
border:1px solid gray;
position:relative;
float:right;
}
HTML
<div class="parentDiv">
<div class="childDiv1">
<img alt="adfasf" src="../img/image.gif">
</div>
<div class="childDiv2">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
<div class="childDiv3"> <span>search here</span>
</div>
</div>
</div>
Live jsfiddle
Like this: jsFiddle. Make the child div appear first as a child of childDiv2 and keep the CSS as-is.
Move it inside .childDiv2
Demo here
CSS (no change):
.parentDiv { width:295px;border:1px solid black; }
.parentDiv .childDiv1 { width:36px;border:1px solid black;float:left; }
.parentDiv .childDiv2 { width:210px;border:1px solid black;float:left; }
.parentDiv .childDiv3 { width:44px;right:0px;top:0px;border:1px solid gray; position:relative; float:right; }
HTML
<div class="parentDiv">
<div class="childDiv2">
<div class="childDiv1">
<img alt="adfasf" src="../img/image.gif">
</div>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
<div class="childDiv3">
<span>search here</span>
</div>
</div>
</div>
Here is a simplified version:
<div class="childDiv2">
<div class="childDiv3">
<span>search here</span>
</div>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</div>
CSS:
.childDiv2 { width:210px;border:1px solid black;}
.childDiv3 { width:44px;right:0px;top:0px;border:1px solid gray;float:right }
Here's my jsFiddle solution
In addition to the fix, I removed the unnecessary CSS.
The reason for this issue is parsing order. HTML is parsed left-to-right, top-to-bottom. When you have element-A declared after element-B, element-A will naturally be parsed after element-B.
As others have noted, all that needed to be done was to move the paragraph of text so that it's declared after childDiv3. This will allow childDiv3 to reside on the first line of childDiv2 and float itself normally.
Additionally, I added a margin to childDiv1 and some padding to parentDiv to space things out a bit. Feel free to strip out or modify properties as you wish. I also added a .clear element before the closing tag of parentDiv so that it would properly wrap around its floated child elements, as you may have intended it to.