I've got the following situation where I'd like the list on the right to use just the remaining space until it's passed the content on the left at which point it can take up the full width again.
I can get it done by hardcoding a margin-left: 50% for the first few <li> but this is inadequate since I don't know the text-wrapping div's dimensions.
.intro {
width: 50%;
float: left;
}
li {
display: block;
height: 50px;
border: 1px solid black;
}
<div class="intro">Some text and stuff and text and maybe some more text and donuts let's play high powered god mutant prototype<br>Some more text to illustrate obviouslycate some wrapping</div>
<div class="list">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
I am assuming that you want the content of list items to be next to the floated content. You can accomplish this by using regular divs. Not sure as to why you are utilizing ul and li tags.
FAUX Solution:
Fiddle: http://jsfiddle.net/jebgerp8/.
HTML:
<div class="intro">
Some text and stuff and text and maybe some more text and donuts let's play high powered god mutant prototype<br>Some more text to illustrate obviouslycate some wrapping
</div>
<div class = "li">
<img src = "http://placehold.it/50x50" />
</div>
<div class = "li">
<img src = "http://placehold.it/50x50/ff0000" />
</div>
<div class = "li">Another "list item"</div>
<div class = "li">Fourth "list item"</div>
<div class = "li">Last "list item"</div>
CSS:
.intro {
width: 50%;
float: left;
border: 2px dashed #bbb;
}
.li {
height: 50px;
margin: 2px 0;
}
.li:nth-last-of-type(-n + 3) {
border: 1px solid #000;
}
TRUE Adjustable Solution via Flexbox (requires modern browser).
Fiddle: http://jsfiddle.net/148y1b18/
CSS:
.intro {
width: 50%;
float: left;
border: 2px dashed #bbb;
}
.li {
height: 50px;
display: flex;
border: 1px solid #000;
}
.li + .li {
margin-top: 2px;
}
add this:
.list {
width:50%;
float:right;
}
Demonstration:
.intro {
width: 50%;
float: left;
}
.list {
width:50%;
float:right;
}
li {
display: block;
height: 50px;
border: 1px solid black;
}
<div class="intro">Some text and stuff and text and maybe some more text and donuts let's play high powered god mutant prototype<br>Some more text to illustrate obviouslycate some wrapping</div>
<div class="list">
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
I'm not sure what you were trying to do with the black border but if I have a little more information I could probably help out with that a bit more too.
Part of the problem you had with the list was that you left out your . in front of the li. Look at your css above. It was not taking on the elements that you had specified.
check out this js fiddle. I think it's what you are looking for, short of the border probably.
http://jsfiddle.net/j9pekyje/
<p class="intro">Some text and stuff and text and maybe some more text and donuts let's play high powered god mutant prototype<br>Some more text to illustrate obviouslycate some wrapping</p>
<ul>
<li>hi i like pancakes</li>
<li>hi i like pancakes</li>
<li>hi i like pancakes</li>
<li>hi i like pancakes</li>
<li>hi i like pancakes</li>
<li>hi i like pancakes</li>
<li>hi i like pancakes</li>
<li>hi i like pancakes</li>
<li>hi i like pancakes</li>
</ul>
.intro {
width: 50%;
float: left;
}
.list {
width:50%;
float:right;
}
.li {
display: block;
height: 50px;
border: 1px solid black;
}
Just a heads up on this as well. You could potentially run into some issues with total being 100% with or without setting margin or padding because that is usually additive. Something to be aware of in the future. Hope this helps you.
Related
I'm currently working on an old website that was created with some old crappy WYSIWYG editor. I'm new to web-dev and still trying to get my head around positioning elements properly. My current issue is, from what I have read, using absolute positioning is BAD, but how would you change this?
So this is the old code:
<div id="wb_Text1"
style="margin:0;
padding:0;
position:absolute;
left:187px;
top:24px;
width:83px;
height:147px;
text-align:left;
z-index:1;
border:0px #C0C0C0 solid;
overflow-y:hidden;
background-color:transparent;
">
<div style="font-family:'.Helvetica Neue DeskInterface';font-size:15px;color:#000000;">
<div style="text-align:left">
<span style="font-family:Arial;font-size:43px;color:#FFFFFF;">
<strong>W</strong>
</span>
</div>
<div style="text-align:left">
<span style="font-family:Arial;font-size:43px;color:#FFFFFF;">
<strong>A</strong>
</span>
</div>
<div style="text-align:left">
<span style="font-family:Arial;font-size:43px;color:#FFFFFF;">
<strong>C</strong>
</span>
</div>
</div>
And what I have come up with to replace it is:
HTML
<div class="logo-ul">
<ul>
<li>W</li>
<li>A</li>
<li>C</li>
</ul>
</div>
CSS
.logo-ul {
list-style-type: none;
color: white;
font-size: 2em;
z-index:24;
float: right;
margin-right: 80%;
}
Which looks fine until you collapse the window and it falls apart :( lol.
You can see what I'm doing here http://media.wacmotorcycles.co.uk/
How should I be writing this please?
Thanks.
Try changing #logo to
#logo {
max-width: 165px;
max-height: 171px;
margin: 0.75em 0;
float: left;
}
And, .logo-ul to
.logo-ul {
list-style-type: none;
color: white;
font-size: 2em;
z-index: 24;
float: left;
}
There is nothing inherently wrong with absolute positioning. If used incorrectly, it can have unexpected results when working with responsive layouts.
In your specific case, the W A C might be better implemented as part of the logo image itself rather than text. It's not offering any semantic or SEO benefit to include the letters in a list. Short of that, this is one way to implement what I think you're after:
.logo {
height: 6rem;
padding-left: 50px;
}
.logo-letter {
display: block;
height: 2rem;
}
<div class="logo">
<span class="logo-letter">W</span>
<span class="logo-letter">A</span>
<span class="logo-letter">C</span>
</div>
So I am creating this website, With a top navigation menu, a left navigation menu and a main content container, all made with bootstrap. The problem is, I can't get the text in the top navigation menu and the left navigation menu to center vertically. I assume both have the same problem, so I will only show the code of the left menu:
HTML:
<div class="row">
<div class="col-md-3 z-overview-left-menu">
<ul class="z-left-list">
<li class="z-left-list-item"><span class="z-test">One</span></li>
<li class="z-left-list-item z-selected">Two</li>
<li class="z-left-list-item">Three</li>
</ul>
</div>
<div class="col-md-9 z-overview-main-menu">
</div>
</div>
CSS:
.z-selected {
background-color: rgb(255, 216, 0);
}
.z-left-list {
vertical-align: middle;
padding-left: 0;
list-style: none;
}
.z-left-list-item {
display: block;
vertical-align: middle;
height: 7%;
font-size: 150%;
border-bottom: 1px solid black;
}
Simplified Jsfiddle: Jsfiddle
So what am I doing wrong? I already tried adding display: table to the z-left-list and display: table-cell to the z-left-list-item classes.
Try something like this:
<div class="z-overview-left-menu">
<ul class="z-left-list">
<li class="z-left-list-item"><span class="z-test">One asdfasd fasd fasdf asdf asdf</span></li>
<li class="z-left-list-item z-selected"><span>Two</span></li>
<li class="z-left-list-item"><span>Three</span></li>
</ul>
</div>
.z-left-list {
padding-left: 0;
list-style: none;
}
.z-left-list-item {
width:100%;
display: table;
vertical-align: middle;
height: 60px;
font-size: 150%;
border-bottom: 1px solid black;
}
.z-left-list-item span {
display:table-cell;
vertical-align:middle;
}
https://jsfiddle.net/fekfrwoz/7/
I would strongly recommend that you use the navbar classes. See here. This will make your code easier to maintain, and will take advantage of a lot of jscript coding done by Bootstrap to make those navbars work. For example, on a mobile screen, navbars will collapse into the hamburger icon (the three stacked horizontal bars that give you a pulldown). In my latest web app, I have two navbars (although located different from what you describe), and it works great.
If you know your list items will only have one line of text, you could always just add line-height to the .z-left-list-item class definition.
https://jsfiddle.net/fekfrwoz/1/
You could remove the height of the .z-left-list-item and use padding on the top and the bottom of the li, like so:
padding: 35px 0;
Which would emulate them being in the center of the li?
I have the following code which creates a list containing images.
HTML:
<ul>
<li class="list">
<div class="list_div">
<img class="list_image" align="top" src=""/>
<h3><a>Headline 1</a></h3>
<p>text,text,text,text,text,text</p>
</div>
</li>
<li>
<div class="list_div">
<img class="list_image" align="top" src=""/>
<h3><a>Headline 2</a></h3>
<p>text,text,text,text,text,text.</p>
</div>
</li>
</ul>
CSS:
li {
padding: 2px;
color: #000000;
font-size: 12px;
text-align: left;
vertical-align: middle;
word-wrap: break-word;
border-bottom: 1px solid #AFAFAF;
background-color: #CCD5DF;
}
.list_div {
width: 100%;
display: block;
}
.list_image {
float: left;
width: 30%;
height: auto;
border: 2px solid #000;
left: 0;
top: 0;
}
I want to:
place image in left and headline, text in right side. ==> in first List
place image in center and show headline, text within Image in center ==> in second List
BUT, this style need to follow:
image width 30% in 1st List and 50% in second List.
ul, li in static position.
page is responsive.
here is my code sample, link: http://jsfiddle.net/2ycggga9/
is this what u want to do
http://jsfiddle.net/2ycggga9/5/
.list2 > h3,.list2>p{
position:relative;
left:-23%;
}
<li class="list2">
<img class="list_image" src="http://thekitemap.com/images/feedback-img.jpg"/>
<h3><a>Headline 2</a></h3>
<p>text,text,text,text,text,text.</p>
</li>
In a way this is simple but I have been trying to figure out this for hours now so I decided to write the problem down and maybe with your help I could find a solution.
On layout heading (h1, h2, h3) have a line next to them. Basically somehting like this:
Example Heading--------------------------------------------
Another Example Heading---------------------------------
One more------------------------------------------------------
So that is end result (----- is gfx as background-image). How would you do it? The background color could change and/or have opacity.
One thing what I was thinking would be this:
<h1><span>Example Heading</span></h1>
when the CSS would look lke this:
h1 {
background-image: url(line.png);
}
h1 span {
background: #fff;
}
But since the background color can be something else than white (#fff) that doesn't work.
Hopefully you did understand my problem :D
Hacky but, maybe something like this:
HTML:
<h1>
<span>Test</span>
<hr>
<div class="end"></div>
</h1>
And the css:
h1 span{ float :left; margin-right: 1ex; }
h1 hr {
border: none;
height: 1px;
background-color: red;
position: relative;
top:0.5em;
}
h1 div.end { clear:both; }
Fiddle here
This worked for me.
HTML
<div class="title">
<div class="title1">TITLE</div>
</div>
CSS
.title {
height: 1px;
margin-bottom: 20px;
margin-top: 10px;
border-bottom: 1px solid #bfbfbf;
}
.title .title1 {
width: 125px;
margin: 0 auto;
font-family: Arial, sans-serif;
font-size: 22px;
color: #4c4c4c;
background: #fff;
text-align: center;
position: relative;
top: -12px
}
I don't think you can achieve this with pure css because the heading text could be any length. Here is a dynamic javascript solution which sets the width of the line image based on the width of the heading text.
Click here for jsfiddle demo
html (can be h1, h2 or h3)
<div class="heading-wrapper">
<h1>Example Heading</h1>
<img src="line.png" width="193" height="6" alt="" />
</div>
css
h1{font-size:16px}
h2{font-size:14px}
h3{font-size:12px}
h1,h2,h3{margin:0;padding:0;float:left}
.heading-wrapper{width:300px;overflow-x:hidden}
.heading-wrapper img{
float:right;padding-top:9px;
/*ie9: position:relative;top:-9px */
}
jquery
setHeadingLineWidth('h1');
setHeadingLineWidth('h2');
setHeadingLineWidth('h3');
function setHeadingLineWidth(selector){
var hWidth;
var lineWidth;
var wrWidth = $('.heading-wrapper').width();
hWidth = $(selector,'.heading-wrapper').width();
lineWidth = wrWidth - hWidth;
$(selector).siblings('img').width(lineWidth);
}
heading width = width of the heading text inside the wrapper
line image width = wrapper width - heading text width
Hope that helps :)
At the top of a page I've got two divs, one floated to the left and one to the right. I can place text with a border between them, however, I now need to stack two such areas of text between them.
Here's a Fiddle illustrating my problem: http://jsfiddle.net/TcRxp/
I need the orange box under the green box, with each center aligned with the other. The "legend" (floated to the right) used to be at the same level but is shifted down now.
I tried adding another table to the mix but that didn't help.
Excuse the markup - it's not real slick, I know. A few people have touched this over time and none of us are gurus at this.
And yes, I have lobbied for a designer to be added to the team but it hasn't happened yet.
Thanks,
Paul
UPDATE: Incorporating #Jeremy B's suggestion
Does it have to be via CSS changes? When dealing with scenarios like this, you need to be careful of the order in which the HTML elements are defined.
Look at the modification here: http://jsfiddle.net/TcRxp/8/
I was able to acheive what you needed by changing the order of the three DIVs and using the CSS suggesion from #Jeremy B
Essentially, the logic for the layout is
Draw the float-right content
Draw the float-left content
Draw the content in the middle (as it will now render to the right of the float-left content.
First make your top span a block element to stack them:
<span class="color status active bold" style="display:block">Status:</span>
then float the middle div left as well:
add float:left to #headmiddle in your css
It's always going to be difficult to get the desired results when you're combining CSS and tables-for-layout.
I would suggest simplifying your HTML:
<div id="headleft">a little search form here</div>
<div id="headmiddle">
<div class="active"><strong>Status:</strong> Active</div>
<div class="search">Search results displayed</div>
</div>
<div id="headright">
<dl>
<dt>Legend:</dt>
<dd>Status numero uno</dd>
<dd>Status two</dd>
</dl>
</div>
and your CSS:
div { padding: 2px; }
strong { font-weight: bold; }
#headleft { float: left; font-size: 0.8em; }
#headmiddle { float: left; font-size: 0.8em; }
#headmiddle div { border: 1px solid #000; margin-bottom: 3px; }
.search { background: orange; }
.active { background: #8ed200; }
#headright { float: right; font-size: 0.8em; }
dt { float: left; font-weight: bold; }
dd { margin-left: 4.5em; }
The result is semantically correct HTML, easier to read and therefore easier to modify in the future. Supporting fiddle.
If you need to do it with CSS, see my changes: Fiddle
I added the following:
#headmiddle span.status { display: block }
This will cause your spans to "stack".
I got it by putting together many different sources. Alex Coles' solution was closest right off the bat but the middle wasn't centered. It was much cleaner than my mess too. I started with the code from this post:
<style type="text/css">
.leftit {
float: left;
}
.rightit {
float: right;
}
.centerit {
width: 30%;
margin-right: auto;
margin-left: auto;
text-align: center;
}
.centerpage {
width: 80%;
margin-right: auto;
margin-left: auto;
}
</style>
</head>
<body>
<div class="centerpage">
<div class="leftit">Hello Left</div>
<div class="rightit">Hello Right</div>
<div class="centerit">Hello Middle</div>
</div>
(fiddle for above)
I took the elements Alex cleaned up which got me even closer to my goal, but the center color blocks were way too wide. From this question I learned about "max-width", which ended up being the final piece I needed...or so I thought.
Edit: max-width doesn't work in IE7 quirks mode (which I have to support) so from this page I learned how to tweak my css to work in IE7 quirks mode, IE8, and FF.
The final code (fiddle):
.leftit {
float: left;
font-size: 0.8em;
}
.rightit {
float: right;
font-size: 0.8em;
}
.centerit {
width:220px;
margin-right: auto;
margin-left: auto;
font-size: 0.8em;
}
#headmiddle div {
border: 1px solid #000;
margin-bottom: 3px;
}
.centerpage {
margin-right: auto;
margin-left: auto;
text-align: center;
}
strong { font-weight: bold; }
.search { background: orange; }
.active { background: #8ed200; }
dt { float: left; font-weight: bold; }
dd { margin-left: 4.5em; }
<div class="centerpage">
<div class="leftit">a little search form here</div>
<div class="rightit">
<dl>
<dt>Legend:</dt>
<dd>Status numero uno</dd>
<dd>Status two</dd>
</dl>
</div>
<div class="centerit" id="headmiddle">
<div class="active"><strong>Status:</strong>
Active</div>
<div class="search">Search results displayed</div>
</div>
</div>
Thanks to all the great answers - I learned a lot from this question.
Paul