Variable floating oddly - html

I have a problem with an unordered list when I insert a variable inside an image.
Please have a look at this fiddle.
So basically, what I get here is a list of images, centred and floated to the left, with left alignment on new lines as well.
In Jsfiddle I used a random image. When I copy this code exactly as it is into my code it works fine. When I swap the random image to a PHP variable the whole list jumps around and it looks very bad. Allow me to illustrate what I see with a PHP variable inserted:
I have no idea why this becomes like this. Here is my code with the PHP variable:
<div class="snaps-wrap">
<ul>
<?php
//Here is php code which works fine
?>
<li>
<a href="#">
<img id="snap-img" src="<?php echo $snappic?>" alt="">
</a>
</li>
<?php }
}
?>
<p style="clear: both;"></p>
</ul>
</div>
Here is CSS:
.snaps-wrap {
width: 70%;
margin: 0 auto;
padding: 0;
}
.snaps-wrap ul {
padding: 0.5em 0;
text-align:center;
margin:0 auto;
background:#ddd;
list-style: none;;
}
.snaps-wrap ul li {
float: left;
width: 25%;
margin: 0.5em 0;
}
#snap-img {
width: 150px;
}
As I mentioned, with the image used in jsfiddle this works fine, as soon as I change the image source to my variable it becomes misplaced.
Any ideas why this happens and how to fix this?

Related

Why text before div section will appears AFTER it?

I try to modify single.php in WordPress theme, by adding social buttons before & after the post contents, as below:
<div class="socialsharebuttons">
<strong>SHARE NOW:</strong><?php echo do_shortcode('[DISPLAY_ULTIMATE_SOCIAL_ICONS]'); ?>
</div>
<div class="entry">
<?php the_content(''); ?>
</div>
<div class="socialsharebuttons">
<strong>SHARE NOW:</strong><?php echo do_shortcode('[DISPLAY_ULTIMATE_SOCIAL_ICONS]'); ?>
</div>
In the code, the "SHARE NOW" text appears right before the PHP code that generate the shortcode. However, after displaying the post such as http://www.sybase-recovery.com/blogs/datanumen-archive-repair-3-8-is-released-on-may-16-2021/, I find the "SHARE NOW" shows AFTER the social buttons, as below:
I then use Chrome DevTools to diagnose the issue, and find the codes are:
<div class="socialsharebuttons">
<strong>SHARE NOW:</strong><div class="sfsi_widget sfsi_shortcode_container">...</div>
</div>
The "SHARE NOW" is also before the <div class="sfsi_widget sfsi_shortcode_container">.
I then check the CSS for , and find it has property float: left. So I follow the instructions in https://stackoverflow.com/a/2417150/2704265 and modify CSS as below:
div.socialsharebuttons {
display: inline-block;
width: 100%;
float: left;
}
But that still not working, why?
This happens because strong is an inline element so it won't respect the preceding floats. In order to make it side by side just set
div.socialsharebuttons strong{
float: left;
margin-top: 13px;
}
After setting this it will looking like this
If you want the list to go after the text use
div.socialsharebuttons strong{
display: block;
margin-bottom: 13px;
}
you want the "share now" in front, or above the social buttons?
For above it's:
.sfsi_shortcode_container {
float: none;
}
In Front:
.sfsi_shortcode_container {
float: right;
margin-left:10px;
}
.socialsharebuttons > strong {
position: relative;
top: 15px;
}

Prevent image from showing on top of text

I've recently started learning web dev. I'm making a site that fetches data from the mealdb api and displays the data. I've mostly gotten everything working, but the issue is when I inspect the web page and view it on mobile, the image is rendered on top of the text, i.e. the title and the ingredients. How do I prevent this from happening?
Ideally, on a mobile device, I'd like to show the title, followed by the image, ingredients and the instructions in a single column.
This is how it looks on desktop:
On mobile:
.Recipe {
padding-top: 30px;
text-align: left;
display: flex;
flex-wrap: wrap;
justify-content: center;
overflow: auto;
vertical-align: text-top;
}
.left-content {
width: 40%;
float: left;
}
.list {
list-style: none;
padding-left: 0px;
padding-bottom: 15px;
font-size: 1.2rem;
}
.right-content {
width: 40%;
float: right;
}
.title {
font-size: 3rem;
justify-content: center;
padding-bottom: 0px;
}
.instructions {
font-size: 1.2rem;
}
.Recipe h1 {
text-align: center;
padding-left: 250px;
}
.image {
float: right;
height: 480px;
width: 480px;
margin: 20px
}
<div className="Recipe">
<div className="left-content">
<h2 className="title">{prop.food.meals[0].strMeal}</h2>
<ul className="list">
{prop.materials.map(function(ingredients){ return
<li key={ingredients.strIngredient}>{ingredients.name + " - " + ingredients.amount}</li>
})}
</ul>
<p className="instructions">{prop.food.meals[0].strInstructions}</p>
</div>
<div className="right-content">
<img src={prop.food.meals[0].strMealThumb} alt="" className="image" />
</div>
</div>
This is a CSS situation, and for this specific situation I highly suggest learning about grid: https://css-tricks.com/snippets/css/complete-guide-grid/
Now, I know you probably don't want to read that much or learn something entirely new just to solve this. So for now I will give you a quick solution, which it isn't so bad in terms of performance.
You can use react-device-detect
It has some components that print specifically on Desktop or Mobile. So in your case you can have something like this:
import {BrowserView, MobileView} from 'react-device-detect';
And in your render:
<div className="Recipe">
<div className="left-content">
<h2 className="title">{prop.food.meals[0].strMeal}</h2>
<MobileView>
<img src={prop.food.meals[0].strMealThumb} alt="" className="image"/>
</MobileView>
<ul className="list">
{prop.materials.map(function(ingredients){
return <li key={ingredients.strIngredient}>{ingredients.name + " - " + ingredients.amount}</li>
})}
</ul>
<p className="instructions">{prop.food.meals[0].strInstructions}</p>
</div>
<BrowserView>
<div className="right-content">
<img src={prop.food.meals[0].strMealThumb} alt="" className="image"/>
</div>
</BrowserView>
</div>
The idea is printing the image "twice", one for mobile and one for desktop. However, they will not be printed at the same time, obviously. And the images on web get requested only once, so you can print the same image dozens of time but it will only be loaded once on the browser, which is why this alternate solution works well.
If you don't want to use react-device-detect, you can print the image twice (on the same location as the example), and on CSS just use Media Query to set a display: none for mobile and desktop when they're not required. Let me know if you prefer CSS and I can elaborate further on how to do this on CSS. But I don't suggest this one because it is less efficient since the HTML will have two tags of the same image even if you're hiding them on CSS.
Let me know if you have any questions. And I hope this was helpful.

Remove the empty space present below the image

we can see lot of empty space in link as below the image. I want to hide those empty space.
.main {
margin: 0 auto;
width: 1000px;
}
body, button, input, select, table, textarea {
font-family: 'Roboto Condensed', sans-serif;
color: #636363;
font-size: 14px;
line-height: 1.5;
}
html
<div class="custom_case">
<div class="custom_case_left">
<h1 class="cc1">Custom Cases</h1>
<h2 class="cc2">Make Your Own design</h2>
</div>
<?php
$brandSelect = '<select id="brand_select">';
$brandSelect .= '<option value="">My Brand</option>';
$brandSelect .= '</select>';
echo '<select id="model_select"><option value="">My Model</option></select>';
?>
<div class ="cc3">
<div class ="cc4">
<span class ="cc5"> See Cases > </span>
</div>
</div>
I dont want to give so much empty space between image and below footer
please help me for this.
Thanks in advance.
Figured it out for you!
Your image of the phone cases is what is causing the space issue.
.custom_case_right img {
/*float:right;*/
/*bottom:320px;*/
}
That will fix the spacing beneath your image. Now your image is displaying improperly and to fix do this
.custom_case_right {
float:right;
margin-top:-310px;
}
These two changes ought to take care of it for you. I tested this out in Chrome.
You'll still need to think about how you want to have your image behave as your viewport shrinks though.
trying to make img:
line-height: 0;
vertical-align: top or bottom;
You have to fix the height of main-container.
enter code here.main-container{
height:550px;
}
Make this changes to your classes:
.col1-layout .col-main {
position: relative;
}
.custom_case_right {
float: left;
position: absolute;
top: 0;
bottom: 0;
right: 0;
}
And in your image remove position absolute, add this style instead:
.custom_case_right img {
position: relative;
width: 620px;
height: 100%;
}

Using svg on webpage results in weird css rendering in webkit browsers

I'm running into a weird glitch which only seems to happen in chrome and safari. It's hard to explain why this happens with sample code, but I'll try to illustrate what I'm doing with code, while providing a link to the actual page below.
First of all, I have an unordered list displayed inline-block, so it can be justified just like text. Each list item contains an svg in an image tag and a paragraph with a short description, both wrapped in a single anchor tag. Nothing special i guess, but here's the catch: in chrome and safari the browser renders a 1px by approximately 15px blue/blackish line between the paragraph and the image, and I have no idea why this is happening. Here's the code:
<div class="wrapper">
<div class="justified-list home-icons">
<ul>
<li>
<a href="#">
<img src="http://voctel.wearebold.nl/wp-content/uploads/2015/02/company-building.svg" />
<br/>
<p>Description</p>
</a>
</li>
<li>
<a href="#">
<img src="http://voctel.wearebold.nl/wp-content/uploads/2015/02/company-building.svg" />
<br/>
<p>Description</p>
</a>
</li>
<li>
<a href="#">
<img src="http://voctel.wearebold.nl/wp-content/uploads/2015/02/company-building.svg" />
<br/>
<p>Description</p>
</a>
</li>
</ul>
<span class="stretcher"></span>
</div><!-- .justified-list -->
</div><!-- .wrapper -->
and here is the css (I'm using scss):
.wrapper {
width: 100%;
}
.justified-list {
width: 100%;
text-align: justify;
* {
display: inline;
}
li {
display: inline-block;
vertical-align: top;
}
.stretcher {
display: inline-block;
position: relative;
width: 100%;
height: 0;
}
}
Also, a codepen is provided here:
http://codepen.io/smelly586/pen/NPVVYd
If anyone has a clue on what's going on, or even better: has a possible fix for this, you have my gratitude.
Set your font-size on the element to 0. What you're seeing is the underline in the anchor element for whitespace in your HTML.
You could turn off the text-decoration: underline; that the browser renders by default for anchors, but let's assume that's not what you want to do.
Instead, the element with text will need to be reset to document root font-size (or whatever you want) using something like p { font-size: 1rem; }.
Example Codepen
So, accordingly, the SCSS/LESS would be:
.justified-list {
width: 100%;
text-align: justify;
* {
display: inline;
}
li {
display: inline-block;
vertical-align: top;
a {
font-size: 0;
p { font-size: 1rem; }
}
}
.stretcher {
display: inline-block;
position: relative;
width: 100%;
height: 0;
}
}

I can't get my links display as inline in HTML

i'm trying to write a div box with headings and links below to it, but somehow i can't get the links to display next to eachother, i've tried using display:inline, but it did no effect, i've also tried float, position etc, but just can't get what i want without messing up.
my code is here: http://jsfiddle.net/dfc8gceg/2/
<div style="background:#E1ED9D; width: 25%;height:250px; position: relative; float: left;">
<h3 style="text-align:center; margin:0;">I want the links below display as first row link1 and line2, then next row link3 and link4, 50% width each</h3>
<a href="">
<h4 style="background:blue; width:50%; color:#0e8dbc; text-align:center; margin:10% 0 0 0; ">Link1</h4>
</a>
<a href="">
<h4 style="background:orange; width:50%; color:#0e8dbc; text-align:center; margin:3% 0 0 0;">Link2</h4>
</a>
<a href="">
<h4 style="background:purple; width:50%; color:#0e8dbc; text-align:center; margin:3% 0 0 0;">Link3</h4>
</a>
<a href="">
<h4 style="background:red; width:50%; color:#0e8dbc; text-align:center; margin:3% 0 0 0;">Link4</h4>
</a>
</div>
Sorry for the repetition of code, it's because i can't use CSS or put code into head section, only body section of html due to my task requirement,
i would appreciate alot if someone can show me the answer without too much change on my code
I got rid of the h4 tags and used divs instead
http://jsfiddle.net/dfc8gceg/8/
<div style="background:#E1ED9D; width: 50%;height:150px; position: relative; float: left;">
<h3 style="text-align:center; margin:0;">I want the links below display as first column link1 and line2, then next column link3 and link4, 50% width each</h3>
<a href="">
<div id="div1">hej</div>
</a>
<a href="">
<div id="div2">hej</div>
</a>
<a href="">
<div id="div3">hej</div>
</a>
<a href="">
<div id="div4">hej</div>
</a>
</div>
I also added some css to the jsfiddle
you should look more into how to use css and html
Hope this works out for you!
I made a JSFiddle, is this what you were aiming for?
http://jsfiddle.net/dfc8gceg/7/
Here is the HTML
<div id="container">
<h3>I want the links below display as first column link1 and line2, then next column link3 and link4, 50% width each</h3>
<h4>Link1</h4>
<h4>Link3</h4>
<h4>Link2</h4>
<h4>Link4</h4>
</div>
With accompanying CSS
#container {
background: #E1ED9D;
width: 25%;
height: 250px;
position: relative;
float: left;
}
h3 {
text-align: center;
margin:0;
}
a {
display: inline-block;
}
.link {
width: 50%;
color: #0e8dbc;
text-align: center;
display: inline-block;
float: left;
}
#link1 {
background: blue;
margin: 10% 0 0 0;
}
#link2 {
background: orange;
margin: 3% 0 0 0;
}
#link3 {
background: purple;
margin: 10% 0 0 0;
}
#link4 {
background: red;
margin: 3% 0 0 0;
}
I think I achieved what you were looking for.
Hope this helps! :D
PS: I'm a noob at Stack Overflow, did I format this correctly? It wanted the code in the answer so...
EDIT: I kept the H4 elements for you, but feel free to change them (I didn't want to change any of your code, I kept it all just made it neater)
A preferred method would be instead to use an unordered list (<ul><li></li></ul>), and then add css to the list, display: inline; to remove the default block level display. Alternatively, you can use display: block; float: left;, which you would need in order to give a width to the li.
Moreover, you should not be using inline CSS, but rather a stylesheet.
Like this:
CSS:
.container {
background: #E1ED9D;
width: 25%;
height: 250px;
position: relative;
float: left;
}
.container h3 {
text-align:center;
margin:0;
font-size: 14px;
font-family: arial;
font-weight: normal;
}
.list {
width: 100%;
padding: 15px 0 0 0;
margin: 0;
}
.list li {
style-type: none;
display: block;
float: left;
width: 50%;
margin: 15px 0 0 0;
padding: 10px 0;
text-align:center;
}
.list li a {
color:#0e8dbc;
}
#first-link {
background:blue;
}
#second-link {
background:orange;
}
#third-link {
background:purple;
}
#fourth-link {
background:red;
}
HTML
<div class="container">
<h3>I want the links below display as first row link1 and line2, then next row link3 and link4, 50% width each</h3>
<ul class="list">
<li id="first-link">Link1</li>
<li id="second-link">Link2</li>
</ul>
<ul class="list">
<li id="third-link">Link3</li>
<li id="fourth-link">Link4</li>
</ul>
</div>
Also, as above, you don't need the H4s because that is poor coding to put into a menu (what you have is essentially a menu). H4 is better used as a header tag. By instead defining css classes to the LI elements, there is no need for a specific html tag like h4.
EDIT: I improved the CSS code from what I had before. I changed the ID elements to classes (class is used if there will be more elements using the same class), and moved the link classes into the LI. I also changed the li classes to IDs because ID is to be used when it appears only one time on the page. Given the specificity of the IDs, these will likely not be used again. If they are, you should change it back to a class.
jsfiddle: http://jsfiddle.net/Lxyjjfx2/1/