I have 2 divs:
div.main-info {
background: yellow;
width: 50%;
float: left;
}
div.main-cta {
background: red;
width: 20px;
}
<div id="wrapper">
<div class="main-info">
<h1>Lorem Ipsum?</h1>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
</div>
<div class="main-cta">
<div class="window-cta">
<p>Compare Now!</p>
</div>
</div>
</div>
but the div with class main-cta seems to be still at the 2nd line? Why is that? I thought that when you float a div, it will pop out of the doc's flow and the next element will occupy the first row where the floated element was and get hidden by it?
I'm kinda confused.
Thanks!
Try this
<style>
div.main-info {
background: yellow;
width: 50%;
float: left;
}
div.main-cta {
background: red none repeat scroll 0 0;
float: left;
width: auto;
}
</style>
I think it will help for you..
div.main-info {
background: yellow;
width: 50%;
float: left;
}
div.main-cta {
background: red;
background: red none repeat scroll 0 0;
float:right;
}
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<div id="wrapper">
<div class="main-info">
<h1>Lorem Ipsum?</h1>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<div class="main-cta">
<div class="window-cta">
<p>Compare Now!</p>
</div>
</div>
</div>
</div>
Just add float:left to div.main-cta .
div.main-info {
background: yellow;
width: 50%;
float: left;
}
div.main-cta {
background: red;
width: 20px;
float: left; /*new line*/
}
Demo fiddle: https://jsfiddle.net/nikhilvkd/f6stjstk/
Or you dont like to add float:left , you can use display:inline-block;
div.main-info {
background: yellow;
width: 50%;
display: inline-block; /*new line*/
}
div.main-cta {
background: red;
width: 20px;
display: inline-block; /*new line*/
vertical-align: top;
}
Demo fiddle: https://jsfiddle.net/nikhilvkd/f6stjstk/2/
In order to pop the div out of the flow, you need to make the position of the div absolute.
float asks the div to move toward the left, in the same row.
Related
This has been driving me nuts. Every solution I find doesn't work. Can someone please - once and for all instruct me on how to fix this issue:
Two flex boxes side by side inside a flex display.
Flex box 1 contains long text which needs to be shorted with ellipses. Instead, the long text causes a resize of the flex box 1. I do not want either flex box to resize or reposition based on the contents.
.wrapper {
width: 50%;
display: flex;
background-color: green;
}
.container {
flex: 1;
margin: 10px;
border: 2px solid blue;
height: 200px;
background: pink;
}
span {
user-select: none;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
<div class="wrapper">
<div class="container">
<span>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</span>
</div>
<div class="container"></div>
</div>
If you are wanting the 2 boxes to stay equal width, I would just add a width to them (you'll also need to give your span a width to make the ellipsis work):
.wrapper {
width: 50%;
display: flex;
background-color: green;
}
.container {
flex: 1;
margin: 10px;
border: 2px solid blue;
height: 200px;
background: pink;
width: calc(50% - 20px); /* 20px is the left and right margin */
box-sizing: border-box; /* add this so width includes your border */
}
span {
user-select: none;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
display: block; /* add this so you can give the span a width so the ellipsis will work */
width: 100%;
}
<div class="wrapper">
<div class="container">
<span>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</span>
</div>
<div class="container"></div>
</div>
First, get rid of the <span> and put that information into the first <div> with the class = "container" and get rid of the second <div> container class, but keep the first one. In CSS, remove .span, and in .container, add overflow: scroll;
wrapper {
width: 50%;
display: flex;
background-color: green;
}
.container {
flex: 1;
margin: 10px;
border: 2px solid blue;
height: 200px;
overflow: scroll;
background: pink;
}
<div class="wrapper">
<div class="container">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
I'm trying to prevent an image and text from overlapping with each other in html. Currently this is what I have:
But when the screen size gets smaller, the text and image intercept. I'm looking to make it so the text conform to the boarders of the image. This is what's happening now:
Lastly, this is my CSS
.image {
width: 500px;
margin-left: auto;
display: block;
padding-top: 10%;
padding-right: 10%;
}
.text {
font-size: 22px;
padding-top: 10%;
max-width: 700px;
position: absolute;
}
Your issue is with absolute positioning. Whenever you use position:absolute you remove that element from the source flow. You can try to remove the absolute positioning and then try something like the following:
Codepen example
<div class="parent">
<div class="text">
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem
Ipsum has been the industry's standard dummy text ever since the 1500s, when an
unknown printer took a galley of type and scrambled it to make a type specimen
book. It has survived not only five centuries, but also the leap into electronic
typesetting, remaining essentially unchanged. It was popularised in the 1960s with
the release of Letraset sheets containing Lorem Ipsum passages, and more recently
with desktop publishing software like Aldus PageMaker including versions of Lorem
Ipsum.
</p>
</div>
<div class="image">
Place your image here.
</div>
And CSS:
.parent {
display: flex;
max-width: 1000px;
margin: 0 auto;
}
.text, .image {
padding: 15px;
}
.image {
width: 500px;
}
.text {
width: calc(100% - 500px);
}
I have a fiddle,
https://jsfiddle.net/thakv1/9zf1tm7q/2/
HTML :-
<div class = "single-page">
<div class="navigation">
<div class ="circle">
1
</div>
</div>
<div class="content">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
CSS:-
.single-page{
display: flex;
flex-flow: row nowrap;
}
.content{
height: 400px;
flex:1;
background-color:white;
}
.navigation{
width : 52px;
}
.circle{
width: 30px;
line-height: 30px;
border-radius: 50%;
text-align: center;
background-color: #295ED9;
color: white;
font-weight: 700;
cursor: pointer;
text-decoration: none;
margin: 20px 10px;
}
In this fiddle the height of navigation is 400px, i want height of navigation equal to height of circle div (around 30px something) not content div.How can we achieve this.
You should add align-self:flex-start to .navigation
.single-page{
display: flex;
flex-flow: row nowrap;
}
.content{
height: 400px;
flex:1;
background-color:red;
}
.navigation{
width : 52px;
background: red;
align-self:flex-start;
}
.circle{
width: 30px;
line-height: 30px;
border-radius: 50%;
text-align: center;
background-color: #295ED9;
color: white;
font-weight: 700;
cursor: pointer;
text-decoration: none;
margin: 20px 10px;
}
<div class = "single-page">
<div class="navigation">
<div class ="circle">
1
</div>
</div>
<div class="content">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
I was trying to do an udacity's assignment, i want to move the paragraph to the right of the image please help.
I actually tried putting div tags for each and every block ie heading and image and a paragraph
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div>
<div class="heading">
<h1>MY FAVOURITE APP</h1>
</div>
<div class="data">
<div class="data">
<img src="C:\Users\sreem\Desktop\pix.jpeg" alt="">
<div>
<p class="para">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
**style.css**
css code for html file
img {
height: 250px;
width: 250px;
margin-top: 20px;
margin-left: 100px;
}
.heading {
height: 70px;
width: 80%;
margin-top: 50px;
color:white;
background-color:#5AB9BA;
padding-top: 70px;
letter-spacing: 5px;
margin-left: 100px;
}
.para{
height: 250px;
width: 250px;
margin-left: 400px;
}
Float the image to the left.
img {
height: 250px;
width: 250px;
margin-top: 20px;
margin-left: 100px;
float: left; /** float the image to the left **/
}
.heading {
height: 70px;
width: 80%;
margin-top: 50px;
color: white;
background-color: #5AB9BA;
padding-top: 70px;
letter-spacing: 5px;
margin-left: 100px;
}
.para {
height: 250px;
width: 250px;
margin-left: 400px;
}
<div>
<div class="heading">
<h1>MY FAVOURITE APP</h1>
</div>
<div class="data">
<img src="http://lorempixel.com/250/250/" alt="">
<p class="para">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with
desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
</div>
</div>
You can use float property. I gave float: left; to img tag.
img {
height: 250px;
width: 250px;
margin-top: 20px;
margin-left: 100px;
float: left;
}
.heading {
height: 70px;
width: 80%;
margin-top: 50px;
color:white;
background-color:#5AB9BA;
padding-top: 70px;
letter-spacing: 5px;
margin-left: 100px;
}
.para{
height: 250px;
width: 250px;
margin-left: 400px;
}
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div>
<div class="heading">
<h1>MY FAVOURITE APP</h1>
</div>
<div class="data">
<div class="data">
<img src="https://www.w3schools.com/css/img_fjords.jpg" alt="">
<div>
<p class="para">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
Force image float to left:
display:inline-block;
float:left;
img {
height: 250px;
width: 250px;
margin-top: 20px;
margin-left: 100px;
display:inline-block;
float:left;
}
For some reason my divs aren't gaining height when I apply .section {height: 100%;}, but when I give it a height attribute in pixels it works. The idea is that I want the divs to use the browsers window, so the div would cover entire section of the browser no matter what the resolution of the display.
http://jsfiddle.net/marrto/npe2y/
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title> 10 </title>
<!-- Slidebars CSS -->
<link href="css/mystyle.css" rel="stylesheet" text="text/css" >
</head>
<body>
<!-- MAIN AREA -->
<!-- WRAPPER - WRAPPS NAVIGATION AND LOGO-->
<div id="wrapper">
<div id="header">
<div class="logo">
<img src="logo.png" alt="Logo">
</div>
<div class="navBar">
<ul id="nav">
<li>Homepage</li>
<li>About</li>
<li>Photos</li>
<li>Contact</li>
</ul>
</div>
<div style="clear: both;"> </div>
</div>
</div>
<!-- WRAPPER END -->
<div id="topbar" class="section">
<div class="content">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
<div id="about" class="section">
<div class="content">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
<div id="photos" class="section">
<div class="content">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
<div id="contact" class="section">
<div class="content">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
</div>
<!-- WRAPPER - WRAPPS NAVIGATION AND LOGO-->
<div id="container">
<div id="footer">
<div class="legal">
text
</div>
<div class="site">
Text
</div>
<div style="clear: both;"> </div>
</div>
</div>
<!-- WRAPPER END -->
</body>
</html>
body { /* general font size, family and color */
font-family: Arial, Helvetica, sans-serif;
font-size: .9em;
color: #343434;
margin: 0;
padding: 0;
}
.sb-toggle-left {
display: none;
}
#wrapper { /* wrapps logo and the navigation links */
background-color: #ffffff;
height: 60px;
width: 100%;
top: 0;
left: 0px;
position: relative;
z-index: 99;
-moz-box-shadow: 0 0 3px 0 #ccc;
-webkit-box-shadow: 0 0 3px 0 #ccc;
box-shadow: 0 0 3px 0 #ccc;
}
.section:nth-child(odd) {
background-color: #b1d994;
}
.section:nth-child(even) {
background-color: #5bc473;
}
.section {
height: 100%;
padding: 5%;
}
.content {
width: 60%;
margin-right: auto;
margin-left: auto;
text-align: justify;
}
/*
#topbar {
background-image: url('banner.jpg');
}
*/
#header {
width: 60%;
position:relative;
margin-left: auto;
margin-right: auto;
min-width: 600px;
}
.logo {
float: left;
padding-top: .9em;
}
.navBar {
float: right;
padding-top: 1.3em;
}
.navBar ul {
list-style-type:none;
margin:0;
padding:0;
overflow:hidden;
}
.navBar li {
float:left;
}
.navBar a:link, .navBar a:visited {
display: block;
color:#4a4949;
padding:4px;
text-decoration:none;
text-transform:uppercase;
font-size: 0.8em;
}
.navBar a:hover {
color:#ababab;
}
#container { /* wrapps logo and the navigation links */
background-color: #ffffff;
height: 60px;
width: 100%;
top: 0;
left: 0px;
-moz-box-shadow: 0 0 3px 0 #ccc;
-webkit-box-shadow: 0 0 3px 0 #ccc;
box-shadow: 0 0 3px 0 #ccc;
}
#footer {
width: 60%;
position:relative;
margin-left: auto;
margin-right: auto;
}
.legal {
float: left;
padding-top: 1.3em;
}
.site {
float: right;
padding-top: 1.3em;
}
If the parent element doesn't have height set explicitly, % height won't work in it's children...
in your case the parent of divs having class section is <body>, which doesn't have a height set.
HERE a wirking fiddle.
I just changed 100% with 100vh
.section {
height: 100vh;
padding: 5%;
}
You need to set following css:
html,body{
height:100%;}
you can do this using js
element = document.getElementsByClassName("section");
for(element in ele){
ele.style.width=screen.width+"px";
}
if width is gonna fixed the height won't change
For me it worked by setting position: absolute in the very top level container div.