Creating the perfect layout with CSS: A step-by-step guide

As I work on refining my layout to achieve the desired look, let me share my initial idea before delving into the issue at hand.

Currently, I am attempting to create something similar to this: https://i.stack.imgur.com/rtXwm.png

This is how it appears at the moment:

https://i.stack.imgur.com/FUNN3.png

We are almost there, but as you can see, the Title, vote, and release attributes are too close to the image. I wish to introduce some spacing between them. Unfortunately, I have tried various methods like margin, positioning, and more without success. I suspect that my JavaScript may be responsible due to the line:

$('#title').html("Title: " + data.title);

I'm uncertain if the addition of 'Title:' might be causing the issue. While in CSS, I have implemented the following styling:

#title{
    margin: 15px;
    font-size:15px;
    padding: 5px;
}
#release {
    font-size:15px;
    padding: 5px;
}
#vote {
    font-size:15px;
    padding: 5px;
}
#overview {
    font-size:15px;
    padding: 5px;
}
#poster {
    float: left;
    width: 250px;
    height: 450px;  
}
#trailer {      
}

The aspects concerning the poster and description worry me. Using 'float: left;' for the poster might cause issues when handling lengthy descriptions where the text could end up below the picture. Moreover, achieving a space between the picture and the description remains a challenge.

If more code or information is required, do not hesitate to ask, and I will respond promptly.

A Youtube embed has yet to be incorporated since I haven't mastered the process. However, establishing a tentative position now would eliminate concerns later on.

The ID declarations should ideally be nested within aside elements:

<aside id="title"></aside>
<aside id="release"></aside>
<aside id="vote"></aside>
<aside id="overview"></aside>
<aside id="resultsDiv"></aside>
<aside id="poster"></aside>
<aside id="trailer"></aside>

In the CSS section:

aside {
    float : left;
    margin-left: 20px; 
}

If further modifications are necessary, here's an update with additional HTML markup:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MovieTrailerbase</title>

<link rel="stylesheet" type="text/css" href="styles.css" />

</head>

<body>

<div id="page">

    <h1>Movie Search</h1>

    <form id="searchForm" method="post">
        <fieldset>

            <input id="s" type="text" />

            <input type="submit" value="Submit" id="submitButton" />

            <div id="searchInContainer">
                <input type="radio" name="check" value="site" id="searchSite" checked />
                <label for="searchSite" id="siteNameLabel">Search movie</label>

                <input type="radio" name="check" value="web" id="searchWeb" />
                <label for="searchWeb">Search series</label>
            </div>

        </fieldset>
    </form>
<aside id="title"></aside>
<aside id="release"></aside>
<aside id="vote"></aside>
<aside id="overview"></aside>
<aside id="resultsDiv"></div>
<aside id="poster"></aside>
<aside id="trailer"></aside>
</div>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="script.js"></script>


</html>

Finally, after resolving the issue using the provided link, I want to express my gratitude to everyone who contributed!

Answer №1

Think of your design as a table layout.

+--------------------------------+
| input                 | button |
+------------+-------------------+
|            |                   |
| poster     | content           |
|            |                   |
|            |                   |
|            |                   |
+------------+-------------------+
|                                |
|           video                |
|                                |
+--------------------------------+

Looking at the rows, we have 3 in total.

To represent this in HTML:

<div class="header"></div>
<div class="main"></div>
<div class="youtube"></div>

The header contains the input and button, main section has image and content, while the YouTube video is placed below.

<div class="header">
    <input class="input" />
    <button class="button">button</button>
</div>
<div class="main">
    <div class="poster"></div>
    <div class="content"></div>
</div>
<div class="youtube"></div>

Add some CSS with floats to align the image and content with some spacing between them:

.poster {
    float: left;
}
.content {
    float: left;
    margin-left: 10px;
}

Check out the working solution here: http://jsfiddle.net/ubrdxnuw/

Answer №2

My personal approach would be to group all the elements on the right side of the poster (such as title, vote, release date) into a container that is floated to the left like the poster itself.

Then, apply a margin-left: 20px (for instance) to that container housing those items. This adjustment should produce the desired effect.

Answer №3

Enclose your

#title, #vote, #release, and #overview
within an <aside> element and align it to the left side:

HTML:

<aside>
    <div id="title"</div>
    <div id="vote"</div>
    <div id="title"</div>
    <div id="overview"</div>
</aside>

CSS:

aside {
    float: left;
}

Next, you can apply a left margin to the <aside> container:

aside {
    float : left;
    margin-left: 20px; //Adjust as needed
}

Answer №4

After analyzing the code you provided, it appears that there were some missing pieces in the original code. To address this, I have created a basic fix with placeholder content for demonstration purposes. You can view the updated code in action at this link.

The CSS structure looked fine overall. One suggestion is to enclose the relevant information within a div element (I named it as class="info") on the same level as the <aside id="poster"> element. Then, you can apply floats to these two elements and organize the child elements like info, title, etc., within the div.info container.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exploring the process of web scraping from dynamic websites using C#

I am attempting to extract data from using HtmlAgilityPack. The website is dynamic in nature, displaying content after the page has fully loaded. Currently, my code retrieves the HTML of the loading bar using this method, but encounters a TargetInvocation ...

Utilizing media queries to customize the appearance of a jQuery accordion widget

Hello, I'm struggling with implementing a jQuery accordion for mobile platforms that destroys itself on larger screens. While my code is mostly working, I've encountered two issues: The accordion only gets destroyed when the window is resized ...

Is it possible in HTML to create an "intelligent" overflow effect where text is truncated and replaced with an ellipsis "..." followed by a link to view the full content?

I have a <div> that has a limited size, and I am looking for a way to display multiline text in it. If the text exceeds the available space, I would like to add "..." at the end along with a link to view the full content on another page. Is there a ...

How to position items at specific coordinates in a dropdown using JavaScript

I have five images in my code and I would like to arrange them in a circular pattern when they are dropped into the designated area. For example, instead of lining up the five images in a straight line, I want them to form a circle shape once dropped. Ho ...

jQuery's slide toggle function is limited to toggling the visibility of just one section at

Welcome to my first post! As a newbie in web development, I have just started my first project. While I feel comfortable with HTML and CSS, jQuery is proving to be a bit challenging for me. In the head section of my intranet page, I have the following cod ...

Tips for concealing scrollbars across various browsers without compromising functionality

Is there a way to hide the scrollbar functionality on a horizontal scrollbar without using "overflow: hidden"? I need to maintain JS functionality and ensure compatibility with all modern browsers. $j = jQuery.noConflict(); var $panels = $j('#primar ...

Explore a variety of themes for the antd design token

Is there a way to access the text color of both the default and dark themes using design tokens? I am looking for a method to seamlessly switch between the two color schemes based on specific conditions, without having to change the entire theme. For ins ...

Creating a universal function to handle setTimeout and setInterval globally, inclusive of clearTimeout and clearInterval for all functions

Is it possible to create a universal setTimeout and setInterval function with corresponding clearTimeout and clearInterval for all functions while passing values to them? The situation is as follows: 1. More than 8 functions utilizing setInterval for act ...

`Finding the appropriate place to define a variable within a React Component`

When attempting to declare the variable images within the component, I encountered an error. See the screenshot for more information: here. ...

CSS: The calc() function does not take into account the bottom padding when used in Firefox and Internet

I am encountering an issue with the calc() function in Firefox 32 and IE 11, where the bottom padding of a div is not being respected. However, this problem does not occur in Chrome and Opera. The main content section should have a fixed height while allo ...

Having trouble with jQuery animate function?

I have been struggling to get my animate function to work, despite looking at multiple similar posts and making modifications to my code. My goal is to make an image of a plane move from left to right across the screen and stop halfway. Here is the code I ...

Ways to ensure a div remains at the bottom of a page without using a wrapper

I am currently working on my website and this is the content I have in my body tag: #social-media { width: 175px; margin-left: auto; margin-right: auto; padding-top: 10%; } #social-media img { padding: 5px; } #soci ...

Tips on transforming button-controlled tab pages in Bootstrap 2 to Bootstrap 3

I am currently in the process of upgrading my website from Bootstrap 2 to Bootstrap 3, and I have encountered an issue with a specific control that consists of multiple sets of tab pages controlled by toggle buttons. Here is an example of the functional c ...

Steps for selecting a radio button based on a MySQL table value:

My table has two fields, name and gender. When I retrieve the data and attempt to display it in input fields, everything works fine for the Name field. However, I am curious if there is a way to automatically select the radio button based on the gender d ...

Is there a way to run both PHP and HTML code using the eval function?

Is it possible to execute HTML and PHP simultaneously using the eval function? eval ("<center> this is some html </center>"); The above code does not yield the desired output, so I am considering changing it to: echo ("<center> this is ...

Text centered over an animated underline using CSS

Seeking help with my bootstrap 4 nav menu. I have implemented a CSS animation that creates an outward underline effect for the nav-link items. However, I am struggling to center the text above the line. Any suggestions on how to achieve this? I attempted ...

Removing all HTML elements within the div container

My HTML code includes the following: <div class="row" id="conditional-one"> <div class="large-12 columns"> <h3><?php echo $arrayStage_rule_one_title?></h3> <p> <?php echo $arrayS ...

I need to display 5 columns in a parent component, each with its own unique icon. How can I conditionally render them in a React component?

Creating a parent component to reuse multiple times can be very useful. In my case, I have included 5 different icons in each instance of the component, all taken from hero icons. I have set up an object with unique ids for each child component, but I am ...

Display a concealed text box upon clicking BOTH radio buttons as well as a button

Below is the HTML code for two radio buttons and a button: <body> <input data-image="small" type="radio" id="small" name="size" value="20" class="radios1"> <label for=&qu ...

Is there a way to remove the initial number entered on a calculator's display in order to prevent the second number from being added onto the first one?

I am currently in the process of developing a calculator using HTML, CSS, and JavaScript. However, I have encountered an issue with my code. After a user inputs a number and then clicks on an operator, the operator remains highlighted until the user inputs ...