In a responsive design website, I need to show four links presented side-by-side and have the collection of those 4 links enclosed within a self-resizing border. If all four links can't all fit horizontally on one line without overwriting each other, those links that can't fit should drop down to subsequent lines and the bounding border box should increase in size.
My main problem is that the bounding box... doesn't surround the links or resize properly. What am I doing wrong?
Here's the code and CSS that I've tried: http://jsfiddle.net/K3jyD/
HTML:
<div class="boundingbox">
<div class="boundeditem">
<div style="text-align: center;"><a title="Link Number One" href="http://www.abc.com/1/"><span><strong>NUMBER ONE</strong></span></a>
</div>
</div>
<div class="boundeditem">
<div><a title="Link Number Two" href="http://www.abc.com/2/"><span><strong>NUMBER TWO</strong></span></a>
</div>
</div>
<div class="boundeditem">
<div><a title="Link Number Three" href="http://www.abc.com/3/"><span><strong>NUMBER THREE</strong></span></a>
</div>
</div>
<div class="boundeditem">
<div style="text-align: center;"><a title="Link Number Four" href="http://www.abc.com/4/"><span><strong>NUMBER FOUR</strong></span></a>
</div>
</div>
</div>
CSS:
.boundingbox {
border: 1px solid red;
padding:10px;
margin:10px;
clear:both;
}
.boundeditem {
width:25%;
min-width:25%;
max-width:25%;
float:left;
padding:10px;
}
.boundeditem div {
text-align: center;
}
.boundeditem a {
text-decoration: underline;
}
I am not permitted to use jquery or external javascript libraries other than plain old html and css on this project.
The float:left is bringing your links outside the bounding box. Try this instead:
.boundeditem {
width:25%;
min-width:25%;
max-width:25%;
display: inline-block;
padding:10px;
}
If you want four links next to each other rather than three, make the width slightly smaller than 25% and put the padding in the div inside boundeditem rather than boundeditem itself.
.boundeditem {
width:24%;
min-width:24%;
max-width:24%;
display: inline-block;
}
.boundeditem div {
text-align: center;
padding: 10px;
}
add this to the .boundingbox
.boundingbox {
position: absolute;
height: auto;
}
Not sure if that's exactly what you're looking for.
Related
I'm working on a tiny css action which based on A element hover, will display another element. The code is pretty basic:
<a title="#" class="portfolio-reaction" href="#">
<img src="http://i.imgur.com/OZb7SI8.png" class="attachment-grid-feat" />
<div class="headline-overlay">LOREM IPSUM</div>
</a>
.portfolio-reaction {
width:250px;
height:250px;
display:block;
}
.headline-overlay {
background:none;
height:100%;
width:100%;
display:none;
position:absolute;
top:10%;
z-index:999;
text-align:left;
padding-left:0.5em;
font-weight:bold;
font-size:1.3em;
color:#000;
}
.attachment-grid-feat:hover ~ .headline-overlay {
display:block;
}
and jsfiddle: https://jsfiddle.net/yL231zsk/1/
This solution works in 99%. The missing percent is the effect - while moving mouse arrow through the button, text is blinking. I have no idea why. Secondly - what if I want to extend number of appearing elements from 1 to 3. So to have:
<a title="#" class="portfolio-reaction" href="#">
<img src="http://i.imgur.com/OZb7SI8.png" class="attachment-grid-feat" />
<div class="headline-overlay">
<p class="element-1">abc</p>
<p class="element-2">111</p>
<div class="element-3">X</div>
</div>
</a>
Thank you for any tips and advices.
You wrote the following in your css file :
.attachment-grid-feat:hover ~ .headline-overlay {
display:block;
}
It won't work since .attachment-grid-feat isn't the parent of .headline-overlay. So it won't select the state when the parent is selected because there are no element .healine-overlay inside .attachment-grid-feat. Also no need to add ~ between the two. The right selector is the following :
.portfolio-reaction:hover .headline-overlay {
display: block;
}
This way you are targeting the child div .healine-overlay when parent div .portfolio-reaction (you might want to make the <a> tag a <div> tag) is hovered.
.portfolio-reaction {
width: 250px;
height: 250px;
display: block;
}
.headline-overlay {
background: none;
display: none;
position: absolute;
top: 10%;
z-index: 999;
text-align: left;
padding-left: 0.5em;
font-weight: bold;
font-size: 1.3em;
color: #000;
}
.portfolio-reaction:hover .headline-overlay {
display: block;
}
<div title="#" class="portfolio-reaction" href="#">
<img src="http://i.imgur.com/OZb7SI8.png" class="attachment-grid-feat" />
<div class="headline-overlay">
<div id="element-1">Hello 1</div>
<div id="element-2">Hello 2</div>
<div id="element-3">Hello 3</div>
</div>
</div>
In this code snippet, three elements are contained inside .headline-overlay. On hover, all three elements are displayed.
First, change the last CSS line from this:
.attachment-grid-feat:hover ~ .headline-overlay {
display:block;
}
into this:
.attachment-grid-feat:hover .headline-overlay {
display:block;
}
And will "half" work. You need after to change the width and height of your <div class="headline-overlay"> from a smaller percentage to match your square width and height(leaving it to 100% covers the entire screen, and as a result, the text wont dissapear, no matter where you will move the cursor). Or, If you want your <div> element to match automaticaly the square size, then you leave the width and height unchanged and change only his position:absolute into position:relative and of course, a little adjusting his position from top.
Here is a working fiddle: https://jsfiddle.net/yL231zsk/9/
I'm creating a horizontal nav bar in CSS and would like the icons to be placed in the following order from left to rigiht: +Matthew, Gmail, Images, 3x3 Square Block, Alarm Clock, Google Plus, Smiley Face. The problem is that the 3x3 Square Block always locates to the far right and does not fit in with the rest of the list. The block was created using a separate div and blocks with CSS. How do I make it so that I can place it as the fourth item from the left? Also, I am struggling to properly align my Google Plus icon with the rest of the list items. Whenever I try to set a seperate padding for the icon, it moves all of the icons down as well. Here's my code:
<ul>
<li><a class ="headerLink matthew" href="#home">+Matthew</a></li>
<li><a class ="headerLink gmail" href="#news">Gmail</a></li>
<li><a class ="headerLink images" href="#contact">Images</a></li>
<li>
<div id="googleApps"> <a href="https://www.google.com/drive/">
<div class ="googleDocs"></div>
<div class ="square"></div>
<div class ="square"></div>
<div class ="square"></div>
<div class ="square"></div>
<div class ="square"></div>
<div class ="square"></div>
<div class ="square"></div>
<div class ="square"></div>
<div class ="square"></div>
</div>
<li> <a class="headerLink alarm" href="https://www.nba.com">☎</a> </li>
<li><img class="headerLink googlePlus" src="http://www.siam.org/publicawareness/images/Google-plus-icon.png">
<li><a class="headerLink profPic" href="https://plus.google.com/+MatthewThrasher/posts">☺</a></li>
</ul>
#googleApps {
height:20px;
width:20px;
position:relative;
float:right;
}
#googleApps:hover .square {
background-color:black;
}
.headerLink {
font-size: 12px;
color:#989898;
text-decoration:none;
font-family:"Arial", arial, sans-serif;
padding-left:30px;
}
.matthew:hover, .gmail:hover, .images:hover {
text-decoration:underline;
}
.square {
background-color:#737373;
float:left;
position: relative;
width: 30%;
padding-bottom: 30.66%;
margin:1.66%;
}
.square:hover {
background-color:black;
}
.driveLink {
width:20px;
height:20px;
background-color:white;
color:white;
/*Important:*/
position:relative;
}
.alarm {
font-size: 25px;
}
.googlePlus {
height: 30px;
width: 30px;
}
.profPic {
font-size: 30px;
}
I'm not sure if you have more CSS in your document but you're missing a bit of CSS to actually make your menu horizontal.
You can make it horizontal by adding to your CSS:
li {
display: inline-block;
}
Extra properties in your CSS was pushing your squares to the side.
Remove float:right and it should align properly.
Pretty much everything else was caused by missing closing tags.
I fixed up the code and made comments where they were missing: http://jsbin.com/letuwahuqe/1/edit?html,css,output
Just some tips as you continue coding - you should really pay attention to your formatting and syntax. Not sure how you're working on your stuff but the code you copy and pasted here has a lot of inconsistent spacing in both HTML and CSS. This makes it really hard to catch mistakes like missing tags and especially difficult for other people looking at your code to understand.
I recommend using something like Sublime Text (it's free!) which will make your life a lot easier!
You can do this by adding the following CSS to your code:
li {
display: inline;
}
I think this will do it!
I also resized your icon:
<img class="headerLink googlePlus" src="http://www.siam.org/publicawareness/images/Google-plus-icon.png" style="height: 20px; width: 20px;">
I'm trying to center a bordered READ MORE link on a web page, but haven't succeeded yet. The link still sits on the left of the page:
I'm using Twitter Boostrap and that's how the HTML looks like:
<div class="container">
<h2 class="more">read more</h2>
</div> <!--end container-->
And the CSS:
#process .more {
border: 1px solid #392e2e;
padding: 15px;
display: inline-block;
margin: 0 auto;
}
#process .more a {
color: #392e2e;
text-decoration: none;
text-align: center;
}
I've also tried it with Bootstrap's class="text-center", but that doesn't work either. Here's a link to my project, you can see the READ MORE link issue at the very bottom of the page.
Thank you for your help.
Use the text-center class but use it on the parent div container for the link:
<div class="container text-center">
<h2 class="text-center more">read more</h2>
</div>
You can do it two ways:
1. Block display method:
#process .more a {
color: #392e2e;
text-decoration: none;
display:block;
width:100px; //Adjustable and depends on you
margin:0 auto;
}
or:
2. Outer element align:
h2.more {
display:block;
text-align:center;
}
h2.more a {
display:inline-block;
width:auto;
}
Here is the fiddle with 2 examples: Example
There are actually other ways to do it with CSS, but these two are the most common.
I'm trying to format math equations vertically using CSS. For example 5,343 + 32 should be formatted as so:
Line 1: 5,343 (right aligned)
Line 2: + (left aligned) 32 (right aligned) --- Note that the plus sign and bottom number are on the same line.
Line 3: ------ (horizontal line)
I've been fooling around with this for the last hour and have had very little luck.
I laid by HTML out like this:
<div id="textbox">
<p class="upperNum">5,343</p>
<p class="sign">+</p>
<p class="lowerNum">32</p>
<p class="line"><hr></p>
</div>
A semantic approach
Here's a semantic approach to marking up an equation that, from the same markup, can be rendered horizontally or vertically by adding a single class. These equations are made up of numbers, an operator, and an equals sign. Here's the markup for an equation:
<span class="equation">
<span class="number">5,343</span>
<span class="operator">+</span>
<span class="number">32</span>
<span class="equals">=</span>
<span class="number">5,375</span>
</span>
That alone renders horizontally:
5,343
+
32
=
5,375
With a little CSS, we quickly can transform into a stacked layout. We just add a single stacked class to the equation element:
<span class="equation stacked">
<span class="number">5,343</span>
<span class="operator">+</span>
<span class="number">32</span>
<span class="equals">=</span>
<span class="number">5,375</span>
</span>
The following CSS does the magic:
.equation.stacked {
display: inline-block;
}
.equation.stacked .number {
display: block;
margin-left: 1em; /* space for the operator */
text-align: right;
}
.equation.stacked .operator {
float: left;
}
.equation.stacked .equals {
display: block;
height: 0;
border-bottom: solid 1px black;
overflow: hidden;
}
This renders like this:
Here's a JSBin you can explore: http://jsbin.com/afemaf/1/edit
Do you mean something like this?: http://jsfiddle.net/PkfAU/2/
What you would be doing is using divs, because they are better for creating layouts. Paragraphs are also valid, as the other answer points out, but I find it easier to see with divs. In this case you will need a container div, and three horizontal ones, the second of them being also a container.
.plus and .number are floating inside its container .second, because you need them to use the same horizontal space (all floating elements require a wrapper).
HTML:
<div class="container">
<div class="first">5,343 </div>
<div class="second">
<div class="plus">+</div>
<div class="number">32</div>
</div>
<div class="third">
<div class="result">5,375</div>
</div>
</div>
CSS:
.container {
width:200px;
}
.first,
.second {
width:200px;
text-align:right;
display:table;
}
.plus {
width:auto;
float:left;
}
.number {
width:auto;
float:right;
}
.third {
width:200px;
text-align:right;
border-top:1px solid black;
}
I think this may be your best bet:
HTML:
<div id="textbox">
<p class="upperNum">5,343</p>
<p class="lowerNum">
<span class="operand">32</span>
<span class="sign">+</span>
</p>
<br class="clear" />
<p class="line"><hr></p>
</div>
CSS:
#textbox { width: 75px; }
.upperNum { text-align: right; }
.operand { float: right; }
.sign { float: left; }
.clear { clear: both; }
Here's a fiddle that shows this effect also:
http://jsfiddle.net/8CPar/
Here, you can contain the bottom line in a paragraph, then give the operator and operand a separate span container that you can float, giving you the desired effect. Then, you add a "clear break" which clears the float, making the horizontal break show correctly.
I hope this helps!
There are some fine examples here, but I went through with the effort of making a fiddle so might aswell post it.
You just need to ensure that widths and alignments are set correctly and it should work out.
My JSFiddle Example.
<div id="list">
<span class="item">5472</span>
<span class="operator">+</span><span class="item operand">32</span>
<hr class="divider"/>
<span class="result">5504</span>
</div>
With css
.list
{
width:50px;
}
span
{
display:block;
margin-left:20px;
font-family:"Lucida Console", Monaco, monospace;
width:50px;
}
.operator
{
float:left;
width:20px;
margin-left:0px;
}
.divider
{
clear:both;
width:40px;
margin-left:20px;
}
.operand
{
float:left;
width:50px;
}
I also created an example using pre, that uses pre formatted text, so it should still be precise.
Classics,
<html>
<head>
<style type="text/css">
.textbox
{
width: 100px;
}
.upperNum
{
text-align: right;
width: 100%;
}
.sign
{
float: left;
text-align: left;
}
.lowerNum
{
text-align: right;
}
.secondline
{
clear: both;
width: 100%;
}
</style>
</head>
<body>
<div class="textbox">
<div class="upperNum">
5,343
</div>
<div class="secondline">
<div class="sign">
+
</div>
<div class="lowerNum">
32
</div>
</div>
<div>
<hr />
</div>
</div>
</body>
</html>
Please see this This Image for a picture of the problem.
I have a div that displays a list under a text field. It is a fake Combo-box, using a text element and JavaScript. The list that appears when someone types should cover the other form elements, but should also make the wrapper div bigger so it doesn't get cut off. I have only been able to do one or the other.
Here's The relevant HTML
<td id="EditorMainColumn">
<div id="EditorPanesWrapper">
<div style="display: block;"><!-- a Jquery Tools Tab, also the problem div -->
<div class="EditorFormFieldWrapper">
<label>My Field</label>
<input class="EditorInput" name="name">
</div>
<br class="ClearBoth"><!-- I don't know if this helps or not -->
<div class="ComboBoxListWrapper">
<div class="ComboBoxList">
<!-- <a> elements are inserted dynamically here -->
<br class="ClearBoth"><!-- I don't know if this helps or not -->
</div>
</div>
<div><!-- Cover me! -->
You can't see this when the combo box is open...
</div>
</div><!-- END display:block div -->
</div><!-- END EditorPanesWrapper -->
</td>
CSS:
#EditorMainColumn {
overflow:hidden!important;
background:#f9f9f4;
border-top:1px solid black;
padding:20px;
color:#432c01;
}
#EditorPanesWrapper {
width:auto;
margin-right:20px;
overflow:auto;
}
.ComboBoxListWrapper{
position:relative;
top:-10px;
}
.ComboBoxList{
border: 1px solid red;
width:288px;
position:absolute;
z-index:2;
margin-left:180px;
}
.ComboBoxList a {
display:block;
border: 1px solid #DDD7C6;
border-top:0px;
float: left;
padding: 8px;
padding-left:0px;
top:-11px;
color: #432C01;
width:279px;
font-weight: bold;
font-size: 10px;
background:white;
}
How do I get the div to expand for the combo-box's height while still keeping the options list over/above the other form elements?
as i notice using this
EditorPanesWrapper
inside the TD make the size fix,
Try to give an specific width and height in % if you want it to adjust to the content of your page.
Another question why do you need to put it into a table ? you can just use div