I have a large group of "li" elements (consisting of an image, and several lines of text) that resides in a content div. My "li" elements are going to vary in size (some have long links, some have long titles, etc)
I'd like two columns across when possible; I need to do responsive, so when I get to mobile I'll probably have one column across. I thought having a fixed size "li" would do the trick, but obviously not. Each time one of the titles or links is longer than the other, it throws off all the blocks.
Would using div's be better vice using "li" elements?
<div>
<img src="test.png" />
<h2>One - average title is here</h2>
<h3>Link is here and this might be long also</h3>
</div>
Is there a better way to do this without the fixed height for an "li"? And why does my first element always seem lower? I know this isn't rocket science, but I can't seem to come up with the fix.
jsfiddle
I believe the following layout is better:
(Try resizing your browser window less than 480px to view the mobile layout.)
*{
margin: 0px;
padding: 0px;
}
html, body{
width: 100%;
}
li{
width: 40%;
vertical-align: top;
}
#media screen and (max-width: 480px){
li{
width: 80%;
}
}
ul,li {
padding: 0;
margin: 0;
}
#links {
font-size: 0;
text-align: center;
}
#links li {
font-size: 12px;
display: inline-block;
border: 1px solid #000000;
padding: 2px;
background: #c0c0c0;
margin: 5px;
}
#links li h2 {
font-size: 1em;
}
<ul id="links">
<li>
<img src="test.png" />
<h2>One - average title is here</h2>
<h3>Link is here and this might be long also</h3>
</li>
<li>
<img src="test.png" />
<h2>Two - this title is here and is really, really long</h2>
<h3>Link is here </h3>
</li>
<li>
<img src="test.png" />
<h2>Threee -title is here</h2>
<h3>Link is here </h3>
</li>
<li>
<img src="test.png" />
<h2>Four - this title is here and is really, really long</h2>
<h3>Link is here </h3>
</li>
<li>
<img src="test.png" />
<h2>Five title is here</h2>
<h3>Link is here </h3>
</li>
<li>
<img src="test.png" />
<h2>Six title is here</h2>
<h3>Link is here and this area can be long also </h3>
</li>
</ul>
Updated jsFiddle Demo
Readup: CSS #media queries | MDN
Remove that fixed size and put float: left instead.
#links li {
font-size: 12px;
border: 1px solid #000000;
padding: 0;
background: #c0c0c0;
float: left; /*change here*/
margin: 2%; /*responsive margin*/
width: 45%; /*and width*/
}
Now clear the left side of each 2n + 1 div:
#links li:nth-child(2n + 1){
clear: left;
}
And add a media query:
#media screen and (max-width: 400px){
#links li {
margin: 2% 0;
width: 97%;
}
}
JSFIDDLE.
Related
Hi! I am trying to place two paragraphs inside a DIV (a Name and a Job Position) for a responsive site.
.header {
min-height: 56px;
transition: min-height 0.3s;
max-width: 800px;
}
.header__inner {
margin-left: auto;
margin-right: auto;
float: left;
border: 3px solid #73AD21;
display: inline;
}
.header__text {
float: right;
border: 3px solid #73AD21;
display: inline;
}
<header class="header">
<div class="header">
<div class="header__inner">
<img class="header__logo" src="logo.jpg" alt="Logo">
</div>
<div class="header__text">
<p class="header__title">
NAME
</p>
<p class="header__subtitle">
CURRENT POSITION
</p>
</div>
</div>
</header>
Whenever I start playing with different sizes of screen both paragraphs switch places randomly. How can I make sure that they will stay in order?
This is how the page looks
Page with misplaced texts
And this is what I would like to accomplish
what I want to do
It seems you didn't post the CSS for the two elements whose position you want to switch, header__title and header__subtitle. But apparently they are both floated right. To make sure header__subtitle is NOT displayed to the left of header__title even if there is enough space, you can add this:
.header__subtitle {
clear: right;
}
This is probably has a really easy solution, since it is one of the most basic things in web design.
After a lot research and not finding the answer decided to ask it. Basically my webpage looks perfectly fine on my 13" Macbook but all the elements get messed up when I try to display it on my 27" desktop. I understand the core of the problem is that, when I set something to 300px, it covers much of the screen in 13" but just a little in 27" thus causing everything to sit on top of each other but I failed at finding a solution. Just to be clear, this is not a 100% issue of responsiveness, I don't want different layouts for different screens but I just want the same layout to look ok in many screens, just like you are resizing the page from the corners. Here is some of the code that I hope will be helpful. Also things that I have tried:
Using em instead of px. Not really helpful.
Using % instead of px. Not really helpful in cases like the first jumbotron where parent element doesnt have a defined height
HTML :
<body>
<div class="jumbotron">
<img src="images/banner.jpg" >
</div>
<div id="menu">
<ul class="nav nav-pills navbar-left">
<li> <p> 1 </p></li>
<li> <p> 2 </p> </li>
<li> <p> 3 </p></li>
<li> <p> 4 </p></li>
</ul>
<ul class="nav nav-pills navbar-right">
<li id="toleft"> <p> 5 </p> </li>
<li> <p> 6 </p></li>
<li> <p> 7 </p> </li>
<li> <p> 8 </p> </li>
</ul>
</div>
<!-- Script to fix navbar-->
<script>
$(document).ready(function(){
$(window).bind('scroll', function() {
var navHeight = $( window ).height() - 450;
if ($(window).scrollTop() > navHeight) {
$('#menu').addClass('fixed');
}
else {
$('#menu').removeClass('fixed');
}
});
});
</script>
<div id="displayframe">
<div id="display">
<img id="mainimage" src="images/col1.jpg" height="420" width="960" />
</div>
</div>
<!-- Script for changing images with time-->
<script>
$(document).ready(function(){
var imageArray = ["images/col2.jpg", "images/col3.jpg", "images/col4.jpg", "images/col5.jpg", "images/ban.jpg"];
var count = 0;
function loadImage(){
$("#mainimage").attr("src", imageArray[count]);
if(count == imageArray.length){
count = 0;
}else{
count = count + 1;
}
}
setInterval(function(){
loadImage();
}, 3000);
})
</script>
<div class="container">
<div id="head">
<p> RECENT NEWS </p>
</div>
</div>
<div class="newsfeed">
<ul>
<li>
<p style="float: left;"> <img src="images/chris.jpg" width="190px" /> </p>
<h2></h2>
<p id="bodypart">
</p>
</li>
<li class="newselement"><p style="float: left;"> <img src="images/city.jpg" width="190px" height="280px" /> </p>
<h2></h2>
<p id="bodypart">
</p></li>
<li class="newselement"><p style="float: left;"> <img src="images/alex.jpg" width="190px" height="280px" /> </p>
<h2></h2>
<p id="bodypart">
</p></li>
</ul>
</div>
CSS:
body{
background-color: black !important;
}
.jumbotron{
height: 320px;
background-color: black !important;
}
.jumbotron > img{
width: 100%;
margin-top: -50px;
}
#toleft{
left: -10px;
position: relative;
}
.nav p{
font-family: "Crimson Text";
font-size: 28px;
font-weight: bold;
z-index: 2;
}
.navbar-left{
margin-left: 20px;
position: relative;
}
.navbar-left li{
width: 120px;
}
.navbar-right{
left: -50px;
margin-left: 0px;
position: relative;
}
.navbar-right li{
width: 140px;
}
#menu{
background-color: black;
width: 99%;
margin-top: -110px;
}
.nav li p{
padding-left: 15px;
}
.fixed {
position: fixed;
top: 110px;
height: 50px;
z-index: 1;
background-color: black;
}
#display{
width: 960px;
height: 420px;
overflow: hidden;
margin: 30px auto 0px auto;
margin-top: 130px !important;
border-radius: 4px;
background-color: white;
}
#display ul{
position: relative;
margin: 0;
padding: 0;
height: 960px;
width: 420px;
list-style: none;
}
#display ul li{
position: relative;
display: block;
float: left;
margin: 0;
padding: 0;
width: 960px;
height: 420px;
}
#head > p{
font-family: "Crimson Text";
font-size: 30px;
font-weight: bold;
}
#head{
margin-top: 30px;
margin-left: 85px;
}
.tweets{
background-color: rgba(247,12,12,0.3);
margin-top: -800px;
margin-right: 50px;
border: 1px solid white;
border-color: white;
}
.newsfeed{
margin-left: 100px;
width: 60%;
height: 800px;
}
.newsfeed > ul{
list-style: none;
}
.newsfeed > img{
list-style: none;
display: inline-block;
position: absolute;
float: left;
}
.newsfeed > h2{
display: inline-block;
position: absolute;
margin-top: -50px;
margin-left: 50px;
float: right;
}
.newsfeed > li{
border-bottom: 1px white;
border-top: 1px white;
border-color: white;
height: 400px;
}
#bodypart{
font-size: 17px;
}
.newselement{
border-top: 1px solid white;
}
Actually this is responsive issue only because you are viewing your page on different screen or resolution. So if you want to create responsive website you have to add #media queries for different resolution.
-- #media queries
-- Outer div should keep fixed (px) or in percentage (%).
-- And inner div or content should wrap according to outer div width eg(width:100%).
-- Finally depend on different resolution change your css in #media queries.
Why use Px (pixels) which are pre-fixed? Instead play around with % (percents) which allow you to scale your webpage based on the user's screen. You could make your image 1600px wide which would be the full length of your MBP but for example on your Imac it only shows your image 1600px wide when really the Imac has 2880px for the screens width. Therefore you have another 1280px remaining to fill. If you were to use 100% it would fill 100% of who's ever screen is viewing your webpage. Hope this some what helps. You lost me on the 300px off.
I have setup a JSfiddle here.
I found a few things that you could add/modify to help improve your code and get things aligning better.
<img src="images/banner.jpg" > was not closed correctly you missed the / <img src="images/banner.jpg" />. Also you have no clearing tags anywhere in your code so of course when the width of your page scales out the elements on the page are going to stack up beside each other. I created a class;
<div class="clear"/>
.clear{
clear:both;
}
This i placed below each of your element sections so it will return them to the next line.
Next i placed a wrapper and a content div around your whole page content to center-align the content and make the page width 1000px (which is standard among most websites).
The images were not rendered into the JSfiddle becaise the paths are relative to your computer so i left them blank. If you want to see it working better please update the JSfiddle and i can help further.
-Epik
I've been having an enormous amount of trouble for what I thought would be easy, but it's turning out to be much more difficult than I had anticipated.
I have an image alt="home" that I want to center in my footer, with text underneath it, but margin-left and margin-right: auto don't work, margin: 0 auto doesn't work either. Are there other options to center something?
And for the address, it's being pushed down because the width of the copyright and "home" img have a width the size of the footer. When I try to apply a width percentage to the div containing the home img and the copyright text, it disappears for some reason?
This is the result I want to achieve: http://i.imgur.com/khjrZow.jpg
jsfiddle (with complete html and css): http://jsfiddle.net/A2H3n/
If anyone knows what's going on, and can let me know, that would make me so happy... but really, I've spent 4 hours trying to fix this(I've just started learning CSS). Any help would be appreciated!
Relevant HTML:
<footer>
<div id="sociallinks">
<img class="sociallogo" src="images/facebooklogo.jpg" alt="Facebook">
<img class="sociallogo" src="images/Twitterlogo.jpg" alt="Twitter">
</div>
<div id="logoandtext">
<img id="footerlogo" src="images/blackbeltinverse.png" alt="home">
<p>© Hsien-Jin Martial Arts Studio<p>
</div>
<div id="contactinfo">
<p>7548 Mahogany Rd</p>
<p>Los Angeles, CA 97789</p>
<p>(444) 123-4567 </p>
</div>
</footer>
Relevant CSS:
footer{
overflow: hidden;
display: block;
margin: 0 auto;
color: #FFFFFF;
}
#sociallinks{
float: left;
margin: 0;
display: block;
width: 20%;
height: 100%;
}
.sociallogo{
width: 3em;
height: 3em;
}
#footerlogo {
width: 4em;
height: 4em;
margin: 0 auto;
}
#contactinfo {
line-height: 1.25em;
text-align: right;
}
display:inline-block; may be the answer:
footer{
text-align:center;
}
#sociallinks, #logoandtext, #contactinfo{
display:inline-block;
}
#contactinfo{
float:right;
}
Fiddle : http://jsfiddle.net/bonatoc/PLbae/1/
CSS overwrites are at the very bottom.
You can do it like this
Move the #contactinfo div above the #logoandtext
HTML
<div id="sociallinks">/*Some thing here*/</div>
<div id="contactinfo">/*Some thing here*/</div>
<div id="logoandtext">/*Some thing here*/</div>
CSS
#logoandtext {
margin: 0 140px;
text-align: center;
}
#contactinfo {
float: right
}
Is there a simple way in CSS to position a number of images—stacked vertically—on the right) of a variable-sized image. The variable-sized image has a max-width defined that should be relative to the size of the browser window (i.e. it should be as big as possible to not fall off the screen, but not bigger than the actual image pixel dimensions). To make this more difficult, the markup is such that all <img>s are listed as equals, i.e., the images to appear on the right are not in a separate container.
Using a markup like the following, the size of each image is about equal.
<ul>
<li><img/></li> <!-- the big image -->
<li><img/></li>
<li><img/></li>
etc...
</ul>
By request, in a jsFiddle: http://jsfiddle.net/2p9gR/
It would be nice to do this in pure CSS(3), I don't need to support any browsers except my own (the latest Chrome).
Oh. And I will accept "no" for an answer, if it is the truth.
given your picture I have come up with the following solution:
HTML
<div class="container">
<div class="main-image"><img src="http://lorempixel.com/800/800/sports/1/" /></div>
<ul class="small-image-list">
<li><img src="http://lorempixel.com/120/120/sports/2/" /></li>
<li><img src="http://lorempixel.com/120/120/sports/3/" /></li>
<li><img src="http://lorempixel.com/120/120/sports/4/" /></li>
<li><img src="http://lorempixel.com/120/120/sports/5/" /></li>
</ul>
</div>
CSS
.container {padding-right:150px;}
.container .main-image {width:100%; float:left;}
.container .main-image img {width:100%; max-width:800px; max-height:800px;}
.small-image-list {list-style:none; margin:0 -150px 0 0; padding:0; width:120px; float:right;}
.small-image-list li {width:100%; overflow:hidden; padding-bottom:10px;}
#media all and (min-width: 950px) {
/*this is optional if you want the images to stick left when the page is over 950px;*/
.container {padding:0;}
.container .main-image {width:800px;}
.small-image-list {margin:0 0 0 30px; float:left;}
}
Example
Delete the media query if you want the large gutter
EDIT
Given the need for it all to be in a list you can try this:
HTML
<ul class="list">
<li><img src="http://lorempixel.com/800/800/sports/2/" /></li>
<li><img src="http://lorempixel.com/120/120/sports/3/" /></li>
<li><img src="http://lorempixel.com/120/120/sports/4/" /></li>
<li><img src="http://lorempixel.com/120/120/sports/5/" /></li>
</ul>
CSS
.list {list-style:none; padding:0 150px 0 0; margin:0;}
.list li {width:120px; float:right; padding:0; display:block; overflow:hidden; margin-right:-150px;clear:right; display:block;}
.list li:first-child {width:100%; float:left; margin:0; padding:0;}
.list li:first-child img {width:100%; max-height:800px; max-width:800px;}
List Example
Here is a partial solution. I needed to consider two cases that depend on the aspect ratio of the large image, portrait and landscape.
Case 1 - Portrait
<ul class="portrait">
<li class="first">
<img src="http://placekitten.com/300/1000" />
</li>
<!-- the next two images should 'float' right of the first one -->
<li>1
<img src="http://placekitten.com/800/600" />
</li>
<li>2
<img src="http://placekitten.com/800/560" />
</li>
</ul>
ul.portrait {
list-style: none;
border: 1px solid blue;
margin: 0;
padding: 0;
float: left;
}
ul.portrait li {
border: 1px dotted red;
width: 120px;
float: right;
clear: right;
margin-left: 30px;
}
ul.portrait li img {
width: 100%;
}
ul.portrait li.first {
float: left;
width: auto;
border: 1px dashed blue;
margin: 0;
}
ul.portrait li.first img {
vertical-align: top;
height: 100%;
max-height: 800px;
}
Case 2 - Landscape
<ul class="landscape">
<li class="first">
<img src="http://placekitten.com/1000/500" />
</li>
<!-- the next two images should 'float' right of the first one -->
<li>1
<img src="http://placekitten.com/800/600" />
</li>
<li>2
<img src="http://placekitten.com/800/560" />
</li>
<li>3
<img src="http://placekitten.com/800/560" />
</li>
<li>4
<img src="http://placekitten.com/800/560" />
</li>
<li>5
<img src="http://placekitten.com/800/560" />
</li>
<li>6
<img src="http://placekitten.com/800/560" />
</li>
</ul>
ul.landscape {
list-style: none;
border: 1px solid blue;
margin: 0;
padding: 0;
float: left;
}
ul.landscape li {
border: 1px dotted red;
width: 120px;
float: right;
clear: right;
margin-left: 30px;
}
ul.landscape li img {
width: 100%;
}
ul.landscape li.first {
float: left;
width: auto;
border: 1px dashed blue;
margin: 0;
}
ul.landscape li.first img {
vertical-align: top;
width: 100%;
max-width: 600px;
}
It is possible to get the images appearing in the correct configuration, bit there are some limitations.
Since floats are being used, as you make the screen more narrow, the right hand thumbnails will eventually stack below the large image. This suggests specifying a min-width for the parent ul containing block.
See Fiddle: http://jsfiddle.net/audetwebdesign/rsqW3/
The gist of the problem is in the rule for the large image. In the portrait case, you need to specify height: 100% and max-height: 800px and for the landscape case, you need to specify width: 100% and max-width: 600px. You can't quite make this distinction using CSS alone. The calc() value may be of some help but it is not yet widely supported.
I am using bootstrap to develop a responsive site.
I have two containers that have content which I don't want to break onto new lines if the window is resized.
I currently have this fiddle which demonstrates.
I thought using clearfix on the parent container for each news item would work. But the text is breaking from the image on resize.
You can see this in this image
Any clues?
This is the basic css (although it's all in the fiddle):
/* News items */
.news-item {
padding:10px 0 10px 10px;
}
.news-item p {
padding:0;
margin:0;
}
.news-item img,
.news-item-text {
float:left;
}
.news-item-text {
padding:0 0 0 5px;
}
.news-heading {
font-size:18px;
}
.news-tags {
font-family:ffs-italic;
font-size:12px;
}
This is the top of the html:
<div class="row"><!-- breaking and buzzing -->
<div class="span4"><!-- breaking news -->
<h2>Breaking</h2>
<div id="breakingNews" class="rounded clearfix">
<div class="news-item clearfix">
<a href="">
<img src="img/news/sm/sq01.jpg" width="54" height="54" />
</a>
<div class="news-item-text">
<p class="news-heading">Omni Scents to launch...</p>
<p class="news-subheading">At vero eos fragrance line inspired</p>
<p class="news-tags">BEAUTY, PRODUCTS</p>
</div>
</div>
<div class="news-item clearfix">
<a href="">
<img src="img/news/sm/sq02.jpg" width="54" height="54" />
</a>
<div class="news-item-text">
<p class="news-heading">IFF finishes year strong...</p>
<p class="news-subheading">Lorem ipsum in dolor contratis</p>
<p class="news-tags">INDUSTRY</p>
</div>
</div>
You in those cases you need to float your divs and also specify a width for the div, like this:
.news-item {
padding: 10px 0 10px 10px;
float: left;
width: 220px;
}
Also you need to determine the width of each <p>inside the divs, like this:
.news-item-text {
padding: 0 0 0 5px;
width: 160px;
}
For responsive layout, you need to use the tag #mediato set each width again, like:
#media (max-width: 767px) {
.news-item {
padding: 10px 0 10px 10px;
float: left;
width: 160px;
}
.news-item-text {
padding: 0 0 0 5px;
width: 100px;
}
}
I hope it works!
.news-item a
{
display: block;
float: left
}
.news-item-text
{
float: right;
width: 75%; /* adjust this to fit */
}