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

Launch Internet Explorer and input variable values (such as ScriptEngineMinorVersion)

I am looking to create a script that can open a file and inject values into it. Here is a basic example: Set WshShell = WScript.CreateObject("WScript.Shell") Return = WshShell.Run("iexplore.exe google.com", 1) However, I also need to modify some variab ...

Utilize generated styling data bindings when referencing assets

Currently, I am working with vue-cli 3 and trying to create background-image paths. To achieve this, I am utilizing the style data bind within a v-for-loop. Below is the component structure: <template> <ul> <li v-for="(tool, inde ...

Is there a way to make the text on my Bootstrap carousel come alive with animation effects?

My website features a Bootstrap Carousel with three elements structured like this: <a><img data-src="img" alt="Third slide" src="img"> </a> <div class="carousel-caption"> <h2> <u ...

Challenges with creating a contact form using bootstrap modal

I'm facing an issue with a bootstrap modal contact form. It works fine on all browsers except for iPad/Safari. Can anyone help me figure out what's wrong? On iPad, the modal is positioned to the right and down the page instead of in the cente ...

The property 'filter' is not recognized on the 'Object' type. An attempt to filter the response was made

Trying to fetch data from a JSON file that matches the player's name in the URL, such as localhost:4200/players/Febiven, should only retrieve information about Febiven. The code is written in Angular 6. The current code snippet is as follows: player ...

Is there a method to stop a mobile device from rotating my responsive website on mobile devices?

Currently, I am in the process of developing a mobile responsive website and I'm aiming to prevent any rotation on Safari specifically. Is there a way that I can achieve this without affecting other browsers like Android? ...

What are the steps to restrict the scope of a <style> declaration in HTML?

Currently, I am in the process of creating a user interface for a webmail. Whenever I receive an email, I extract its content and place it within a <div> element for display purposes. However, one challenge that I am facing is that each email contain ...

Exploring Anchor Tags in Next.js

I'm having trouble using an anchor tag in Next.js Despite not receiving any console errors when setting it up and clicking the link, the page doesn't scroll to the specified id tag. A recent GitHub issue implies that a significant amount of cus ...

On iPhone, links located under a fixed-positioned div can be easily clicked

I am facing an issue on our mobile website where the footer with fixed positioning overlaps with a scrolling feed underneath it, causing the links in the feed to be clickable from the footer area. Footer CSS: .footer { position: fixed; bottom: 0; right: ...

Rotating the icon in Bootstrap Accordion upon opening

I am trying to customize a Bootstrap 4 accordion by conditional rotating the icon to point up when it is open and back down when closed. I managed to achieve this using CSS, but now I need to implement it conditionally based on active states rather than ev ...

Encountering an 'undefined' error while attempting to showcase predefined JSON data on an HTML webpage

As I try to display the predefined JSON data from https://www.reddit.com/r/science.json on an HTML page, I keep encountering the message "undefined." Below is a snippet of my HTML code: $.getJSON('https://www.reddit.com/r/science.json', funct ...

Implementing PHP echo alerts using Javascript

My current task involves validating the IP address entered in a textbox using PHP. $('#check_ip').click(function() { var iptext = $('#Ip_Txt').val(); $.ajax({ type : "POST", url : "mypage.php", data : { iptext : ip ...

Efficiently pinpointing the <div> element with precision using jQuery

I am building an interactive quiz for users of my app. The questions are table based, and can be answered "yes," "no," or "maybe." If the user answers "no" or "maybe," I would to slide open an informational panel that lives beneath the table. Here is the ...

The behavior of Material-UI Drawer varies when used on tablets

Encountering some strange issues with the Material-UI drawer component. It's scrolling horizontally on my iPad, while it scrolls vertically on my MacBook and Android Phone. Expected Result on MacBook: https://i.sstatic.net/txBDf.png On my MacBook, it ...

What is the best way to position an <a> tag in the top right corner of a card using Bootstrap?

I own a card that features an image in the background. <div class="col-12 col-sm-8 col-md-6 col-lg-4 mt-4"> <div class="card"> <img class="card-img" style=" filter: brightness(75%);" src=& ...

Unable to apply styling to body element in style.css file when using Node.js

I recently launched a basic Node.js website but encountered an unusual issue. When trying to style the body using the default style.css stylesheet provided by Express, I found that it was not recognizing it. The only workaround was to add the class body di ...

After the checkbox is clicked, I must send a boolean value to the function through the input flag in AngularJS

<input class="bx--toggle" id="toggle-view" type="checkbox" ng-model="vm.monthView" ng-change="vm.getRelevantData()" ng-attr-data-modal-target="{{vm.alertForSaveAll ? '#add-save-all-alert-modal': 'undefined'}}"> Within this p ...

A guide on verifying a phone number using just one character

I am looking to validate a phone number with only one character being allowed. For example, the format should be XXX-XXXXXXX where "-" is the only allowed character. Below is my validation function: function validatePhoneNumber() { if(addform.staff_m ...

Retrieve data from a specific page on a URL using AJAX

window.onload= function(){ var page = window.location.hash; if(window.location.hash != ""){ page = page.replace('#page:', ''); getdata('src/'.page); } } Once the window has loaded, I want to check ...

The mysterious behavior of HTML 5 causing images to mysteriously add a 3px margin at the

Whenever I update my website to <!DOCTYPE HTML> Each img element enclosed within a DIV mysteriously acquires a 3px bottom margin, even though no CSS rule defines it. To clarify, there are no style attributes responsible for this 3px bottom margin. & ...